def general_prefix_rectangle(rectangle): left_top = encode(rectangle[0].latitude, rectangle[0].longitude) left_bottom = encode(rectangle[1].latitude, rectangle[0].longitude) right_top = encode(rectangle[0].latitude, rectangle[1].longitude) right_bottom = encode(rectangle[1].latitude, rectangle[1].longitude) return Search.str_first_intersection(left_top, left_bottom, right_top, right_bottom)
def test_point_lifecycle(self): point = { "point_id": "test-location-lifecycle-" + str(uuid.uuid4()), "latitude": 50.45466, "longitude": 30.5238, "geohash": encode(50.45466, 30.5238) } with create_app().test_client() as client: resp = client.post('/location/v1/points', json=point) self.assertEqual(resp.status_code, 201) # created new point resp = client.get('/location/v1/points/{0}'.format(point["point_id"])) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.json, point) resp = client.post('/location/v1/points', json=point) self.assertEqual(resp.status_code, 200) # updated existing event resp = client.delete('/location/v1/points/{0}'.format(point["point_id"])) self.assertEqual(resp.status_code, 200) resp = client.get('/location/v1/points/{0}'.format(point["point_id"])) self.assertEqual(resp.status_code, 404) resp = client.delete('/location/v1/points/{0}'.format(point["point_id"])) self.assertEqual(resp.status_code, 404)
def test_to_json(self): point = Point("id1", 50.45466, 30.5238) expected = { "point_id": "id1", "latitude": 50.45466, "longitude": 30.5238, "geohash": encode(50.45466, 30.5238) } self.assertEqual(point.to_json(), expected)
def test_from_json(self): json = { "point_id": "id", "latitude": 50.45466, "longitude": 30.5238, "geohash": str(encode(50.45466, 30.5238)) } expected = Point("id", 50.45466, 30.5238) self.assertEqual(Point.from_json(json), expected)
def general_prefix(centre_point, distance): # d - angular radius d = distance / 6371000.0 # latitude and longitude in radians lat_rad = centre_point.latitude * pi / 180 long_rad = centre_point.longitude * pi / 180 delta_long = asin(sin(d) / cos(lat_rad)) # max/min latitude and longitude (degrees) long_min = (long_rad - delta_long) * 180 / pi long_max = (long_rad + delta_long) * 180 / pi lat_min = (lat_rad - d) * 180 / pi lat_max = (lat_rad + d) * 180 / pi # Four vertices of the minimum bounding rectangle that fully contains QUERY CIRCLE north_west = encode(lat_max, long_min) south_west = encode(lat_min, long_min) south_east = encode(lat_min, long_max) north_east = encode(lat_max, long_max) return Search.str_first_intersection(north_east, south_east, north_west, south_west)
def __init__(self, point_id, latitude, longitude): self.point_id = point_id self.latitude = latitude self.longitude = longitude self.geohash = encode(latitude, longitude)