MongoDB 2dsphere 索引失败(几何形状错误?)

标签 mongodb geojson mongodb-indexes 2dsphere

我目前正在尝试构建 2dsphere 索引,但创建似乎失败了。

索引创建失败的文档是有效的geojson(根据geojsonlint)。

据我所知,它遵守 MongoDB“多边形”规则。

我将不胜感激,因为我无法弄清楚索引创建似乎失败的原因。

提前致谢!

db.poly.ensureIndex( { loc: "2dsphere" } )
{
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 1,
        "ok" : 0,
        "errmsg" : "Can't extract geo keys from object, malformed geometry?: { _
id: 353, loc: { type: \"Polygon\", coordinates: [ [ [ 8.090732000000001, 53.6379
766 ], [ 8.050639500000001, 53.6250853 ], [ 8.036974600000001, 53.6286108 ], [ 7
.994035500000001, 53.6016978 ], [ 8.0120927, 53.59855020000001 ], [ 8.0102720000
00001, 53.5883803 ], [ 8.023379, 53.5867745 ], [ 8.0148004, 53.5832729 ], [ 8.02
6839500000001, 53.57895840000001 ], [ 8.0271685, 53.5727671 ], [ 8.0432450000000
01, 53.57190120000001 ], [ 8.0386477, 53.565241 ], [ 8.0192488, 53.5609644 ], [
8.030192100000001, 53.5508096 ], [ 8.037298, 53.5565769 ], [ 8.041402400000001,
53.55249540000001 ], [ 8.030647100000001, 53.53854200000001 ], [ 8.0381080000000
01, 53.5275022 ], [ 8.048501400000001, 53.5243656 ], [ 8.051459700000001, 53.509
912 ], [ 8.091510100000001, 53.50258460000001 ], [ 8.153839000000001, 53.5148059
0000001 ], [ 8.1708242, 53.53993010000001 ], [ 8.164240300000001, 53.5287913 ],
[ 8.1562255, 53.531339 ], [ 8.1700993, 53.54524050000001 ], [ 8.150740200000001,
 53.5596328 ], [ 8.1539377, 53.56452330000001 ], [ 8.1408203, 53.58015880000001
], [ 8.155694800000001, 53.5858101 ], [ 8.1496093, 53.60191990000001 ], [ 8.1234
503, 53.5984032 ], [ 8.090732000000001, 53.6379766 ] ] ] } }",
        "code" : 16755
}

最佳答案

按照您的做法将索引应用于“loc”(GeoJSON 字段)。但是,请确保您的坐标按经度、纬度(不是纬度、经度)的顺序指定。

根据 http://docs.mongodb.org/manual/applications/geospatial-indexes/#spherical 上的文档:

Store your location data as GeoJSON objects with this coordinate-axis order: longitude, latitude. The coordinate reference system for GeoJSON uses the WGS84 datum.

另外,根据 http://geojson.org/geojson-spec.html#positions 的 GeoJSON 规范:

A position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.

关于MongoDB 2dsphere 索引失败(几何形状错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23923909/

相关文章:

mongodb - 如何在 Rockmongo 或 mongovue 中执行 shell 一些查询?

javascript - 预加载(预过滤)点到 Polymaps API

javascript - Leaflet 和 geojson AJAX 调用

MongoDB 拒绝使用索引交集

MongoDB 在多个字段上建立索引

java - Morphia 在保存到 DataStore 时给出 NoSuchMethodError

java - 使用 spring 和 mongodb 根据我的查询获取文档列表

javascript - D3 map 未显示在本地服务器上的浏览器中

mongodb - 当你 'index' 一个 MongoDB 数据库时到底发生了什么?

c# - MongoDB C# 2.x 驱动程序 ElemMatch 与字典