mongoDB提供了两种空间索引用来存储poi信息:
2d: 索引支持平台普通坐标的索引.
2dsphere: 可以对多种几何类型进行计算,包括点,线,面,多点,多面等。
使用示例:
- 创建空间索引:
db.collection.createIndex({"filed_name":"2dsphere"});
可以指定特定集合名称
- 插入GeoJson数据,mongoDB利用GeoJson Object来进行存储和计算。
db.collection.insert({"location":{"type":"Point","coordinates":[40,5]},"name":"work poi"})
- 查询,mongodb提供了很丰富的查询操作符,各有用于,比如查找给定地点附近的点:
db.geo.find({"location":{"$near":{"$geometry":{"type":"Point","coordinates":[40,5]},"$maxDistance":100,"$minDistance":0}}})