def test_geospatial_loads_positive_with_query(self):
        """
            Perform a positive loads on geoJSON raw string followed by a query
        """
        geo_object_loads = aerospike.GeoJSON({"type": "Polygon", "coordinates": [[[-124.500000, 
            37.000000],[-125.000000, 37.000000], [-121.000000, 38.080000],[-122.500000, 
                38.080000], [-124.500000, 37.000000]]]})

        geo_object_loads.loads('{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000],[-122.500000, 38.080000], [-122.500000, 37.000000]]]}')

        assert geo_object_loads.unwrap() == {'coordinates': [[[-122.5, 37.0], [-121.0, 37.0], [-121.0, 38.08],
            [-122.5, 38.08], [-122.5, 37.0]]], 'type': 'Polygon'}

        records = []
        query = TestGeospatial.client.query("test", "demo")
        query.where(p.geo_within_geojson_region("loc", geo_object_loads.dumps()))

        def callback((key, metadata, record)):
            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 test_geospatial_positive_query_for_circle(self):
        """
            Perform a positive geospatial query for a circle
        """
        if TestGeospatial.skip_old_server is True:
            pytest.skip(
                "Server does not support apply on AeroCircle for GeoJSON")

        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.GeoJSON(
            {"type": "AeroCircle", "coordinates": [[-122.0, 37.5], 250.2]})

        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) == 1
        expected = [{'coordinates': [-122.0, 37.5], 'type': 'Point'}]
        for r in records:
            assert r['loc'].unwrap() in expected
示例#3
0
    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
示例#4
0
    def test_geospatial_within_geojson_region_pred(self, bin_name, idx_type):

        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.geodata({
            "type":
            "Polygon",
            "coordinates":
            [[[-122.500000, 37.000000], [-121.000000, 37.000000],
              [-121.000000, 38.080000], [-122.500000, 38.080000],
              [-122.500000, 37.000000]]]
        })

        predicate = p.geo_within_geojson_region(bin_name, geo_object2.dumps(),
                                                idx_type)

        query.where(predicate)

        def callback(input_tuple):
            _, _, record = input_tuple
            records.append(record)

        query.foreach(callback)

        assert len(records) == 3
示例#5
0
    def test_geospatial_positive_query_for_circle(self):
        """
            Perform a positive geospatial query for a circle
        """
        if TestGeospatial.skip_old_server is True:
            pytest.skip(
                "Server does not support apply on AeroCircle for GeoJSON")

        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.GeoJSON({
            "type": "AeroCircle",
            "coordinates": [[-122.0, 37.5], 250.2]
        })

        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) == 1
        expected = [{'coordinates': [-122.0, 37.5], 'type': 'Point'}]
        for r in records:
            assert r['loc'].unwrap() in expected
示例#6
0
    def test_geospatial_positive_query_outside_shape(self):
        """
            Perform a positive geospatial query for polygon where all points
            are outside polygon
        """
        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.GeoJSON({
            "type":
            "Polygon",
            "coordinates":
            [[[-126.500000, 37.000000], [-124.000000, 37.000000],
              [-124.000000, 38.080000], [-126.500000, 38.080000],
              [-126.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) == 0
    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 test_geospatial_within_geojson_region_pred(self, bin_name, idx_type):

        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.geodata({"type": "Polygon",
                                         "coordinates": [[
                                             [-122.500000, 37.000000],
                                             [-121.000000, 37.000000],
                                             [-121.000000, 38.080000],
                                             [-122.500000, 38.080000],
                                             [-122.500000, 37.000000]]]})

        predicate = p.geo_within_geojson_region(
            bin_name, geo_object2.dumps(), idx_type)

        query.where(predicate)

        def callback(input_tuple):
            _, _, record = input_tuple
            records.append(record)

        query.foreach(callback)

        assert len(records) == 3
    def test_geospatial_loads_positive_with_query(self):
        """
            Perform a positive loads on geoJSON raw string followed by a query
        """
        geo_object_loads = aerospike.GeoJSON({"type": "Polygon", "coordinates": [[[-124.500000, 
            37.000000],[-125.000000, 37.000000], [-121.000000, 38.080000],[-122.500000, 
                38.080000], [-124.500000, 37.000000]]]})

        geo_object_loads.loads('{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000], [-121.000000, 37.000000], [-121.000000, 38.080000],[-122.500000, 38.080000], [-122.500000, 37.000000]]]}')

        assert geo_object_loads.unwrap() == {'coordinates': [[[-122.5, 37.0], [-121.0, 37.0], [-121.0, 38.08],
            [-122.5, 38.08], [-122.5, 37.0]]], 'type': 'Polygon'}

        records = []
        query = TestGeospatial.client.query("test", "demo")
        query.where(p.geo_within_geojson_region("loc", geo_object_loads.dumps()))

        def callback((key, metadata, record)):
            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 test_geospatial_loads_positive_with_query(self):
        """
            Perform a positive loads on geoJSON raw string followed by a query
        """
        geo_object_loads = get_geo_object()

        geo_object_loads.loads(
            '{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000],\
             [-121.000000, 37.000000], [-121.000000, 38.080000],\
             [-122.500000, 38.080000], [-122.500000, 37.000000]]]}')

        assert geo_object_loads.unwrap() == {
            'coordinates': [[[-122.5, 37.0], [-121.0, 37.0],
                             [-121.0, 38.08], [-122.5, 38.08],
                             [-122.5, 37.0]]], 'type': 'Polygon'}

        records = []
        query = self.as_connection.query("test", "demo")
        query.where(
            p.geo_within_geojson_region("loc", geo_object_loads.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 test_geospatial_positive_query_outside_shape(self):
        """
            Perform a positive geospatial query for polygon where all points
            are outside polygon
        """
        records = []
        query = self.as_connection.query("test", "demo")

        geo_object2 = aerospike.GeoJSON({"type": "Polygon",
                                         "coordinates": [[
                                             [-126.500000, 37.000000],
                                             [-124.000000, 37.000000],
                                             [-124.000000, 38.080000],
                                             [-126.500000, 38.080000],
                                             [-126.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) == 0
    def test_geospatial_positive_query(self):
        """
            Perform a positive geospatial query for a polygon
        """
        records = []
        query = TestGeospatial.client.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 test_geospatial_loads_positive_with_query(self):
        """
            Perform a positive loads on geoJSON raw string followed by a query
        """
        geo_object_loads = get_geo_object()

        geo_object_loads.loads(
            '{"type": "Polygon", "coordinates": [[[-122.500000, 37.000000],\
             [-121.000000, 37.000000], [-121.000000, 38.080000],\
             [-122.500000, 38.080000], [-122.500000, 37.000000]]]}')

        assert geo_object_loads.unwrap() == {
            'coordinates': [[[-122.5, 37.0], [-121.0, 37.0],
                             [-121.0, 38.08], [-122.5, 38.08],
                             [-122.5, 37.0]]], 'type': 'Polygon'}

        records = []
        query = self.as_connection.query("test", "demo")
        query.where(
            p.geo_within_geojson_region("loc", geo_object_loads.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
示例#14
0
    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_geospatial_positive_query(self):
        """
            Perform a positive geospatial query for a polygon
        """
        records = []
        query = TestGeospatial.client.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((key, metadata, record)):
            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 test_geospatial_positive_query_with_geodata(self):
        """
            Perform a positive geospatial query for a polygon with geodata
        """
        records = []
        query = TestGeospatial.client.query("test", "demo")

        geo_object2 = aerospike.geodata({"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((key, metadata, record)):
            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