6

mongodb 2.4.3 出现以下错误

Can't extract geo keys from object, malformed geometry?

{type: "Polygon",
coordinates: [
    [
        [
            103.8324334524412,
            1.284232321447769
        ],
        [
            103.8342325475588,
            1.284232321447769
        ],
        [
            103.8342325469261,
            1.282433678236006
        ],
        [
            103.8324334530738,
            1.282433678236006
        ]
    ]
]}

有人可以帮我理解这个问题吗?它看起来像一个有效的 geoJSON 对象。我的索引是类型2dsphere

我正在运行的两个步骤是:

collection.ensureIndex {'geometry' : "2dsphere"}, (error) =>
  # some error checking
  # and then
  collection.insert features, (error) =>
    # features is an array of geoJSON feature objects
    # {"type" : "Feature"
    #  "geometry" : <the Polygon object above>
      }

插入查询给出了这个错误。我要插入的完整文档是:

{
    "type":"Feature",
    "geometry": {
        "type":"Polygon",
        "coordinates":[
           [
             [103.83243345244122,1.2842323214477689],
             [103.83423254755876,1.2842323214477689],
             [103.83423254692615,1.2824336782360055],
             [103.83243345307383,1.2824336782360055]
           ]
        ]
      },
    "properties":{"name" : "My location"}
  }
4

3 回答 3

10

geoJSON 中的多边形对象要求第一个点 ([lon, lat]) 与最后一个点相同。通过进行此更改:

{type: "Polygon",
coordinates: [
    [
        [
            103.8324334524412,
            1.284232321447769
        ],
        [
            103.8342325475588,
            1.284232321447769
        ],
        [
            103.8342325469261,
            1.282433678236006
        ],
        [
            103.8324334530738,
            1.282433678236006
        ],
        [
            103.8324334524412,
            1.284232321447769
        ]
    ]
]}

插入查询工作正常。

于 2013-06-22T02:50:58.540 回答
3

就我而言,问题与上述相同,但对我有用的解决方案是

point ([longitude, latitude]) 

我刚刚做了相反的事情

point ([latitude, longitude])

这对我来说非常愚蠢,但很难通过错误无法从对象中提取地理键,格式错误的几何?

但是,如果像我这样的人发现这个,请也检查一下。

于 2014-11-20T20:18:59.613 回答
0

我有同样的问题,我的经度,纬度顺序是正确的。我的错误是我写coordiantes的而不是coordinates mongo 给了我这个:

pymongo.errors.WriteError: Can't extract geo keys: {data}  Point must be an array or object

所以也许你有正确的顺序,但你的键名有问题,确保你遵守 mongo 规则!

于 2017-09-30T22:23:02.610 回答