1

MongoDB can perform geospatial query such as finding restaurants inside region with the operator $geowithin. For example:

db.places.find(
   {
     loc: {
       $geoWithin: {
          $geometry: {
             type : "Polygon" ,
             coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ]
          }
       }
     }
   }
)

I would like to know which algorithm is used by the operator $geoWithin of MongoDB. Can someone provide the pseudo-code?

1

If you mean a point-in-polygon intersection test, it appears to use the raycasting method.

The source of MongoDB is available here on GitHub - look for Polygon::contains .

Wikipedia has a good writeup of the raycasting algorithm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.