您的位置:首页 > 数据库 > Mongodb

MongoDB - 空间数据存储、建立索引、空间查询

2017-07-25 15:08 288 查看

1 概要

MongoDB支持空间数据的存储,不过限制了类型必须为GeoJSON。

MongoDB可以满足一些空间查询的需求,对于不需要空间数据处理的项目极为方便,不需要第三方库来充当空间数据的操作层。

MongoDB可以为GeoJSON类型数据建立索引,提升空间查询的效率。

2 MongoDB支持GeoJSON的种类

1.点(Point)

{
"name": "玉泉路站",
"locaton": {
"type": "Point",
"coordinates": [116.25947, 39.913501]
}
}


2.线(LineString)

{
"name": "地铁1号线",
"geom": {
"type": "LineString",
"coordinates": [
[ 116.184378, 39.932476 ],
[ 116.259470, 39.913501 ],
[ 116.522347, 39.914943 ]
]
}
}


3.面(Polygon)

注意:首末点坐标相同

{
"name": "镂空多边形",
"geom": {
"type": "Polygon",
"coordinates": [
[[ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ]],
[[ 2 , 2 ] , [ 3 , 3 ] , [ 4 , 2 ] , [ 2 , 2 ]]
]
}
}


4.多点(MultiPoint)

{
"name": "1号线站点",
"locaton": {
"type": "MultiPoint",
"coordinates": [
[116.259470, 39.913501],
[116.280423, 39.913833],
[116.301550, 39.913710]
]
}
}


5.多线(MultiLineString)

{
"name": "地铁线路",
"geom": {
"type": "MultiLineString",
"coordinates": [
[[ 116.184378, 39.932476 ],[ 116.259470, 39.913501 ],[ 116.522347, 39.914943 ]],
[[ 25, 60 ], [ 11, 22 ], [ 44, 55 ]],
[[ 0, 0 ], [ 50, 50 ]]
]
}
}


6.多面(MultiPolygon)

{
"name": "多面",
"geom": {
"type": "MultiPolygon",
"coordinates": [
[[[ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]],
[[[ 1, 1], [ 2, 1], [ 2, 2 ], [ 1, 2 ], [ 1, 1 ]]]
]
}
}


7.几何集合(GeometryCollectionn)

{
"type":"GeometryCollection",
"geometries":[
{
"type":"MultiPoint",
"coordinate":[
[116.259470, 39.913501],
[116.280423, 39.913833],
[116.301550, 39.913710]
]
},
{
"type":"MultiPolygon",
"coordinate":[
[[[ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ]]],
[[[ 1, 1], [ 2, 1], [ 2, 2 ], [ 1, 2 ], [ 1, 1 ]]]
]
}
]
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb