Skip to main content

Indexing and querying geospatial data in App Engine.

Project description

GeoModel uses geohash-like objects called ‘geocells’ to provide a generalized solution for indexing and querying geospatial data in App Engine. GeoModel is optimized for the basic real estate finder/store locator use case, but can be adapted for use with large datasets.

Using GeoModel, developers can instantly geo-contextualize datastore models by simply inherting from the GeoModel class. Currently, entities can be associated with a single geographic point and subsequently indexed and filtered by either conformance to a bounding box or by proximity (nearest-n) to a search center point.

Changes

Version 0.2.0 (2009-08-31)

Version 0.1.0 (2009-07-15)

  • Initial PyPI release.

Creating and saving GeoModel-derived entities

To use the GeoModel class, simply declare a new model class inheriting from the geomodel.GeoModel class like so:

>>> import google.appengine.ext.db
>>> import geo.geomodel
>>> class MyEntity(geo.geomodel.GeoModel):
...     foo = google.appengine.ext.db.StringProperty()
...     bar = google.appengine.ext.db.IntegerProperty()

Currently, only single-point entities are supported. Entities of the new MyEntity kind will have a location property of type db.GeoPt, which can be set as needed. Before put()’ing entities to the datastore, make sure to call update_location to synchronize the entity’s underlying geocell indexing properties:

>>> some_entity = MyEntity(location=google.appengine.ext.db.GeoPt(37, -122),
...                        foo='Hello',
...                        bar=5)
>>> some_entity.location = google.appengine.ext.db.GeoPt(38, -122)
>>> some_entity.update_location()
>>> some_entity.put()
datastore_types.Key.from_path(u'MyEntity', 1, _app=u'test')

Querying your entities

There are currently two types of basic geospatial queries supported by the GeoModel library:

  • bounding box queries

  • proximity (nearest-n) queries

To perform a bounding box query, use the bounding_box_fetch class method like so:

>>> import geo.geotypes
>>> results = MyEntity.bounding_box_fetch(
...               MyEntity.all().filter('bar >', 4),  # Rich query!
...               geo.geotypes.Box(39, -121, 37, -123),
...               max_results=10)
>>> results[0].foo
u'Hello'

Be careful not to request too many results or else you’ll get a datastore or request timeout!

To perform a proximity query, use the proximity_fetch class method like so:

>>> result = MyEntity.proximity_fetch(
...               MyEntity.all().filter('bar <', 10),  # Rich query!
...               geo.geotypes.Point(39, -121),  # Or db.GeoPt
...               max_results=10,
...               max_distance=160934)  # Within 100 miles.
>>> result[0].foo
u'Hello'

Note that for rich queries on multiple properties you’ll need to set up the proper indexes in your index.yaml file. Testing your app on the development server should populate that file with the required indexes. Also, GeoModel currently requires many internal properties on each entity (one for each geocell resolution), which can lead to messy looking index.yaml files. That’s something that will hopefully change in future versions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geomodel-0.2.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

geomodel-0.2.0-py2.5.egg (38.8 kB view details)

Uploaded Source

File details

Details for the file geomodel-0.2.0.tar.gz.

File metadata

  • Download URL: geomodel-0.2.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for geomodel-0.2.0.tar.gz
Algorithm Hash digest
SHA256 61f99cdd8959e4cfc5981c6b8dc3f989acb5239d5876d73c4e7358bd824c2751
MD5 c362e57cb987d0b1c53383076b0aaa8f
BLAKE2b-256 05b1d102c703f447a9fe96421c8c6865d3878348631ad6c54bb99445c15451ab

See more details on using hashes here.

File details

Details for the file geomodel-0.2.0-py2.5.egg.

File metadata

  • Download URL: geomodel-0.2.0-py2.5.egg
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for geomodel-0.2.0-py2.5.egg
Algorithm Hash digest
SHA256 500bfb528001004d37a47ee48fab55fc604e9d2bedd62564809ba660a613381d
MD5 70bec329b3f1216c6d68ed8f1842dc09
BLAKE2b-256 c99d74a1f252b32829d76aebb840c187d6aa55252d04df1cd003ffc5ad4c9911

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page