$geoWithin return document located outside the polygon queried

Original post here: mongodb - $geoWithin return document located outside the polygon queried - Stack Overflow

I’ve recently came across this behaviour that I cannot explain. $geowithin return documents outside the polygon queried.

To illustrate my problem, I’ve made a mongodb playground with 3 documents with geometries all located outside the polygon.

Can someone spot what I’m missing here?

Cheers

I said this in the SO question but I can elaborate here: all three of your points are NOT inside this polygon. The query correctly returns the point that’s not inside.

It would be easier to visualize by plotting the smaller rectangle on the globe - I did it on Google Earth, and I think it would be easier to see that two of your points (the two somewhere near Thailand?) are inside of this polygon but the one in South of France is outside of it.

Your three points:

The smaller polygon projected onto Google Earth:

Two of your points are right in the middle of this picture, putting them inside the clockwise polygon, therefore they would be outside the counterclockwise (big) polygon, but the third point would not be.

Asya

Thank you Asya for your answer. I misunderstood the concept of “big” polygon and it is a lot clearer now.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.