MongoDB GeoJSON“无法从对象,格式错误的几何图形中提取地理关键字吗?"插入多边形时 [英] MongoDB GeoJSON "Can't extract geo keys from object, malformed geometry?" when inserting type Polygon
问题描述
我收到错误消息无法从对象,格式错误的几何图形中提取地理关键字吗?".多边形已关闭,格式看起来不错,因为它已正确插入到Mongo中.我正在使用在Centos 6.5 x64上运行的Mongo 2.6.3版.
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.
下面的多边形有什么问题?我非常仔细地遵循了Mongo示例.
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
]
]
}
}
推荐答案
您在坐标中缺少数组级别:
You are missing an array level in the coordinates:
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
这篇关于MongoDB GeoJSON“无法从对象,格式错误的几何图形中提取地理关键字吗?"插入多边形时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!