[SERVER-27968] $geoWithin with $centerSphere does not find GeoJSON documents other than Points Created: 09/Feb/17 Updated: 12/Oct/17 Resolved: 10/Oct/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo, Querying |
| Affects Version/s: | 3.4.0 |
| Fix Version/s: | 3.6.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Derick Rethans | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Operating System: | ALL | ||||||||||||||||
| Backport Requested: |
v3.4
|
||||||||||||||||
| Sprint: | Query 2017-11-13 | ||||||||||||||||
| Participants: | |||||||||||||||||
| Description |
|
Compare:
With a distance of 500km, it should certainly find documents. The range below (1 degree) is much less (about 100km):
|
| Comments |
| Comment by Githook User [ 10/Oct/17 ] | ||||||||||||||||||||||||||
|
Author: {'email': 'tess.avitabile@mongodb.com', 'name': 'Tess Avitabile', 'username': 'tessavitabile'}Message: | ||||||||||||||||||||||||||
| Comment by Githook User [ 10/Oct/17 ] | ||||||||||||||||||||||||||
|
Author: {'email': 'ramon@mongodb.com', 'name': 'Ramon Fernandez'}Message: Revert " This reverts commit f24f7830d01193db30102b8381eeaf4c011d0ea9. | ||||||||||||||||||||||||||
| Comment by Githook User [ 10/Oct/17 ] | ||||||||||||||||||||||||||
|
Author: {'email': 'sindbach@gmail.com', 'name': 'Wan Bachtiar', 'username': 'sindbach'}Message: Closes #1184 Signed-off-by: Tess Avitabile <tess.avitabile@mongodb.com> | ||||||||||||||||||||||||||
| Comment by Wan Bachtiar [ 06/Oct/17 ] | ||||||||||||||||||||||||||
| Comment by Tess Avitabile (Inactive) [ 14/Mar/17 ] | ||||||||||||||||||||||||||
|
Inspecting the code, it looks to me like this is intentional. For $geoWithin queries, we only expect to match "LineString" and "Polygon" GeoJSON documents when the query geometry is a "Polygon" or "MultiPolygon": Matching for points is done here:
Matching for lines is done here. There is no case for $centerSphere, so we reach the end of the function:
Matching for polygons is done here. There is no case for $centerSphere, so we reach the end of the function:
We could consider implementing this feature and/or documenting the current behavior. david.storch, do you have thoughts on how we should proceed? | ||||||||||||||||||||||||||
| Comment by Wan Bachtiar [ 17/Feb/17 ] | ||||||||||||||||||||||||||
|
A couple of things to point out based on the above example documents: A) The last entry for Polygon is not a valid GeoJSON polygon. A GeoJSON single ring polygon need to be enclosed in another array. i.e.
https://docs.mongodb.com/manual/reference/geojson/#polygons-with-a-single-ring B) The 'GeoJSON' documents are on top level and querying by specifying field coordinates is being treated it as if they were an array of legacy coordinates. You can observe this, by correcting the polygon document as per point A, the query below would only return 'Point' and 'LineString'. (Because the GeoJSON polygon, being an array of array of pair coordinates no longer satisfies the legacy coordinate format)
Let's change the document structure, by taking a similar structure example of GeoJSON documents as per documentation: https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/#exploring-the-data
The below query :
Would only return 'Point', where it should have returned all three valid GeoJSON documents. I've also attached a jstest file for testing convenience. | ||||||||||||||||||||||||||
| Comment by Kyle Suarez [ 16/Feb/17 ] | ||||||||||||||||||||||||||
|
derick, MongoDB does indeed support finding all types of GeoJSON with $centerSphere, according to the documentation. After talking to siyuan.zhou, I think there's something weird about your query: the second argument to $centerSphere is the radius specified in radians. If you want to find things within a distance of 500 kilometers, you should specify the radius as 500/6378.1, since the equatorial radius of the Earth is approximately 3,963.2 miles or 6,378.1 kilometers (cf. this docs page). I am not good at all at spherical geometry, though, and it might still be that there's a bug. However, a sanity check locally confirms that $centerSphere can indeed find all sorts of GeoJSON:
| ||||||||||||||||||||||||||
| Comment by Kyle Suarez [ 16/Feb/17 ] | ||||||||||||||||||||||||||
|
siyuan.zhou, is this expected behavior? |