Geoinformation search Mongoengine

Has anyone used geospatial search with mongengine? I can't seem to get it to work! What is the format of the data to be displayed in GeoPointField?

How do I format it? I can not find anything about creating in the documentation!

+6
source share
2 answers

Can you post what you are trying to do?

Point data must be stored in the key field.

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

loc: [22.23432, 21.23212]

With mongoengine there is support for the geopoly field

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

something like the above should work.

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

A list storing latitude and longitude.

New in version 0.4.

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

+5
source

I found the answer in mongoengine docs :

There are several special operators for performing geographic queries that can be used with GeoPointFields:

within_distance - provide a list containing a point and a maximum distance (for example, [(41.342, -87.653), 5])

within_spherical_distance - Same as above, but using a spherical geomodel (for example, [(41.342, -87.653), 5 / earth_radius])

near - order documents by how close they are to the given point near_sphere - Same as above, but using a spherical geomodel

within_box - filter documents by those that are in the specified bounding box (for example, [(35.0, -125.0), (40.0, -100.0)])

within_polygon - filter documents for those that are in the given polygon (for example, [(41.91, -87.69), (41.92, -87.68), (41.91, -87.65), (41.89, -87.65)]) ... note: : Requires Mongo Server 2.0

+2
source

Source: https://habr.com/ru/post/920997/


All Articles