在MongoDB中存储GeoJSON多边形

Dom*_*ger 9 indexing geo mongodb geojson

我有MongoDB的以下问题.我从我的祖国获得了一些地理数据,我必须将它们存储到mongodb中以建立一个简单的Web要素服务.此服务主要使用$within运算符进行边界框查询.数据采用GeoJSON格式.因此我首先导入了[1,2]以这种格式表示为points()的村庄和城市.没问题.下一步是LineStrings的河流和街道,根据GeoJSON代表这种方式[[1,2],[3,4]].但是当导入区域(实际上是多边形并且根据GeoJSON规范3 dim arrrays)时,我geo values have to be numbers在创建索引时遇到了错误 .

db.collection.ensureIndex({"geometry.coordinates" : "2d"});
Run Code Online (Sandbox Code Playgroud)

所有数据都是有效的GeoJSON,并且在EPSG中的普通2d坐标:4326投影.

有人有想法吗?

小智 13

使用MongoDB 2.4,使用GeoJSON Points,LineStrings和Polygons的"2dsphere"索引.

例如,您可以创建此索引:

db.mycoll.ensureIndex( { loc : "2dsphere" } )
Run Code Online (Sandbox Code Playgroud)

并存储此LineString:

{ loc : { type : "LineString" , coordinates : [ [ 1 , 2 ] , [ 3 , 4 ] ] } }
Run Code Online (Sandbox Code Playgroud)

http://docs.mongodb.org/manual/applications/2dsphere/.


Víc*_*ela 3

看来 mongo 2.3.2 开发版本现在具有 GeoJSON 支持: Release Notes for MongoDB 2.4