2014-08-29 67 views
2

我收到错误“无法从对象,格式错误的几何?”提取地理密钥。多边形是封闭的,格式看起来不错,因为它正确地插入到Mongo中。我正在使用Mongo版本2.6.3,在Centos 6.5 x64上运行。MongoDB GeoJSON“无法从对象中提取地理密钥,格式错误?”当插入类型多边形

下面的Polygon有什么问题?我非常仔细地跟踪了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 
      ] 
     ] 
    } 
} 

回答

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

+0

啊。感谢那。在我看到的Mongo文档中,我没有看到有关内部孔的一点。 – thaspius 2014-08-29 14:48:20

+0

你救了我的星期六下午@Slippery皮特 – AndreaM16 2016-06-04 15:32:03

相关问题