1

My question seems unclear. Put it in details: I generate a pymongo database on client and in this database I have a collection of documents, which are all in this format:

{"_id": ...,
 "latlng":{"type":"Polygon",
           "coordinates":[[[-121.1,47.5],[-121.1,47.6],
                           [-121.2,47.6],[-121.2,47.5],
                           [-121.1,47.5]]]},
 "self":{"school":1, "home":2}} 

Actually, this collection is to segment a city into grids and each document describes a grid.

Now my problem is that: if given a new point (new coordinates),I need to determine which grid the point is in and I want to realize this as fast as possible (because the whole city is really large and I have 2 million grids).

So anyone knows a good method? (I want to realize this by querying the database and using GeoJSON since my grid coordinates are of GeoJSON format, however I didn't find a command (like geoWithin) that can match a point to a polygon containing it)

I notice that there are some similar questions but I am wondering whether someone has experience using pymongo database and dealing with the same problem. Thanks a lot if you could share your experience with me.

Jay Kominek
  • 8,674
  • 1
  • 34
  • 51
gladys0313
  • 2,569
  • 6
  • 27
  • 51
  • 1
    possible duplicate of [Point in Polygon aka hit test](http://stackoverflow.com/questions/217578/point-in-polygon-aka-hit-test) – stark Apr 18 '15 at 13:40
  • thanks! But I am wondering whether there is a command like geoWithin which is more convenient and faster, otherwise I need to use the if-loop to compare the point with all grid coordinates until I find the matching one..... – gladys0313 Apr 18 '15 at 15:31

0 Answers0