Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when importing geo data to Mongodb : Can't extract geo keys from object, malformed geometry

I am trying to import some geo data (more than 40K) to mongodb(3) but I get sometime an error for some documents:

"code" : 16755,
"errmsg" : "insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry

I have checked the document and it's a valid geojson, respecting mongodb format [long, lat]. And when I insert the document without the polygon, it works...

I cannot figure out what's wrong with those polygons. Here is an example:

Thanks for help.

{
  name: "Alco",
  slug: "alco-montpellier",
  cities: ["MONTPELLIER"],
  polygon: {
    type: "Polygon",
    coordinates: [
        [
            [3.834017, 43.610297],
            [3.833734, 43.610352],
            [3.832791, 43.612713],
            [3.832684, 43.613476],
            [3.832791, 43.614735],
            [3.830752, 43.614796],
            [3.829067, 43.614578],
            [3.831064, 43.617001],
            [3.832523, 43.61924],
            [3.832716, 43.619938],
            [3.833925, 43.620975],
            [3.834285, 43.621277],
            [3.834561, 43.621804],
            [3.834534, 43.621753],
            [3.834561, 43.621803],
            [3.835378, 43.622456],
            [3.835416, 43.622468],
            [3.835417, 43.622473],
            [3.836562, 43.622849],
            [3.835891, 43.624896],
            [3.838081, 43.626389],
            [3.839628, 43.627281],
            [3.840811, 43.628289],
            [3.841549, 43.629196],
            [3.842159, 43.631116],
            [3.84352, 43.629856],
            [3.845636, 43.628679],
            [3.846009, 43.628236],
            [3.846367, 43.62771],
            [3.847108, 43.627283],
            [3.848243, 43.62677],
            [3.850334, 43.625332],
            [3.852267, 43.624563],
            [3.853425, 43.623907],
            [3.854275, 43.623266],
            [3.854834, 43.622371],
            [3.85659, 43.621271],
            [3.857811, 43.62069],
            [3.855053, 43.620195],
            [3.852897, 43.620075],
            [3.852789, 43.620075],
            [3.850239, 43.620028],
            [3.847899, 43.619022],
            [3.844711, 43.618395],
            [3.843713, 43.617984],
            [3.842315, 43.617007],
            [3.840065, 43.615578],
            [3.839092, 43.613684],
            [3.838844, 43.612444],
            [3.838938, 43.610591],
            [3.838526, 43.609439],
            [3.834017, 43.610297]
        ]
    ]
  },
  centroid: {
    type: "Point",
    coordinates: [3.84344, 43.6203]
  }
}
like image 652
Amine Sadry Avatar asked Feb 09 '23 08:02

Amine Sadry


1 Answers

If you insert the document via Mongo Shell in MongoDB v3.0, you should see an error message:

  "writeError": {
    "code": 16755,
    "errmsg": "Can't extract geo keys: ... 
    Loop is not valid: ...
    ...
    Edges 11 and 13 cross. Edge locations in degrees: [3.8342850, 43.6212770]-[3.8345610, 43.6218040] and [3.8345340, 43.6217530]-[3.8345610, 43.6218030]

Checking those coordinates, they are too close together (almost identical) that creates an anomaly in the polygon shape: [3.834561, 43.621804] and [3.834561, 43.621803].

If we visualise it in geodndmap.mongodb.com, you can see that there is a tiny edge causing an invalid loop. This edge crossing is caused by the coordinates above.

invalid polygon loop

like image 162
Wan Bachtiar Avatar answered Feb 11 '23 03:02

Wan Bachtiar