[SERVER-46787] Support geoJson with 2d index Created: 11/Mar/20  Updated: 27/Dec/23

Status: Backlog
Project: Core Server
Component/s: Geo, Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Damiano Barboni Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 0
Labels: qi-geo
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File sentinel_polygon.png    
Assigned Teams:
Query Integration
Participants:

 Description   

As documented here https://docs.mongodb.com/manual/core/2d/ 2d Indexes can not be used to store GeoJSON and for this kind of geometries the correct index should be the 2dsphere.

Trying to load polygons conceived in a plane with a 2dsphere index is possible to receive an error like:

Edges 171 and 221 cross. Edge locations in degrees: [-180.0000000, 85.0511500]-[-180.0000000, 0.0000000] and [-180.0000000, -74.5979195]-[-180.0000000, -85.0511500]

I don't want to discuss the error above, for me is clear. The problem is that there are professional sectors where most of the available geometry resources are "flat" and also the adopted software tools make this assumption.

The error above for example refers to the polygon of a Sentinel dataset provided by the ESA but affects also datasets/geometry provided by NASA, USGS and so on. The provided field of view of this rasters are not wrong but are coordinates mapped on a plane not on a sphere.

Sorry if I went too long. Summarising, what in my opinion should be useful is the support of geoJson also with a 2d index.

Thanks

Damiano



 Comments   
Comment by Damiano Barboni [ 22/Oct/20 ]

Hi @kateryna.kamenieva ,

The query below try to insert a polygon that came from a Sentinel dataset and is an example of a geometry that is valid on a "flat Earth" but not with the 2dsphere index. 

I tried to found a way to handle this error but until now, in case of exception, the only workaround is to replace the real dataset footprint with a rectangular bounding box.
Do you know about the existence of some tool/library that can be used to perform and automate a kind of "reprojection" of the polygon on a 3D surface?

 

db.test.insertOne({geometry:{ type: "Polygon", coordinates: [ [ [ -44.74779976, 81.01643883 ], [ 0.0, -44.74779976 ], [ 80.74934903099999, -0.147521676 ], [ 81.06045689, 0.0 ], [ -38.49267456, 80.07679594 ], [ -37.296921296, 76.21663527600001 ], [ -44.74779976, 81.01643883 ] ] ] }})

The error:

2020-10-22T13:41:44.095+0000 E  QUERY    [js] WriteError({
        "index" : 0,
        "code" : 16755,
        "errmsg" : "Can't extract geo keys: { _id: ObjectId('5f918c18ae0e4a40eb359137'), geometry: { type: \"Polygon\", coordinates: [ [ [ -44.74779976, 81.01643883 ], [ 0.0, -44.74779976 ], [ 80.74934903099999, -0.147521676 ], [ 81.06045689, 0.0 ], [ -38.49267456, 80.07679594 ], [ -37.296921296, 76.21663527600001 ], [ -44.74779976, 81.01643883 ] ] ] } }  Loop is not valid: [ [ -44.74779976, 81.01643883 ], [ 0.0, -44.74779976 ], [ 80.74934903099999, -0.147521676 ], [ 81.06045689, 0.0 ], [ -38.49267456, 80.07679594 ], [ -37.296921296, 76.21663527600001 ], [ -44.74779976, 81.01643883 ] ] Edges 0 and 4 cross. Edge locations in degrees: [-44.7477998, 81.0164388]-[0.0000000, -44.7477998] and [-38.4926746, 80.0767959]-[-37.2969213, 76.2166353]",
        "op" : {
                "_id" : ObjectId("5f918c18ae0e4a40eb359137"),
                "geometry" : {
                        "type" : "Polygon",
                        "coordinates" : [
                                [
                                        [
                                                -44.74779976,
                                                81.01643883
                                        ],
                                        [
                                                0,
                                                -44.74779976
                                        ],
                                        [
                                                80.749349031,
                                                -0.147521676
                                        ],
                                        [
                                                81.06045689,
                                                0
                                        ],
                                        [
                                                -38.49267456,
                                                80.07679594
                                        ],
                                        [
                                                -37.296921296,
                                                76.216635276
                                        ],
                                        [
                                                -44.74779976,
                                                81.01643883
                                        ]
                                ]
                        ]
                }
        }
}) :
WriteError({
        "index" : 0,
        "code" : 16755,
        "errmsg" : "Can't extract geo keys: { _id: ObjectId('5f918c18ae0e4a40eb359137'), geometry: { type: \"Polygon\", coordinates: [ [ [ -44.74779976, 81.01643883 ], [ 0.0, -44.74779976 ], [ 80.74934903099999, -0.147521676 ], [ 81.06045689, 0.0 ], [ -38.49267456, 80.07679594 ], [ -37.296921296, 76.21663527600001 ], [ -44.74779976, 81.01643883 ] ] ] } }  Loop is not valid: [ [ -44.74779976, 81.01643883 ], [ 0.0, -44.74779976 ], [ 80.74934903099999, -0.147521676 ], [ 81.06045689, 0.0 ], [ -38.49267456, 80.07679594 ], [ -37.296921296, 76.21663527600001 ], [ -44.74779976, 81.01643883 ] ] Edges 0 and 4 cross. Edge locations in degrees: [-44.7477998, 81.0164388]-[0.0000000, -44.7477998] and [-38.4926746, 80.0767959]-[-37.2969213, 76.2166353]",
        "op" : {
                "_id" : ObjectId("5f918c18ae0e4a40eb359137"),
                "geometry" : {
                        "type" : "Polygon",
                        "coordinates" : [
                                [
                                        [
                                                -44.74779976,
                                                81.01643883
                                        ],
                                        [
                                                0,
                                                -44.74779976
                                        ],
                                        [
                                                80.749349031,
                                                -0.147521676
                                        ],
                                        [
                                                81.06045689,
                                                0
                                        ],
                                        [
                                                -38.49267456,
                                                80.07679594
                                        ],
                                        [
                                                -37.296921296,
                                                76.216635276
                                        ],
                                        [
                                                -44.74779976,
                                                81.01643883
                                        ]
                                ]
                        ]
                }
        }
})
 
 
 

 

The following image represent the polygon on a 2D geoJson viewer

Comment by Katya Kamenieva [ 07/Oct/20 ]

Hi barboni@meeo.it,

We are not planning on developing 2d indexes further, but ability to operate on the flat coordinate system is a feature that we will consider in the future. Currently, it is not scheduled for implementation.

Could you provide an example of the dataset and what kind of queries you are looking to run against it? I'd like to understand if geospatial query operators and geoJSON geometries that exist in MongoDB today would satisfy your use case?

Comment by Eric Sedor [ 11/Mar/20 ]

Thank you for the detailed description, barboni@meeo.it. We're assigning this ticket to the appropriate team to be evaluated against our currently planned work. Updates will be posted on this ticket as they happen.

Eric

Generated at Thu Feb 08 05:12:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.