[SERVER-34673] Create Index does not support GeoJSON that cross the meridian Created: 25/Apr/18  Updated: 25/Apr/18  Resolved: 25/Apr/18

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

Type: Bug Priority: Major - P3
Reporter: Ching Chang Assignee: Kevin Albertson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-9948 Cannot index a polygon crossing the 1... Closed
Operating System: ALL
Steps To Reproduce:
  • create a collection with a geojson polygon that crosses the merdian (with longitude < -180 or > 180)
  • create an index on the collection
  • see error "longitude/latitude is out of bounds"

    > db.shapefiles.createIndex({geometry:"2dsphere"})
    {
            "ok" : 0,
            "errmsg" : "Can't extract geo keys: { _id: ObjectId('5add7cb127dcb663e5995e15'), type: \"Feature\", properties: { CELLX: -1292, CELLY: 2800, CLAT: 68.5077661, CLONG: -179.9914767, CX: -1046520, CY: 2268000 }, geometry: { type: \"Polygon\", coordinates: [ [ [ -180.00428, 68.5097566 ], [ -179.9861529, 68.5125547 ], [ -179.9786755, 68.5057748 ], [ -179.9967985, 68.5029775 ], [ -180.00428, 68.5097566 ] ] ] } }  longitude/latitude is out of bounds, lng: -180.004 lat: 68.5098",
            "code" : 16755,
            "codeName" : "Location16755"
    }
    

Participants:

 Description   

I have a large GeoJSON collection with some polygons that crosses the date line. Because of that these polygons, I am not able to create a 2dsphere index on the collection.

Different GIS tools handle this use case differently. Some opts to support longitude that < -180 and > 180 to represent shapes that cross the merdian the short way, instead of the long way (across the other side of the globe).

MongoDB as a database system that stores these data, should be generic enough to handle this use case.



 Comments   
Comment by Kevin Albertson [ 25/Apr/18 ]

Hi Ching,

Coordinates are considered out of bounds if the longitude falls outside of [-180, 180] or the latitude falls outside of [-90, 90].

Converting the out of bounds coordinates to in bounds allows this shape to be indexed:

var data = {geo: { type: "Polygon", coordinates: [ [ [ 179.99572, 68.5097566 ], [ -179.9861529, 68.5125547 ], [ -179.9786755, 68.5057748 ], [ -179.9967985, 68.5029775 ], [ 179.99572, 68.5097566 ] ] ] }};
db.geo.drop();
db.geo.insert(data);
db.geo.createIndex({"geo": "2dsphere"})

If possible, you could preprocess your data to convert any out of bounds points to wrap around.

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