def GET(self, name):
        request_params = web.input()
        print(request_params.lat)
        print(request_params.lang)
        latitude = float(request_params.lat)
        langitude = float(request_params.lang)
        radius = int(request_params.radius)
        #pp = pprint.PrettyPrinter(indent=2)
        try:
            client = aerospike.client(config).connect()
            # Records are addressable via a tuple of (namespace, set, key)
            query = client.query('locality', 'location')
            query.select('store', 'seller', 'address', 'loc')
            query.where(p.geo_within_radius('loc', langitude, latitude,
                                            radius))

            stores = []
            sellers = []
            address = []

            def matched_names((key, metadata, bins)):
                #pp.pprint(bins)
                stores.append(bins['store'])
                sellers.append(bins['seller'])
                address.append(bins['address'])

            query.foreach(matched_names)

            storeStr = ''
            addressStr = ''
            sellerStr = ''
            for i in range(0, stores.__len__()):
                storeStr = storeStr + str(stores[i]) + '|'
                addressStr = addressStr + address[i] + '|'
                sellerStr = sellerStr + sellers[i] + '|'
            response = storeStr[:
                                -1] + '~' + sellerStr[:
                                                      -1] + '~' + addressStr[:
                                                                             -1]

            print("Final response::", response)

            return response

            # Close the connection to the Aerospike cluster
            client.close()

        except Exception as e:
            import sys
            print("error: {0}".format(e), file=sys.stderr)
Exemple #2
0
    def test_geospatial_within_radius_pred(self, bin_name, idx_type):

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

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

        predicate = p.geo_within_radius(bin_name, -122.0, 37.5, 250.2,
                                        idx_type)

        query.where(predicate)
        query.foreach(callback)

        assert len(records) == 1
    def test_geospatial_within_radius_pred(self, bin_name, idx_type):

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

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

        predicate = p.geo_within_radius(
            bin_name, -122.0, 37.5, 250.2, idx_type)

        query.where(predicate)
        query.foreach(callback)

        assert len(records) == 1
    def test_geospatial_positive_query_for_circle_with_within_radius_helper(self):
        """
            Perform a positive geospatial query for a circle with helper
        """
        if TestGeospatial.skip_old_server == True:
            pytest.skip("Server does not support apply on AeroCircle for GeoJSON")

        records = []
        query = TestGeospatial.client.query("test", "demo")

        query.where(p.geo_within_radius("loc", -122.0, 37.5, 250.2))

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

        records = []
        query = TestGeospatial.client.query("test", "demo")

        query.where(p.geo_within_radius("loc", -122.0, 37.5, 250.2))

        def callback((key, metadata, record)):
            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
Exemple #6
0
    def test_geo_query_with_geo_within_radius_predicate(self):
        """
            Perform a positive geospatial query for a circle with helper
        """
        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")

        query.where(p.geo_within_radius("loc", -122.0, 37.5, 250.2))

        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
    def test_geo_query_with_geo_within_radius_predicate(self):
        """
            Perform a positive geospatial query for a circle with helper
        """
        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")

        query.where(p.geo_within_radius("loc", -122.0, 37.5, 250.2))

        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
import pprint

config = {'hosts': [('127.0.0.1', 3000)]}
client = aerospike.client(config).connect()

pp = pprint.PrettyPrinter(indent=2)

#client.index_geo2dsphere_create('test', 'pads', 'loc', 'pads_loc_geo')
#bins = {'pad_id': 1,
#        'loc': aerospike.geojson('{"type":"Point", "coordinates":[-80.604333, 28.608389]}')}
#client.put(('test', 'pads', 'launchpad1'), bins)

query = client.query('locality', 'location')
query.select('store', 'seller', 'address', 'loc')
query.where(
    p.geo_within_radius('loc', -94.2217082259192, 36.3689382317293, 1000))
stores = []
sellers = []


def matched_names((key, metadata, bins)):
    pp.pprint(bins)
    stores.append(bins['store'])
    sellers.append(bins['seller'])


query.foreach(matched_names)
pp.pprint(stores[1])
pp.pprint(sellers)
#records = query.results()
client.close()