Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 3.16 KB

geojson.rst

File metadata and controls

93 lines (62 loc) · 3.16 KB

aerospike

GeoJSON Class --- GeoJSON

GeoJSON

Starting with version 3.7.0, the Aerospike server supports storing GeoJSON data. A Geo2DSphere index can be built on a bin which contains GeoJSON data, enabling queries for the points contained within given shapes using ~aerospike.predicates.geo_within_geojson_region and ~aerospike.predicates.geo_within_radius, and for the regions which contain a point using ~aerospike.predicates.geo_contains_geojson_point and ~aerospike.predicates.geo_contains_point.

On the client side, wrapping geospatial data in an instance of the aerospike.GeoJSON class enables serialization of the data into the correct type during write operation, such as ~aerospike.Client.put. On reading a record from the server, bins with geospatial data it will be deserialized into a ~aerospike.GeoJSON instance.

from __future__ import print_function
import aerospike
from aerospike import GeoJSON

config = { 'hosts': [ ('127.0.0.1', 3000)]}
client = aerospike.client(config).connect()
client.index_geo2dsphere_create('test', 'pads', 'loc', 'pads_loc_geo')
# Create GeoJSON point using WGS84 coordinates.
latitude = 28.608389
longitude = -80.604333
loc = GeoJSON({'type': "Point",
               'coordinates': [longitude, latitude]})
print(loc)
# Alternatively create the GeoJSON point from a string
loc = aerospike.geojson('{"type": "Point", "coordinates": [-80.604333, 28.608389]}')

# Create a user record.
bins = {'pad_id': 1,
        'loc': loc}

# Store the record.
client.put(('test', 'pads', 'launchpad1'), bins)

# Read the record.
(k, m, b) = client.get(('test', 'pads', 'launchpad1'))
print(b)
client.close()

Optionally initializes an object with a GeoJSON str or a dict of geospatial data.

wrap(geo_data)

Sets the geospatial data of the ~aerospike.GeoJSON wrapper class.

param dict geo_data

a dict representing the geospatial data.

unwrap() -> dict of geospatial data

Gets the geospatial data contained in the ~aerospike.GeoJSON class.

return

a dict representing the geospatial data.

loads(raw_geo)

Sets the geospatial data of the ~aerospike.GeoJSON wrapper class from a GeoJSON string.

param str raw_geo

a GeoJSON string representation.

dumps() -> a GeoJSON string

Gets the geospatial data contained in the ~aerospike.GeoJSON class as a GeoJSON string.

return

a GeoJSON str representing the geospatial data.

1.0.53