[SERVER-34699] $geoWithin doesn't return correct geo-points when using $box query Created: 26/Apr/18 Updated: 08/May/18 Resolved: 27/Apr/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo |
| Affects Version/s: | 3.6.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rachita Bansal | Assignee: | Asya Kamsky |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
I'm trying to find geolocations inside a geographical area using a bounding box but it seems that $geoWithin query doesn't return correct points at certain range of the bounding box. Adding an example query below. db.wisp.find({"features.geometry":{ $geoWithin: {$box: [[156.82969752500003, -8.287855253974222],[-10.05235377500002, 61.99562499932121]]}}}); An observation - If I make the south-west longitude value to -156, then correct values are returned. |
| Comments |
| Comment by Rachita Bansal [ 02/May/18 ] | ||
|
I'm a little confused here because I tried using the CRS field for big polygons (reference - http://man.hubwiz.com/docset/MongoDB.docset/Contents/Resources/Documents/docs.mongodb.org/manual/reference/operator/query/geoWithin/index.html#geowithin-big-poly) I'm using a query something like below for all bounding box - It works well with bounding box more than a single hemisphere but when I use the same query for small polygons, the results are still incorrect. For example, if I try using the below query for these coordinates - [ [ [ -122.73918903125002, 23.414729495765084 ], [ -122.73918903125002, 41.78103456202856 ], [ -69.43352496875002, 41.78103456202856 ], [ -69.43352496875002, 23.414729495765084 ], [ -122.73918903125002, 23.414729495765084 ] ] ] There are no results found. Attaching expected result and actual result with this query. "features.geometry": { } }
| ||
| Comment by Asya Kamsky [ 28/Apr/18 ] | ||
|
See also discussion in | ||
| Comment by Asya Kamsky [ 28/Apr/18 ] | ||
|
Also note $box Behavior where flat (planar) geometry is used. | ||
| Comment by Asya Kamsky [ 28/Apr/18 ] | ||
|
Please note from our documentation: For $geoWithin queries that specify GeoJSON geometries with areas greater than a single hemisphere, the use of the default CRS results in queries for the complementary geometries. | ||
| Comment by Rachita Bansal [ 27/Apr/18 ] | ||
|
As another example, I'm adding the query and results below. db.data.find({"features.geometry":{ $geoWithin: {$box: [[ 179.37364283750003, 17.08804354613255 ], [ -17.76502903749997, 52.126584787009975 ]]}}}) On the map, the bounding box returns something like below. There is around 7k geo points which lie inside the rectangular region but the query doesn't return any. An example geo point is as below, { "_id" : ObjectId("5a629f84f1653d00012b9049"), "type" : "FeatureCollection", "features" : [ { "type" : "Feature", "geometry" : { "type" : "Point", "coordinates" : [ -75.46488889, 40.34077778 ] }, "properties" : { "id" : "15844522", "geoHash" : "dr4m6zb4h" }} ] } Moving just a little bit to the east, the geo points are returned. db.data.find({"features.geometry":{ $geoWithin: {$box: [[ -179.6524151097331, 17.739545644708063 ], [ -16.791086984733056, 52.54379964085976 ]]}}}) | ||
| Comment by Asya Kamsky [ 27/Apr/18 ] | ||
|
rachita.bansal you say that your bounding box represents lower left and upper right coordinates of the map of US. However, keep in mind that coordinates you used do not look like they are in the vicinity of the US. Very approximately, the coordinates of US are [-60.062125, 46.942589] (northeast) and [-124.046498, 24.556886] (southwest). Putting those coordinates in the query, your sample document will be returned:
| ||
| Comment by Rachita Bansal [ 26/Apr/18 ] | ||
|
The bounding box represents lower left and upper right coordinates of the map of US. There should be more than 6k values inside of this but the query returned none. For example - { , } Is there something I'm doing wrong here? |