[SERVER-56001] Can't extract geo keys error Created: 09/Apr/21  Updated: 27/Oct/23  Resolved: 19/Apr/21

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

Type: Bug Priority: Major - P3
Reporter: Pedro Ribeiro Assignee: Edwin Zhou
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2021-04-19 at 1.02.52 PM.png    
Operating System: ALL
Steps To Reproduce:

Mongo version 4.4.1

try to insert this document in a collection with a index 2dsphere in the field coordinates.bounding_polygon

Participants:

 Description   

I'm trying to add this record to a collection with a index 2dsphere in the field coordinates.bounding_polygon:

{ _id: "553248635975750802", ancestors: [ \{ type: "province_state" }

, { type: "province_state" }, { type: "country" }, { type: "continent" } ], associations: { point_of_interest: [ "6089485" ] }, coordinates: { center_point:

{ type: "Point", coordinates: [ -113.17927, 67.14037 ] }

, bounding_polygon: { type: "Polygon", coordinates: [ [ [ 127.192506, 66.047911 ], [ -126.841607, 65.925156 ], [ -124.9152374267578, 65.91987032044477 ], [ -123.853326, 65.55643600000001 ], [ -102.139892578125, 65.55845978217837 ], [ -101.953125, 65.67638148211446 ], [ -101.881272, 65.80209499999999 ], [ -101.881272, 67.66619900000001 ], [ -102.232233, 67.747986 ], [ -104.956842, 67.891375 ], [ -108.82403, 68.01429899999999 ], [ -110.845514, 68.383011 ], [ -112.691217, 68.362539 ], [ -117.173639, 69.284336 ], [ -118.491998, 69.42772100000001 ], [ -121.831841, 69.407248 ], [ -122.182832, 69.325457 ], [ -122.007022, 68.362678 ], [ -122.270605, 68.07589299999999 ], [ -122.270643, 67.645715 ], [ -122.710748, 67.58411 ], [ -124.908013, 67.604585 ], [ -125.083105, 67.563776 ], [ -123.676893, 67.481837 ], [ -123.325678, 67.113114 ], [ -123.85302, 66.990206 ], [ -123.325982, 66.826398 ], [ -122.974419, 66.94930600000001 ], [ -122.271294, 66.94930600000001 ], [ -121.919732, 66.621551 ], [ -121.040826, 66.642036 ], [ -120.337701, 66.498645 ], [ -119.195123, 66.51912900000001 ], [ -118.316217, 66.68300600000001 ], [ -117.085748, 66.642036 ], [ -116.470514, 66.68300600000001 ], [ -116.118951, 66.62155300000001 ], [ -115.503717, 66.62155300000001 ], [ -115.41552, 66.560028 ], [ -115.591607, 66.518987 ], [ -116.118951, 66.559957 ], [ -116.734185, 66.478019 ], [ -116.909665, 66.43711999999999 ], [ -116.558098, 66.293727 ], [ -116.997857, 66.19123999999999 ], [ -117.700982, 66.232202 ], [ -118.228326, 66.35511 ], [ -118.75567, 66.25268699999999 ], [ -119.107232, 66.273172 ], [ -119.458795, 66.375596 ], [ -120.337701, 66.31414100000001 ], [ -120.513178, 66.273242 ], [ -119.810053, 66.150335 ], [ -119.897949, 65.945488 ], [ -120.337701, 65.88396400000001 ], [ -121.304498, 65.965903 ], [ -121.479981, 65.80209499999999 ], [ -121.12814, 65.679187 ], [ -121.304498, 65.63808299999999 ], [ -122.271294, 65.63808400000001 ], [ -122.710748, 65.74050699999999 ], [ -123.238091, 65.63808299999999 ], [ -123.853326, 65.658558 ], [ -124.293385, 65.86354900000001 ], [ -124.293084, 66.088881 ], [ -124.46856, 66.129779 ], [ -125.259576, 66.006801 ], [ -126.490044, 66.00679599999999 ], [ -127.017388, 66.17067299999999 ], [ -127.192506, 66.047911 ] ] ] } }, country_code: "CA", createdDate: new Date(1617983854867), descendants: { city: [ "3914", "181833", "3000470090" ] }, description: { en-US: "region" }, lastModifiedDate: new Date(1617983854867), name: { en-US: "Fort Smith Region" }, name_full: { en-US: "Fort Smith Region, Canada" }, type: "province_state" } Loop is not valid: [ [ -127.192506, 66.047911 ], [ -126.841607, 65.925156 ], [ -124.9152374267578, 65.91987032044477 ], [ -123.853326, 65.55643600000001 ], [ -102.139892578125, 65.55845978217837 ], [ -101.953125, 65.67638148211446 ], [ -101.881272, 65.80209499999999 ], [ -101.881272, 67.66619900000001 ], [ -102.232233, 67.747986 ], [ -104.956842, 67.891375 ], [ -108.82403, 68.01429899999999 ], [ -110.845514, 68.383011 ], [ -112.691217, 68.362539 ], [ -117.173639, 69.284336 ], [ -118.491998, 69.42772100000001 ], [ -121.831841, 69.407248 ], [ -122.182832, 69.325457 ], [ -122.007022, 68.362678 ], [ -122.270605, 68.07589299999999 ], [ -122.270643, 67.645715 ], [ -122.710748, 67.58411 ], [ -124.908013, 67.604585 ], [ -125.083105, 67.563776 ], [ -123.676893, 67.481837 ], [ -123.325678, 67.113114 ], [ -123.85302, 66.990206 ], [ -123.325982, 66.826398 ], [ -122.974419, 66.94930600000001 ], [ -122.271294, 66.94930600000001 ], [ -121.919732, 66.621551 ], [ -121.040826, 66.642036 ], [ -120.337701, 66.498645 ], [ -119.195123, 66.51912900000001 ], [ -118.316217, 66.68300600000001 ], [ -117.085748, 66.642036 ], [ -116.470514, 66.68300600000001 ], [ -116.118951, 66.62155300000001 ], [ -115.503717, 66.62155300000001 ], [ -115.41552, 66.560028 ], [ -115.591607, 66.518987 ], [ -116.118951, 66.559957 ], [ -116.734185, 66.478019 ], [ -116.909665, 66.43711999999999 ], [ -116.558098, 66.293727 ], [ -116.997857, 66.19123999999999 ], [ -117.700982, 66.232202 ], [ -118.228326, 66.35511 ], [ -118.75567, 66.25268699999999 ], [ -119.107232, 66.273172 ], [ -119.458795, 66.375596 ], [ -120.337701, 66.31414100000001 ], [ -120.513178, 66.273242 ], [ -119.810053, 66.150335 ], [ -119.897949, 65.945488 ], [ -120.337701, 65.88396400000001 ], [ -121.304498, 65.965903 ], [ -121.479981, 65.80209499999999 ], [ -121.12814, 65.679187 ], [ -121.304498, 65.63808299999999 ], [ -122.271294, 65.63808400000001 ], [ -122.710748, 65.74050699999999 ], [ -123.238091, 65.63808299999999 ], [ -123.853326, 65.658558 ], [ -124.293385, 65.86354900000001 ], [ -124.293084, 66.088881 ], [ -124.46856, 66.129779 ], [ -125.259576, 66.006801 ], [ -126.490044, 66.00679599999999 ], [ -127.017388, 66.17067299999999 ], [ -127.192506, 66.047911 ] ] Edges 3 and 56 cross. Edge locations in degrees: [-123.8533260, 65.5564360][-102.1398926, 65.5584598] and [-121.4799810, 65.8020950]-[-121.1281400, 65.6791870]; nested exception is com.mongodb.MongoWriteException: Can't extract geo keys: { _id: "553248635975750802", ancestors: [

{ type: "province_state" }

, { type: "province_state" }, { type: "country" }, { type: "continent" } ], associations: { point_of_interest: [ "6089485" ] }, coordinates: { center_point:

{ type: "Point", coordinates: [ -113.17927, 67.14037 ] }

, bounding_polygon: { type: "Polygon", coordinates: [ [ [ -127.192506, 66.047911 ], [ -126.841607, 65.925156 ], [ -124.9152374267578, 65.91987032044477 ], [ -123.853326, 65.55643600000001 ], [ -102.139892578125, 65.55845978217837 ], [ -101.953125, 65.67638148211446 ], [ -101.881272, 65.80209499999999 ], [ -101.881272, 67.66619900000001 ], [ -102.232233, 67.747986 ], [ -104.956842, 67.891375 ], [ -108.82403, 68.01429899999999 ], [ -110.845514, 68.383011 ], [ -112.691217, 68.362539 ], [ -117.173639, 69.284336 ], [ -118.491998, 69.42772100000001 ], [ -121.831841, 69.407248 ], [ -122.182832, 69.325457 ], [ -122.007022, 68.362678 ], [ -122.270605, 68.07589299999999 ], [ -122.270643, 67.645715 ], [ -122.710748, 67.58411 ], [ -124.908013, 67.604585 ], [ -125.083105, 67.563776 ], [ -123.676893, 67.481837 ], [ -123.325678, 67.113114 ], [ -123.85302, 66.990206 ], [ -123.325982, 66.826398 ], [ -122.974419, 66.94930600000001 ], [ -122.271294, 66.94930600000001 ], [ -121.919732, 66.621551 ], [ -121.040826, 66.642036 ], [ -120.337701, 66.498645 ], [ -119.195123, 66.51912900000001 ], [ -118.316217, 66.68300600000001 ], [ -117.085748, 66.642036 ], [ -116.470514, 66.68300600000001 ], [ -116.118951, 66.62155300000001 ], [ -115.503717, 66.62155300000001 ], [ -115.41552, 66.560028 ], [ -115.591607, 66.518987 ], [ -116.118951, 66.559957 ], [ -116.734185, 66.478019 ], [ -116.909665, 66.43711999999999 ], [ -116.558098, 66.293727 ], [ -116.997857, 66.19123999999999 ], [ -117.700982, 66.232202 ], [ -118.228326, 66.35511 ], [ -118.75567, 66.25268699999999 ], [ -119.107232, 66.273172 ], [ -119.458795, 66.375596 ], [ -120.337701, 66.31414100000001 ], [ -120.513178, 66.273242 ], [ -119.810053, 66.150335 ], [ -119.897949, 65.945488 ], [ -120.337701, 65.88396400000001 ], [ -121.304498, 65.965903 ], [ -121.479981, 65.80209499999999 ], [ -121.12814, 65.679187 ], [ -121.304498, 65.63808299999999 ], [ -122.271294, 65.63808400000001 ], [ -122.710748, 65.74050699999999 ], [ -123.238091, 65.63808299999999 ], [ -123.853326, 65.658558 ], [ -124.293385, 65.86354900000001 ], [ -124.293084, 66.088881 ], [ -124.46856, 66.129779 ], [ -125.259576, 66.006801 ], [ -126.490044, 66.00679599999999 ], [ -127.017388, 66.17067299999999 ], [ -127.192506, 66.047911 ] ] ] } }, country_code: "CA", createdDate: new Date(1617983854867), descendants: { city: [ "3914", "181833", "3000470090" ] }, description: { en-US: "region" }, lastModifiedDate: new Date(1617983854867), name: { en-US: "Fort Smith Region" }, name_full: { en-US: "Fort Smith Region, Canada" }, type: "province_state" }

The message error displayed is:

Can't extract geo keys error: .... Loop is not valid: [ [ -127.192506, 66.047911 ], [ -126.841607, 65.925156 ], [ -124.9152374267578, 65.91987032044477 ], [ -123.853326, 65.55643600000001 ], [ -102.139892578125, 65.55845978217837 ], [ -101.953125, 65.67638148211446 ], [ -101.881272, 65.80209499999999 ], [ -101.881272, 67.66619900000001 ], [ -102.232233, 67.747986 ], [ -104.956842, 67.891375 ], [ -108.82403, 68.01429899999999 ], [ -110.845514, 68.383011 ], [ -112.691217, 68.362539 ], [ -117.173639, 69.284336 ], [ -118.491998, 69.42772100000001 ], [ -121.831841, 69.407248 ], [ -122.182832, 69.325457 ], [ -122.007022, 68.362678 ], [ -122.270605, 68.07589299999999 ], [ -122.270643, 67.645715 ], [ -122.710748, 67.58411 ], [ -124.908013, 67.604585 ], [ -125.083105, 67.563776 ], [ -123.676893, 67.481837 ], [ -123.325678, 67.113114 ], [ -123.85302, 66.990206 ], [ -123.325982, 66.826398 ], [ -122.974419, 66.94930600000001 ], [ -122.271294, 66.94930600000001 ], [ -121.919732, 66.621551 ], [ -121.040826, 66.642036 ], [ -120.337701, 66.498645 ], [ -119.195123, 66.51912900000001 ], [ -118.316217, 66.68300600000001 ], [ -117.085748, 66.642036 ], [ -116.470514, 66.68300600000001 ], [ -116.118951, 66.62155300000001 ], [ -115.503717, 66.62155300000001 ], [ -115.41552, 66.560028 ], [ -115.591607, 66.518987 ], [ -116.118951, 66.559957 ], [ -116.734185, 66.478019 ], [ -116.909665, 66.43711999999999 ], [ -116.558098, 66.293727 ], [ -116.997857, 66.19123999999999 ], [ -117.700982, 66.232202 ], [ -118.228326, 66.35511 ], [ -118.75567, 66.25268699999999 ], [ -119.107232, 66.273172 ], [ -119.458795, 66.375596 ], [ -120.337701, 66.31414100000001 ], [ -120.513178, 66.273242 ], [ -119.810053, 66.150335 ], [ -119.897949, 65.945488 ], [ -120.337701, 65.88396400000001 ], [ -121.304498, 65.965903 ], [ -121.479981, 65.80209499999999 ], [ -121.12814, 65.679187 ], [ -121.304498, 65.63808299999999 ], [ -122.271294, 65.63808400000001 ], [ -122.710748, 65.74050699999999 ], [ -123.238091, 65.63808299999999 ], [ -123.853326, 65.658558 ], [ -124.293385, 65.86354900000001 ], [ -124.293084, 66.088881 ], [ -124.46856, 66.129779 ], [ -125.259576, 66.006801 ], [ -126.490044, 66.00679599999999 ], [ -127.017388, 66.17067299999999 ], [ -127.192506, 66.047911 ] ]

I don't see any issue with this polygon:
https://gist.github.com/pmribeiro/f714807f361a68f3609e24aa6c450d7b



 Comments   
Comment by Edwin Zhou [ 19/Apr/21 ]

Hi ribeirinho77@gmail.com,

I've attempted to insert the same polygon and run into the same issue. On further investigation, there is actually a conflict between two coordinates as visualized below. As we see in the gist you linked, many GeoJSON visualizers attempt to project orthogonal cartesian coordinates on a spherical shape, which can mislead how MongoDB queries GeoJSON.

To view an accurate representation of how MongoDB plots and queries GeoJSON, I recommend using https://geodndmap.mongodb.com/. You can plot polygons by opening up your browser's developer tools, and running the following command in the console:

loadGeoJson({"type":"Polygon","coordinates":[[[-127.192506,66.047911],[-126.841607,65.925156],[-124.908013,65.925147],[-123.853326,65.556436],[-102.139892578125,65.55845978217837],[-101.953125,65.67638148211446],[-101.881272,65.802095],[-101.881272,67.666199],[-102.232233,67.747986],[-104.956842,67.891375],[-108.82403,68.014299],[-110.845514,68.383011],[-112.691217,68.362539],[-117.173639,69.284336],[-118.491998,69.427721],[-121.831841,69.407248],[-122.182832,69.325457],[-122.007022,68.362678],[-122.270605,68.075893],[-122.270643,67.645715],[-122.710748,67.58411],[-124.908013,67.604585],[-125.083105,67.563776],[-123.676893,67.481837],[-123.325678,67.113114],[-123.85302,66.990206],[-123.325982,66.826398],[-122.974419,66.949306],[-122.271294,66.949306],[-121.919732,66.621551],[-121.040826,66.642036],[-120.337701,66.498645],[-119.195123,66.519129],[-118.316217,66.683006],[-117.085748,66.642036],[-116.470514,66.683006],[-116.118951,66.621553],[-115.503717,66.621553],[-115.41552,66.560028],[-115.591607,66.518987],[-116.118951,66.559957],[-116.734185,66.478019],[-116.909665,66.43712],[-116.558098,66.293727],[-116.997857,66.19124],[-117.700982,66.232202],[-118.228326,66.35511],[-118.75567,66.252687],[-119.107232,66.273172],[-119.458795,66.375596],[-120.337701,66.314141],[-120.513178,66.273242],[-119.810053,66.150335],[-119.897949,65.945488],[-120.337701,65.883964],[-121.304498,65.965903],[-121.479981,65.802095],[-121.12814,65.679187],[-121.304498,65.638083],[-122.271294,65.638084],[-122.710748,65.740507],[-123.238091,65.638083],[-123.853326,65.658558],[-124.293385,65.863549],[-124.293084,66.088881],[-124.46856,66.129779],[-125.259576,66.006801],[-126.490044,66.006796],[-127.017388,66.170673],[-127.192506,66.047911]]]})

Here is an accurate representation of how these coordinates are mapped on a spherical basis:

Note the two points are the coordinates that cause the overlap and are responsible for this conflict.

As a reminder, the SERVER project is for bugs and feature suggestions for the MongoDB server. As this ticket does not appear to be a bug, I will now close it. If you need further assistance with these coordinates, I encourage you to ask our community by posting on the MongoDB Developer Community Forums.

Best,
Edwin

Comment by Pedro Ribeiro [ 09/Apr/21 ]

{"id":"553248635975750802","type":"province_state","name":"Fort Smith Region","name_full":"Fort Smith Region, Canada","descriptor":"region","country_code":"CA","coordinates":{"center_longitude":-113.17927,"center_latitude":67.14037,"bounding_polygon":{"type":"Polygon","coordinates":[[[-127.192506,66.047911],[-126.841607,65.925156],[-124.908013,65.925147],[-123.853326,65.556436],[-102.139892578125,65.55845978217837],[-101.953125,65.67638148211446],[-101.881272,65.802095],[-101.881272,67.666199],[-102.232233,67.747986],[-104.956842,67.891375],[-108.82403,68.014299],[-110.845514,68.383011],[-112.691217,68.362539],[-117.173639,69.284336],[-118.491998,69.427721],[-121.831841,69.407248],[-122.182832,69.325457],[-122.007022,68.362678],[-122.270605,68.075893],[-122.270643,67.645715],[-122.710748,67.58411],[-124.908013,67.604585],[-125.083105,67.563776],[-123.676893,67.481837],[-123.325678,67.113114],[-123.85302,66.990206],[-123.325982,66.826398],[-122.974419,66.949306],[-122.271294,66.949306],[-121.919732,66.621551],[-121.040826,66.642036],[-120.337701,66.498645],[-119.195123,66.519129],[-118.316217,66.683006],[-117.085748,66.642036],[-116.470514,66.683006],[-116.118951,66.621553],[-115.503717,66.621553],[-115.41552,66.560028],[-115.591607,66.518987],[-116.118951,66.559957],[-116.734185,66.478019],[-116.909665,66.43712],[-116.558098,66.293727],[-116.997857,66.19124],[-117.700982,66.232202],[-118.228326,66.35511],[-118.75567,66.252687],[-119.107232,66.273172],[-119.458795,66.375596],[-120.337701,66.314141],[-120.513178,66.273242],[-119.810053,66.150335],[-119.897949,65.945488],[-120.337701,65.883964],[-121.304498,65.965903],[-121.479981,65.802095],[-121.12814,65.679187],[-121.304498,65.638083],[-122.271294,65.638084],[-122.710748,65.740507],[-123.238091,65.638083],[-123.853326,65.658558],[-124.293385,65.863549],[-124.293084,66.088881],[-124.46856,66.129779],[-125.259576,66.006801],[-126.490044,66.006796],[-127.017388,66.170673],[-127.192506,66.047911]]]}},"associations":

{"point_of_interest":["6089485"]}

,"ancestors":[

{"id":"6025605","type":"province_state"}

,

{"id":"11172","type":"province_state"}

,

{"id":"31","type":"country"}

,

{"id":"500001","type":"continent"}

],"descendants":

{"city":["3914","181833","3000470090"]}

}

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