[SERVER-55027] Geospatial queries over GeoJSONs return wrong results Created: 08/Mar/21 Updated: 15/Aug/22 Resolved: 08/Mar/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo, Index Maintenance, Querying |
| Affects Version/s: | 4.2.6, 4.4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Pavel Antonov | Assignee: | Edwin Zhou |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: | In the following example, I have some stored polygons located over the Baltic sea (between Sweden and Finland). Whenever I draw a polygon over the area where the polygons lie, they are correctly detected, namely all 609 objects are found. (see query and Screenshot_1)
However, the strange behavior occurs when submitting a wider query polygon a little bit below (see Screenshot 2 and 3 with the corresponding queries).
As well as:
Hereby, I also attach three example GeoJSONs that I use:
Thank you in advance! |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Participants: |
| Description |
|
Hello everyone, I am currently working on a project, where I store polygons using the native GeoJSON format and then perform geospatial queries to locate these based on both $geoIntersects and $geoWithin operator. Indeed, everything seemed to be working fine. However, yesterday I discovered a strange behavior, which I am going to reproduce with an example. |
| Comments |
| Comment by sudhanshu sirohia [ 15/Aug/22 ] | ||||||||||||
|
Hi Edwin,
We are also facing issues, and tried using the map you shared and the point shows well inside the polygon, however when using intersect query in mongo, the result does not the return below polygon which contains this point
loadGeoJson( { type: "Polygon", coordinates: [ [ *[ 80.14114379882812, 13.011582508520874 ], [ 80.1471519470215, 13.033826278483838 ], [ 80.13702392578126, 13.038341687052323 ], [ 80.12088775634767, 13.043525943415695 ], [ 80.10149002075197, 13.039010629462274 ], [ 80.09204864501955, 13.033157322059589 ], [ 80.08758544921876, 13.0257986820875 ], [ 80.0907611846924, 13.013171415454433 ], [ 80.08878707885744, 13.008822803857846 ], [ 80.08947372436525, 13.006564840836658 ], [ 80.08921623229982, 13.003888709899078 ], [ 80.09033203125001, 13.002383373560995 ], [ 80.09170532226564, 13.000208982727571 ], [ 80.09290695190431, 12.998619992762274 ], [ 80.09325027465822, 12.997072808548213 ], [ 80.09779930114748, 12.992514831438987 ], [ 80.10251998901369, 12.989169473900679 ], [ 80.10543823242189, 12.988751301039581 ], [ 80.10732650756836, 12.98724587291298 ], [ 80.10878562927248, 12.98732950804826 ], [ 80.11058807373048, 12.987496778234293 ], [ 80.11110305786134, 12.98732950804826 ], [ 80.11230468750001, 12.987664048307733 ], [ 80.11376380920412, 12.987664048307733 ], [ 80.11247634887697, 12.987496778234293 ], [ 80.11556625366212, 12.98791495320668 ], [ 80.11350631713869, 12.98791495320668 ], [ 80.11616706848146, 12.98774768330223 ], [ 80.1185703277588, 12.98732950804826 ], [ 80.1208019256592, 12.987413143155283 ], [ 80.12354850769044, 12.98808222299849 ], [ 80.13135910034181, 12.992013030680738 ], [ 80.13925552368165, 12.997700046553673 ], [ 80.14114379882812, 13.011582508520874 ]* ] ] })
loadGeoJson({ type: "Point", coordinates: [ [ [ 13.0127093, 80.1087259]] ] }) | ||||||||||||
| Comment by Pavel Antonov [ 09/Mar/21 ] | ||||||||||||
|
Hi Edwin, Thanks a lot for your detailed answer! Regards, Pavel | ||||||||||||
| Comment by Edwin Zhou [ 08/Mar/21 ] | ||||||||||||
|
This behavior is caused by GeoJSON visualizers attempting to project orthogonal cartesian coordinates on a spherical shape. Many GeoJSON visualizers on the web plot their coordinates in this way, which can be misleading when trying to interpret how MongoDB queries GeoJSON. To view an accurate representation of how MongoDB queries GeoJSON, I recommend using https://geodndmap.mongodb.com/. You can plot polygons by opening up your browser's developer tools, and running the following command:
where you can replace the object with a polygon of your choice. The polygons that you've provided in your reproduction will show up as follows: Best, |