问题
Hi i have an COllection with an 2d sphere index
wayCollection.createIndex(new BasicDBObject("poly", "2dsphere"));
i when i try to insert a certain object i get an error:
Exception in thread "main" com.mongodb.WriteConcernException: { "serverUsed" : "localhost:27017" , "ok" : 1 , "n" : 0 , "err" : "insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('53a89dc6a0042baf54050037'), id: 24837452, version: \"64\", changeset: \"13731788\", uid: \"362915\", user: \"micha555\", timestamp: \"2012-11-03T09:11:23Z\", poly: { type: \"Polygon\", coordinates: [ [ [ 9.1244131, 50.0109503 ], [ 9.120464800000001, 50.0099731 ], [ 9.116641, 50.0077
although the multipolygon ring is closed (first and last coordinate is the same)
any ideas?
Here is another polygon which is rejected:
{
"type":"Polygon",
"coordinates":[
[
[
9.0496053,
51.3255584
],
[
9.0492235,
51.32532
],
[
9.0495831,
51.3251321
],
[
9.049917199999999,
51.3253429
],
[
9.0496053,
51.3255584
],
[
9.049984500000001,
51.3258463
],
[
9.0505795,
51.3262127
],
[
9.050045600000001,
51.326574
],
[
9.0496432,
51.3263928
],
[
9.049625300000001,
51.3262806
],
[
9.0495628,
51.3261244
],
[
9.0495316,
51.3259341
],
[
9.0495471,
51.3257127
],
[
9.0496053,
51.3255584
]
]
]
}
when i paste it here it seems to be ok: http://geojsonlint.com/
maybe mongo db does not like when a point is used twice
回答1:
First thing I would do is check your polygon at http://geojsonlint.com/ . If it does not pass then you know you have an issue with your data points (which has caused this error for many people previously).
If it does pass then I would check this bug that was recently reported and submitted to MongoDB: https://jira.mongodb.org/browse/SERVER-13735 . Basically a valid MultiPolygon is causing an error with the 2dsphere index on MongoDB 2.6.X. Others have reported similar issues so my bet is that it's a bug, or some undocumented limitation.
I'd vote up the issue on JIRA and add your voice to the comments - the more people let MongoDB know that this bug exists and is impacting them the faster it will get fixed.
回答2:
The polygon is self-intersecting:
MongoDB prohibits such polygons.
来源:https://stackoverflow.com/questions/24375649/mongodb-sphere-index-rejects-my-object