Mongodb错误:无法从对象,格式错误的几何体中提取地理位置键?

时间:2013-06-21 06:52:56

标签: mongodb

我在使用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"}
  }

3 个答案:

答案 0 :(得分:9)

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
        ]
    ]
]}

插入查询工作正常。

答案 1 :(得分:3)

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

point ([longitude, latitude]) 

我刚刚做了相反的事情

point ([latitude, longitude])

这对我来说非常愚蠢,但很难弄清楚错误 无法从对象,格式错误的几何图形中提取地理位置键吗?

但是,只要像我这样的人找到这个,请检查一下。

答案 2 :(得分:0)

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

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

所以也许你有正确的订购,但你的密钥名称有问题,请确保你遵守mongo规则!