[SERVER-19328] $geoIntersects does not work as expected Created: 08/Jul/15  Updated: 09/Jul/15  Resolved: 08/Jul/15

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Mateusz Jaworski Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File plot-server-19328.png    
Issue Links:
Related
is related to SERVER-16557 $geoWithin does not return all docume... Closed
is related to SERVER-17092 $geoWithin does not return result on ... Closed
Participants:

 Description   

Collection content:
db.geotest.insert({
"geometry" :

{ "type" : "Polygon", "coordinates" : [[[80,50],[90,50],[90,40],[80,40],[80,50]]] }

})

The following query does not return anything (the searched shape is totally within the polygon):
db.geotest.find({
"geometry":{"$geoIntersects":{"$geometry":{"type":"Polygon",
"coordinates":[[[10,60],[160,60],[160,20],[10,20],[10,60]]]
}}}});

But when we shrink the polygon just a little (160->150, the shape is still inside), we get the expected result:
db.geotest.find({
"geometry":{"$geoIntersects":{"$geometry":{"type":"Polygon",
"coordinates":[[[10,60],[150,60],[150,20],[10,20],[10,60]]]
}}}});

I chose the values to be round and nice, but this appeared many times for the others and I did not find any pattern. I tested it on 3 different mongodb versions: 3.0.4, 2.6.5 and 2.6.9. I tested also with changing points order and custom crs. This example works with setting crs to "urn:x-mongodb:crs:strictwinding:EPSG:4326", but I can find also other examples that failed.

My case is filtering the polygons of countries borders by the visible area and on large polygons (but much smaller than half of the sphere) couple of countries was always missing in the result.

I have no idea if I do sth wrong or this is a bug.



 Comments   
Comment by Sam Kleinman (Inactive) [ 09/Jul/15 ]

We have a tool https://geodndmap.mongodb.com that you can drag geoJSON strings onto the window to plot geometries. Be aware, it doesn't handle invalid GeoJSON/geometries very well.

Comment by Mateusz Jaworski [ 09/Jul/15 ]

OMG. You are right. It is great that you will add this to documentation for other dummies like me.

What did you use for making this map image with polygons?

Thanks!
Mateusz

Comment by Sam Kleinman (Inactive) [ 08/Jul/15 ]

I believe that this is an expected behavior and an effect of map distortion. I've attached a plot of the points you describe, which I think illustrates your results.

DOCS-5199 is a tracking ticket to clarify our documentation of geospatial indexes and queries. I'm going to go ahead and close this ticket, but feel free to open a support request if you have additional questions.

Cheers,
sam

Generated at Thu Feb 08 03:50:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.