MongoDB GeoJSON “Can't extract geo keys from object, malformed geometry?” when inserting type Polygon

妖精的绣舞 提交于 2020-01-04 16:41:09

问题


I'm getting the error "Can't extract geo keys from object, malformed geometry?". The polygon is closed and the format looks good, as it is inserting correctly into Mongo. I'm using Mongo version 2.6.3, running on Centos 6.5 x64.

What is wrong with the Polygon below? I followed the Mongo examples quite closely.

db.test.remove({});
db.test.insert({testPoly: {type: "Polygon", coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]}});
db.test.ensureIndex({testPoly: "2dsphere" });
db.test.find();

/* 0 */
{
    "connectionId" : 2385,
    "err" : "Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('54008301eb55d4628c080370'), testPoly: { type: \"Polygon\", coordinates: [ [ 0.0, 0.0 ], [ 0.0, 20.0 ], [ 10.0, 30.0 ], [ 20.0, 20.0 ], [ 20.0, 0.0 ], [ 0.0, 0.0 ] ] } }",
    "code" : 16755,
    "n" : 0,
    "ok" : 1
}

/* 0 */
{
    "_id" : ObjectId("54008301eb55d4628c080370"),
    "testPoly" : {
        "type" : "Polygon",
        "coordinates" : [ 
            [ 
                0, 
                0
            ], 
            [ 
                0, 
                20
            ], 
            [ 
                10, 
                30
            ], 
            [ 
                20, 
                20
            ], 
            [ 
                20, 
                0
            ], 
            [ 
                0, 
                0
            ]
        ]
    }
}

回答1:


You are missing an array level in the coordinates:

coordinates: [[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]

Should be:

coordinates: [[[0,0],[0,20],[10,30],[20,20],[20,0],[0,0]]]

See http://geojson.org/geojson-spec.html#id4



来源:https://stackoverflow.com/questions/25569901/mongodb-geojson-cant-extract-geo-keys-from-object-malformed-geometry-when-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!