def test_geospatial_put_get_positive_with_geojson(self): """ Perform a get and put with multiple bins including geospatial bin using geodata method """ key = ('test', 'demo', 'single_geo_put') geo_object_single = aerospike.geojson( '{"type": "Point", "coordinates": [42.34, 58.62] }') geo_object_dict = aerospike.geojson( '{"type": "Point", "coordinates": [56.34, 69.62] }') self.as_connection.put(key, {"loc": geo_object_single, "int_bin": 2, "string_bin": "str", "dict_bin": {"a": 1, "b": 2, "geo": geo_object_dict}}) key, _, bins = self.as_connection.get(key) expected = {'loc': {'coordinates': [42.34, 58.62], 'type': 'Point'}, "int_bin": 2, "string_bin": "str", "dict_bin": {"a": 1, "b": 2, "geo": {'coordinates': [56.34, 69.62], 'type': 'Point'}}} for b in bins: assert b in expected self.as_connection.remove(key)
def test_geospatial_dumps_positive(self): """ Perform a positive dumps. Verify using str """ geojson_str = self.geo_object.dumps() assert type(geojson_str) == str obj = aerospike.geojson(geojson_str) assert obj.unwrap() == self.geo_object.unwrap() geojson_str = str(self.geo_object) assert type(geojson_str) == str obj = aerospike.geojson(geojson_str) assert obj.unwrap() == self.geo_object.unwrap()
def test_geospatial_positive_query_with_geojson(self): """ Perform a positive geospatial query for a polygon with geojson """ records = [] query = self.as_connection.query("test", "demo") geo_object2 = aerospike.geojson( '{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], \ [-121.000000, 37.000000], [-121.000000, 38.080000],\ [-122.500000, 38.080000], [-122.500000, 37.000000]]]}') query.where(p.geo_within_geojson_region("loc", geo_object2.dumps())) def callback(input_tuple): _, _, record = input_tuple records.append(record) query.foreach(callback) assert len(records) == 3 expected = [{ 'coordinates': [-122.0, 37.5], 'type': 'Point' }, { 'coordinates': [-121.8, 37.7], 'type': 'Point' }, { 'coordinates': [-121.6, 37.9], 'type': 'Point' }] for r in records: assert r['loc'].unwrap() in expected
def add_geo_data(connection): pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', 'demo', i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format(pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) geo_object = aerospike.geojson(s) geo_list = [geo_object] geo_map_key = {geo_object: i} geo_map_val = {i: geo_object} connection.put( key, { "loc": geo_object, 'geo_list': geo_list, 'geo_map_keys': geo_map_key, 'geo_map_vals': geo_map_val }) key = ('test', 'demo', 'polygon') geo_object_polygon = aerospike.GeoJSON({ "type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]] }) geo_loc_list = [geo_object_polygon] geo_loc_mk = {geo_object_polygon: 1} geo_loc_mv = {2: geo_object_polygon} connection.put( key, { "loc_polygon": geo_object_polygon, 'geo_loc_list': geo_loc_list, 'geo_loc_mk': geo_loc_mk, 'geo_loc_mv': geo_loc_mv }) key = ('test', 'demo', 'polygon2') geo_object_polygon = aerospike.GeoJSON({ "type": "Polygon", "coordinates": [[[-52.500000, 37.000000], [-51.000000, 37.000000], [-51.000000, 38.080000], [-52.500000, 38.080000], [-52.500000, 37.000000]]] }) geo_loc_list = [geo_object_polygon] geo_loc_mk = {geo_object_polygon: 1} geo_loc_mv = {2: geo_object_polygon} connection.put( key, { "loc_polygon": geo_object_polygon, 'geo_loc_list': geo_loc_list, 'geo_loc_mk': geo_loc_mk, 'geo_loc_mv': geo_loc_mv })
def test_geospatial_positive_query_with_geojson(self): """ Perform a positive geospatial query for a polygon with geojson """ records = [] query = self.as_connection.query("test", "demo") geo_object2 = aerospike.geojson( '{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], \ [-121.000000, 37.000000], [-121.000000, 38.080000],\ [-122.500000, 38.080000], [-122.500000, 37.000000]]]}') query.where(p.geo_within_geojson_region("loc", geo_object2.dumps())) def callback(input_tuple): _, _, record = input_tuple records.append(record) query.foreach(callback) assert len(records) == 3 expected = [{'coordinates': [-122.0, 37.5], 'type': 'Point'}, {'coordinates': [-121.8, 37.7], 'type': 'Point'}, {'coordinates': [-121.6, 37.9], 'type': 'Point'}] for r in records: assert r['loc'].unwrap() in expected
def setup_method(self, method): self.keys = [] pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', 'demo', i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format( pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) self.geo_object = aerospike.geojson(s) TestGeospatial.client.put(key, {"loc": self.geo_object}) self.keys.append(key) key = ('test', 'demo', 'polygon') self.geo_object_polygon = aerospike.GeoJSON( {"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]]}) TestGeospatial.client.put( key, {"loc_polygon": self.geo_object_polygon}) self.keys.append(key) if not TestGeospatial.skip_old_server: key = ('test', 'demo', 'circle') geo_circle = aerospike.GeoJSON( {"type": "AeroCircle", "coordinates": [[-122.0, 37.0], 250.2]}) TestGeospatial.client.put(key, {"loc_circle": geo_circle}) self.keys.append(key)
def test_geospatial_repr_positive(self): """ Perform a positive repr. Verify using eval() """ geojson_str = eval(repr(self.geo_object)) assert type(geojson_str) == str obj = aerospike.geojson(geojson_str) assert obj.unwrap() == self.geo_object.unwrap()
def test_geospatial_positive_query_without_set(self): """ Perform a positive geospatial query for a polygon without a set """ keys = [] pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(1, 10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', None, i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format(pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) geo_object = aerospike.geojson(s) self.as_connection.put(key, {"loc": geo_object}) keys.append(key) self.as_connection.index_geo2dsphere_create("test", None, "loc", "loc_index_no_set") records = [] query = self.as_connection.query("test", None) geo_object2 = aerospike.GeoJSON({ "type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]] }) query.where(p.geo_within_geojson_region("loc", geo_object2.dumps())) def callback(input_tuple): _, _, record = input_tuple records.append(record) query.foreach(callback) self.as_connection.index_remove('test', 'loc_index_no_set') for key in keys: self.as_connection.remove(key) assert len(records) == 2 expected = [{ 'coordinates': [-121.8, 37.7], 'type': 'Point' }, { 'coordinates': [-121.6, 37.9], 'type': 'Point' }] for r in records: assert r['loc'].unwrap() in expected
def test_geospatial_positive_query_without_set(self): """ Perform a positive geospatial query for a polygon without a set """ keys = [] pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(1, 10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', None, i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format( pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) geo_object = aerospike.geojson(s) self.as_connection.put(key, {"loc": geo_object}) keys.append(key) try: self.as_connection.index_geo2dsphere_create( "test", None, "loc", "loc_index_no_set") except(e.IndexFoundError): pass records = [] query = self.as_connection.query("test", None) geo_object2 = aerospike.GeoJSON({"type": "Polygon", "coordinates": [[ [-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]]}) query.where(p.geo_within_geojson_region("loc", geo_object2.dumps())) def callback(input_tuple): _, _, record = input_tuple records.append(record) query.foreach(callback) try: self.as_connection.index_remove('test', 'loc_index_no_set') except(Exception): pass for key in keys: self.as_connection.remove(key) assert len(records) == 2 expected = [{'coordinates': [-121.8, 37.7], 'type': 'Point'}, {'coordinates': [-121.6, 37.9], 'type': 'Point'}] for r in records: assert r['loc'].unwrap() in expected
def test_geojson_str(self): """ verify that str representation of geojson object is correct """ geo_object = get_geo_object() geojson_str = str(geo_object) assert isinstance(geojson_str, str) obj = aerospike.geojson(geojson_str) assert obj.unwrap() == geo_object.unwrap()
def test_geospatial_dumps_positive(self): """ Perform a positive dumps. Verify using str """ geo_object = get_geo_object() geojson_str = geo_object.dumps() assert isinstance(geojson_str, str) obj = aerospike.geojson(geojson_str) assert obj.unwrap() == geo_object.unwrap()
def test_geospatial_repr_positive(self): """ Perform a positive repr. Verify using eval() """ geo_object = get_geo_object() geojson_str = eval(repr(geo_object)) assert isinstance(geojson_str, str) obj = aerospike.geojson(geojson_str) assert obj.unwrap() == geo_object.unwrap()
def setup_method(self, method): self.keys = [] pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', 'demo', i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format(pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) self.geo_object = aerospike.geojson(s) TestGeospatial.client.put(key, {"loc": self.geo_object}) self.keys.append(key) key = ('test', 'demo', 'polygon') self.geo_object_polygon = aerospike.GeoJSON({ "type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]] }) TestGeospatial.client.put(key, {"loc_polygon": self.geo_object_polygon}) self.keys.append(key) if not TestGeospatial.skip_old_server: key = ('test', 'demo', 'circle') geo_circle = aerospike.GeoJSON({ "type": "AeroCircle", "coordinates": [[-122.0, 37.0], 250.2] }) TestGeospatial.client.put(key, {"loc_circle": geo_circle}) self.keys.append(key)
def add_geo_data(connection): pre = '{"type": "Point", "coordinates"' suf = ']}' for i in range(10): lng = 1220 - (2 * i) lat = 375 + (2 * i) key = ('test', 'demo', i) s = "{0}: [-{1}.{2}, {3}.{4}{5}".format( pre, (lng // 10), (lng % 10), (lat // 10), (lat % 10), suf) geo_object = aerospike.geojson(s) geo_list = [geo_object] geo_map_key = {geo_object: i} geo_map_val = {i: geo_object} connection.put( key, { "loc": geo_object, 'geo_list': geo_list, 'geo_map_keys': geo_map_key, 'geo_map_vals': geo_map_val } ) key = ('test', 'demo', 'polygon') geo_object_polygon = aerospike.GeoJSON( {"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000], [-122.500000, 38.080000], [-122.500000, 37.000000]]]}) geo_loc_list = [geo_object_polygon] geo_loc_mk = {geo_object_polygon: 1} geo_loc_mv = {2: geo_object_polygon} connection.put( key, { "loc_polygon": geo_object_polygon, 'geo_loc_list': geo_loc_list, 'geo_loc_mk': geo_loc_mk, 'geo_loc_mv': geo_loc_mv } ) key = ('test', 'demo', 'polygon2') geo_object_polygon = aerospike.GeoJSON( {"type": "Polygon", "coordinates": [[[-52.500000, 37.000000], [-51.000000, 37.000000], [-51.000000, 38.080000], [-52.500000, 38.080000], [-52.500000, 37.000000]]]}) geo_loc_list = [geo_object_polygon] geo_loc_mk = {geo_object_polygon: 1} geo_loc_mv = {2: geo_object_polygon} connection.put( key, { "loc_polygon": geo_object_polygon, 'geo_loc_list': geo_loc_list, 'geo_loc_mk': geo_loc_mk, 'geo_loc_mv': geo_loc_mv } )