mongodb和地理空间模式 [英] mongodb and geospatial schema

查看:118
本文介绍了mongodb和地理空间模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用mongo和地理空间打断了我的头, 所以也许有人对如何解决这个问题有一些想法或解决方案: 我的对象架构类似于从 http://geojson.org/geojson-spec.html .

im breaking my head with mongo and geospatial, so maybe someone has some idea or solution how to solve this: my object schema is like this sample for geoJSON taken from 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":{}}
]}}

其他信息:我使用的是spring数据,但这不应影响答案. 主要问题是如何/在此架构中放置索引.如果某些多边形相交,我需要进行查询以查找给定Point的所有文档.

additional info: I'm using spring data but that shouldn't influence the answer. main problem is how/where to put indexes in this schema. I need to make a query to find all documents for given Point if some polygon intersects.

提前谢谢.

推荐答案

通过在geoJSON.features.geometry上创建2d或2dsphere索引,您应该能够创建覆盖所有geoJSON对象的索引.

By creating a 2d or 2dsphere index on geoJSON.features.geometry you should be able to create an index covering all of the geoJSON-objects.

要获取所有features数组中至少一个子对象覆盖某个点的文档,可以使用

To get all documents where at least one of the sub-object in the features array covers a certain point, you can use the $geoIntersects operator with a geoJSON Point:

db.yourcollection.find( 
            { `geoJSON.features.geometry` :
              { $geoIntersects :
                { $geometry :
                  { type : "Point" ,
                    coordinates: [ 100.5 , 0.5 ] 
                  } 
                } 
              } 
            } 
          )

这篇关于mongodb和地理空间模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆