我对mongo和geographic感到头疼,所以也许有人有一些想法或解决方案来解决这个问题:我的对象模式与以下geoJSON示例类似http://geojson.org/geojson-spec.html.
{
"name":"name",
"geoJSON":{
"type":"FeatureCollection",
"features":[
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]},"properties":{}},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]},"properties":{}},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]},"properties":{}}
]}}
附加信息:我正在使用春季数据,但这不应该影响答案。主要问题是如何/在哪里将索引放在这个模式中。如果某个多边形相交,我需要进行查询以查找给定点的所有文档。
提前谢谢。
通过在geoJSON.features.geometry
上创建2d或2dsphere索引,您应该能够创建覆盖所有geoJSON对象的索引。
要获取features
数组中至少有一个子对象覆盖某一点的所有文档,可以将$geoIntersects
运算符与geoJSON point一起使用:
db.yourcollection.find(
{ `geoJSON.features.geometry` :
{ $geoIntersects :
{ $geometry :
{ type : "Point" ,
coordinates: [ 100.5 , 0.5 ]
}
}
}
}
)