def test_geospatial_put_get_positive_with_geodata(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.geodata(
            {"type": "Point", "coordinates": [42.34, 58.62]})
        geo_object_dict = aerospike.geodata(
            {"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_put_get_positive_with_geodata(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.geodata(
            {"type": "Point", "coordinates": [42.34, 58.62]})
        geo_object_dict = aerospike.geodata(
            {"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)
예제 #3
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
    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_positive_query_with_geodata(self):
        """
            Perform a positive geospatial query for a polygon with geodata
        """
        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]]]})

        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_positive_query_with_geodata(self):
        """
            Perform a positive geospatial query for a polygon with geodata
        """
        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]]]})

        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