MongoDB GeoJSON"无法从对象,格式错误的几何体中提取地理键?"插入多边形时

时间:2014-08-29 14:01:13

标签: mongodb geojson

我收到错误"无法从对象,格式错误的几何图形中提取地理位置键?"。多边形是关闭的,格式看起来很好,因为它正确插入Mongo。我使用的是Mongo 2.6.3版,在Centos 6.5 x64上运行。

下面的多边形有什么问题?我非常密切地关注了Mongo的例子。

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 个答案:

答案 0 :(得分:7)

您在坐标中缺少数组级别:

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

应该是:

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

请参阅http://geojson.org/geojson-spec.html#id4