Geofence report using MongoDB - "the right way"

I have a collection of millions of GPS events and a collection of several user-defined geophotos. Geofences are geoJSON polygons.

My mission is to allow my users to select geofence, time range, and then generate a report that shows when their car entered geofencing and then when it left.

The first approach I took is pretty simple and doesn't use any of MongoDB's geospatial features:

  • Run a query to get a list of all GPS events for a time range.
  • Stream (using mongoose QueryStream) the results and notice the first GPS event that goes into geofencing, and then notice the next GPS event that goes out. Insert these 2 events into an array. A simple point-in-polygon function is used to determine if a GPS event is inside or outside the geoforums.
  • The result looks like this: [{start: start_event, finish: finish_event}, {start: start_event, finish: finish_event}]

Of course, this is probably the most inefficient way to do it, and of course, if I increase the date range in a couple of days, the time it takes becomes too long.

There are two other approaches I am thinking of:

  • Instead of tracing all the events using the process above, first limit the list of GPS events to those near the geofence. For example, if I can work out the bounding box of a geogonal polygon, I can define maxDistance to query $ geoNear. This should significantly reduce the number of events that need to be handled using the same approach as above.

  • Use the $ geoWithin query to select only events that are within the geopotential. The problem with this is that it is more difficult to determine when the vehicle was entering or exiting. I would have to rely on some time threshold to determine the sessions when the vehicle was inside the geofence.

At this point, I'm leaning towards approach # 1, but I'd love to hear how other people solve this problem with MongoDB - specifically using the aggregation pipeline or mapreduce.

+3
node.js mongodb mongoose geospatial


source to share


No one has answered this question yet

Check out similar questions:

1299
How to query MongoDB with "how"?
825
How to delete MongoDB database from command line?
619
MongoDB vs Kassandra
396
Find MongoDB records where array field is not empty
2
Does $ geoNear query in MongoDB aggregate pipeline limit the number of documents?
2
Mongodb Geospatial Index doesn't support $ box?
1
MongoDB $ query precision question
1
Does MongoDB support GIS geoinformation using $ geoWithin?
0
mongodb 2.4.9 $ geoWithin Query for a very simple dataset that returns no results. What for?
0
Link to GeoJson object in mongodb



All Articles
Loading...
X
Show
Funny
Dev
Pics