Example #1
0
    def test_distance(self):
        home = Point(52.015, -0.221)
        dest = Point(52.6333, -2.5)
        assert '%i kM' % home.distance(dest) == '169 kM'
        assert '%i kM' % home.distance(dest, method='sloc') == '169 kM'

        with raises(ValueError, message="Unknown method type 'Invalid'"):
            home.distance(dest, method='Invalid')
Example #2
0
def find_nearby(lat,long, limit):
    """ Returns nearest limit incident objects within max_distance in distance order """
    results = []
    target = Point(lat,long)
    for (id, p) in incidents:
        m = target.distance(p) * 1000
        #if m <= max_distance:
        results.append((m,id))

    results.sort(cmp=lambda a,b: cmp(a[0],b[0]))
    return [dict(distance=i[0], **incident_map[i[1]]) for i in results[:limit]]
Example #3
0
    def test_distance(self):
        home = Point(52.015, -0.221)
        dest = Point(52.6333, -2.5)
        expect('%i kM' % home.distance(dest)) == '169 kM'
        expect('%i kM' % home.distance(dest, method='sloc')) == '169 kM'

        with expect.raises(ValueError, "Unknown method type 'Invalid'"):
            home.distance(dest, method='Invalid')

        start = Point(36.1200, -86.6700)
        dest = Point(33.9400, -118.4000)
        expect('%i kM' % start.distance(dest)) == '2884 kM'
        start.units = 'imperial'
        expect('%i mi' % start.distance(dest)) == '1792 mi'
        start.units = 'nautical'
        expect('%i nmi' % start.distance(dest)) == '1557 nmi'
        start.units = 'metric'
        expect('%i kM' % start.distance(dest, method='sloc')) == '2884 kM'
Example #4
0
 def test_distance2(self, units, result):
     start = Point(36.1200, -86.6700, units=units)
     dest = Point(33.9400, -118.4000)
     assert int(start.distance(dest)) == result