[SERVER-15388] find 'big polygon' geo objects after the 2.8 release Created: 24/Sep/14  Updated: 06/Dec/22  Resolved: 14/Feb/20

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

Type: New Feature Priority: Major - P3
Reporter: Quentin Conner Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-45189 Allow strictwinding property also for... Backlog
is duplicated by SERVER-45189 Allow strictwinding property also for... Backlog
Assigned Teams:
Query
Participants:

 Description   

It would be nice for GEO queries to find stored Big Polygon documents, after the 2.8 release that allows $geoWithin and $geoIntersect queries that reference Big Polygon GeoJson objects.

Big Polygon means a polygon with area larger than one hemisphere.

The following mongo shell script would work with the feature addition.

// current CRS
var CRS = {};
CRS.type = 'name';
CRS.properties = {};
CRS.properties.name = 'urn:mongodb:strictwindingcrs:EPSG:4326';
 
// Big Polygon covering both poles
// this document will NOT be found in the 2.8 release
// b/c this feature does not recognize stored big polygon objects
var bigPoly = {};
bigPoly.geo = {};
bigPoly.name = 'big polygon/rectangle covering both poles';
bigPoly.geo.type = 'Polygon';
bigPoly.geo.crs = CRS;
bigPoly.geo.coordinates = [
              [ [ -130.0, 89.0 ], [ -120.0, 89.0 ], [ -120.0, -89.0 ], [ -130.0, -89.0 ], [ -130.0, 89.0 ] ]
            ];
db.foo.insert(bigPoly);
 
 
 
 
// Triangle around Shenzhen, China
var shenzhenPoly = {};
shenzhenPoly.type = 'Polygon';
shenzhenPoly.coordinates = [
                             [
                               [ 114.0834046, 22.6648202 ],
                               [ 114.2736054, 22.4047911 ],
                               [ 113.8293457, 22.3819359 ],
                               [ 114.0834046, 22.6648202 ]
                             ]
                           ];
shenzhenPoly.crs = CRS;
db.foo.find({geo: {$geoWithin: {$geometry: shenzhenPoly}}});



 Comments   
Comment by Eric Sedor [ 14/Feb/20 ]

This request is now tracked by SERVER-45189. Please watch that ticket for updates.

Comment by Siyuan Zhou [ 13/Oct/14 ]

FranckL,

SERVER-15626 has been filled to support longitude of -181. Thank you for pointing out this issue. However I don't think it will come with 2.8. Please follow that ticket to track its status.

Just to make it clear, rendering this polygon is actually a problem of map projection. Leaflet and Google Map use EPSG:3857 projection, which allows longitude like -181. Map projection is used to display the shapes on the earth, defining how to represent, for example, a point (longitude -181 and 179 are different), a line (the straight line on the map) and a polygon (the area bounded by lines defined above). They are fundamentally different with the model WGS84 used by MongoDB and GPS, which is used to define the shapes on the earth. In WGS84, longitude -181 and 179 are the same and a line is defined by the shortest path on the earth (maybe a curve on the map). This is why your polygon is not a big polygon in the ticket's context, regardless of the map projection.

Since there are so many different kinds of map projection (See D3 Geo Projection), it is impossible for us to support all of them, but we can definitely make using the most common projections easier, like the above SERVER-15626.

Thanks,
Siyuan

Comment by Franck Lahaye [ 08/Oct/14 ]

Siyuan,

Is the support for the extended range of values (>180 and <-180) planned for mongodb 2.8 ?

Changing my longitude values from -181 to +179 is rendering a big polygon using librairies like leaflet (not the smaller one as mongodb assumes).
I will have to create a separate collection for geoqueries in the meantime

Thank you for your precious help,
-Franck

Comment by Siyuan Zhou [ 08/Oct/14 ]

FranckL,

Longitude -181 is actually +179, so replacing -181 with 179 should work for you. We understand that some libraries allow longitude to be less than -180 or greater than 180, but MongoDB doesn't support that yet.

Unfortunately, GeoJSON only defines the syntax of a geometry and some part of the semantic (like the ordering of longitude and latitude). The range of values is not defined in GeoJSON and depends on implementations. The lack of semantic definition is also a reason for this big polygon feature - which side of a polygon on the earth should be the inside? Without "big polygon", we usually assume the smaller one is the inside.

Currently building a 2dsphere index is a way to ensure the correct geometry format.

Thanks,
Siyuan

Comment by Franck Lahaye [ 08/Oct/14 ]

Hi Siyuan,

So the only solution would be to split the polygon in 2 distinct features to perform the geoIntersect query ?
It is quite problematic.

Do you know where I could find the specification for a correctly formed geojson ? I did not see a reference to it on geojson.org.
I never suspected this issue as mapbox/leaflet and tools like geojson.io all displayed my polygons correctly.

Best,
-Franck

Comment by Siyuan Zhou [ 08/Oct/14 ]

Hi FranckL,

Thanks for your question. Yes, it is normal and it's not relevant to the "big polygon" feature.

The given GeoJSON document is considered malformed since the longitude is greater than 180. When answering the above query, MongoDB doesn't understand the document and ignores it silently to respect “schemaless” style. This can be proved by building a 2dsphere index on "features.geometry". MongoDB will return an error when building 2dsphere index for malformed geometries.

longitude/latitude is out of bounds, lng: -181 lat: 80

Comment by Franck Lahaye [ 08/Oct/14 ]

Hi Greg,

Could you please consider the following query and GeoJSON :
db.test.find({
"features.geometry": {
"$geoIntersects": {
"$geometry":

{ "type": "Point", "coordinates": [ -104.4140625, 43.32517767999296 ] }

}
}
})

{
"type" : "FeatureCollection",
"features" : [
{
"type" : "Feature",
"geometry" :

{ "type" : "Polygon", "coordinates" : [ [ [ -130, 10 ], [ -50, 10 ], [ -50, 60 ], [ -100, 80 ], [ -181, 80 ], [ -170, 57 ], [ -130, 10 ] ] ] }

}
]
}

The polygon is smaller than an hemisphere but the query returns no results.
If I change [-181,80] by [-180,80] the query returns the document.

Is it a normal behaviour ? if the polygon is smaller than an hemisphere (or less than 180° of long according to https://jira.mongodb.org/browse/DOCS-1391?jql=text%20~%20%22hemisphere%22) mongodb should not have an issue, correct ?

Thanks

Comment by Greg Studer [ 25/Sep/14 ]

There's two big issues here - the first is that no other application will understand the CRS of these objects, and so this encourages users to store GeoJSON data in an incompatible way. The other problem is that we need to come up with rules regarding how different CRSes are stored and queried in MongoDB - right now we have a lot of inconsistency here.

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