Pergunta

i tried to run this mongodb query

db.building.update( { "_id":ObjectId("53041776a2de55000079b4ba") },
                    { $set :                         
{"geometry":{"type":"Polygon","coordinates":[[[127.357858169667,36.36773567198263],[127.35825816966712,36.36773567198263],[127.35805432178199,36.3675356722397],[127.35825816966712,36.36733567198263],[127.357858169667,36.36733567198263],[127.357858169667,36.36773567198263],[127.357858169667,36.36773567198263]]]}}
                    }
                  )

result is

Exterior shell of polygon is invalid: { type: "Polygon", coordinates: [ [ [ 127.357858169667, 36.36773567198263 ], [ 127.3582581696671, 36.36773567198263 ], [ 127.358054321782, 36.3675356722397 ], [ 127.3582581696671, 36.36733567198263 ], [ 127.357858169667, 36.36733567198263 ], [ 127.357858169667, 36.36773567198263 ], [ 127.357858169667, 36.36773567198263 ] ] ] }

but GeoJSONLint test is a valid.

help me pls. thank you.

Foi útil?

Solução

This error will occur if the polygon is malformed, for example:

  • coordinates are duplicates (the first and last coordinates have to be the same)

1/2 duplicate:

 1/2-----3
  |      |
  |      |
  |      |
  |      |
  |      |
  |      |
  0------4
  • if the lines of the polygon intersect each other (e.g. while trying to draw a pentagram)

intersection:

 1      3
 |\    /|
 | \  / |
 |  \/  |
 |  /\  |
 | /  \ |
 |/    \|
0/4     2

Duplicates are easy to detect, just check whether the first and last coordinate are are equal and remove one of them.

If you have an intersection in your polygon you can try and reorder the points (similar question: MongoDB Error: Exterior shell of polygon is invalid?).

If this dosen't work check if the GeoJSON is valid (from this question: Why is the exterior shell of this GeoJSON invalid?).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top