Mongoengine geospatial search Mongoengine geospatial search mongodb mongodb

Mongoengine geospatial search


Can you post what you are trying to do??

Point data must be stored in a field with key

"loc":{"lon":51.10682735591432, "lat":-114.11773681640625}or

loc: [22.23432, 21.23212]

With mongoengine there is support for a geopoint field

Class Location:  point = GeoPointField()new_location = Location(point=[21.1232,23.23432])new_location.save()

something like above should work.

class GeoPointField(db_field=None, name=None, required=False, default=None, unique=False, unique_with=None, primary_key=False, validation=None, choices=None, verbose_name=None, help_text=None):

A list storing a latitude and longitude.

New in version 0.4.

http://mongoengine-odm.readthedocs.org/en/latest/apireference.html#mongoengine.GeoPointField


I found the answer in the mongoengine docs:

There are a few special operators for performing geographical queries, that may used with GeoPointFields:

within_distance – provide a list containing a point and a maximum distance (e.g. [(41.342, -87.653), 5])

within_spherical_distance – Same as above but using the spherical geo model (e.g. [(41.342, -87.653), 5/earth_radius])

near – order the documents by how close they are to a given point near_sphere – Same as above but using the spherical geo model

within_box – filter documents to those within a given bounding box (e.g. [(35.0, -125.0), (40.0, -100.0)])

within_polygon – filter documents to those within a given polygon (e.g. [(41.91,-87.69), (41.92,-87.68), (41.91,-87.65), (41.89,-87.65)]). .. note:: Requires Mongo Server 2.0