[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: PNG File Screen Shot 2018-04-27 at 4.32.44 PM.png     PNG File Screen Shot 2018-05-02 at 1.03.04 PM.png     PNG File Screen Shot 2018-05-02 at 1.03.26 PM.png    
Issue Links:
Related
related to SERVER-17092 $geoWithin does not return result on ... Closed
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": {
  $geoWithin: {
    $geometry: {
      type: "Polygon",
      coordinates: [],
      crs: {
        type: "name",
        properties:

{           name: "urn:x-mongodb:crs:strictwinding:EPSG:4326"         }

      }
    }
  }

}

 

 

 

Comment by Asya Kamsky [ 28/Apr/18 ]

See also discussion in SERVER-17092

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.
try the below-

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:

db.test.find({"features.geometry":{ $geoWithin: {$box: [  [-60.062125, 46.942589], [-124.046498, 24.556886]  ]}}});
{ "_id" : ObjectId("5a629f84f1653d00012b8fff"), "type" : "FeatureCollection", "features" : [ { "type" : "Feature", "geometry" : { "type" : "Point", "coordinates" : [ -88.24277778, 41.98166667 ] }, "properties" : { "id" : "16107394", "geoHash" : "dp3nzfx8f" } } ] }

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 -
The value below should have been included in the response.

{
"_id" : ObjectId("5a629f84f1653d00012b8fff"),
"type" : "FeatureCollection",
"features" : [
{
"type" : "Feature",
"geometry" :

{ "type" : "Point", "coordinates" : [ -88.24277778, 41.98166667 ] }

,
"properties" :

{ "id" : "16107394", "geoHash" : "dp3nzfx8f" }

}
]
}

Is there something I'm doing wrong here?

Generated at Thu Feb 08 04:37:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.