GeoJSON Objects对象
On this page本页内容
Overview概述
MongoDB supports the GeoJSON object types listed on this page.MongoDB支持本页列出的GeoJSON对象类型。
To specify GeoJSON data, use an embedded document with:要指定GeoJSON数据,请使用带有以下内容的嵌入式文档:
a field named指定GeoJSON对象类型的名为type
that specifies the GeoJSON object type andtype
的字段,以及a field named一个名为coordinates
that specifies the object's coordinates.coordinates
的字段,用于指定对象的坐标。ImportantIf specifying latitude and longitude coordinates, list the longitude first, and then latitude.如果指定纬度和经度坐标,请先列出经度,然后列出纬度。Valid longitude values are between有效的经度值介于-180
and180
, both inclusive.-180
和180
之间(包括-180
和180
)。Valid latitude values are between有效的纬度值介于-90
and90
, both inclusive.-90
和90
之间(包括-90
和90
)。
<field>: { type: <GeoJSON type> , coordinates: <coordinates> }
MongoDB geospatial queries on GeoJSON objects calculate on a sphere; MongoDB uses the WGS84 reference system for geospatial queries on GeoJSON objects.MongoDB对GeoJSON对象的地理空间查询在球体上计算;MongoDB使用WGS84参考系统对GeoJSON对象进行地理空间查询。
Point
The following example specifies a GeoJSON Point以下示例指定GeoJSONPoint:
:
{ type: "Point", coordinates: [ 40, 5 ] }
LineString
The following example specifies a GeoJSON LineString以下示例指定GeoJSON LineString:
:
{ type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] }
Polygon
Polygons consist of an array of GeoJSON 由GeoJSON LinearRing坐标数组组成。LinearRing
coordinate arrays. These 这些LinearRings
are closed LineStrings
. LinearRings
是闭合的LineStrings
。Closed 闭合的LineStrings
have at least four coordinate pairs and specify the same position as the first and last coordinates.LineStrings
至少有四个坐标对,并指定与第一个和最后一个坐标相同的位置。
The line that joins two points on a curved surface may or may not contain the same set of co-ordinates that joins those two points on a flat surface. 连接曲面上两点的线可能包含也可能不包含连接平面上两点的同一组坐标。The line that joins two points on a curved surface will be a geodesic. 连接曲面上两点的线将是一条测地线。Carefully check points to avoid errors with shared edges, as well as overlaps and other types of intersections.仔细检查点,以避免共享边、重叠和其他类型的交点出现错误。
Polygons with a Single Ring具有单个环的多边形
The following example specifies a GeoJSON 以下示例指定了一个GeoJSONPolygon
with an exterior ring and no interior rings (or holes). The first and last coordinates must match in order to close the polygon:Polygon
,该多边形有一个外部环,没有内部环(或孔)。第一个和最后一个坐标必须匹配才能闭合多边形:
{
type: "Polygon",
coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
}
For Polygons with a single ring, the ring cannot self-intersect.对于具有单个环的多边形,环不能自相交。
Polygons with Multiple Rings具有多个环的多边形
For Polygons with multiple rings:对于具有多个环的多边形:
The first described ring must be the exterior ring.第一个描述的环必须是外环。The exterior ring cannot self-intersect.外环不能自相交。Any interior ring must be entirely contained by the outer ring.任何内环必须完全由外环包含。Interior rings cannot intersect or overlap each other. Interior rings cannot share an edge.内环不能相互交叉或重叠。内环不能共用一条边。
The following example represents a GeoJSON polygon with an interior ring:以下示例表示一个带有内环的GeoJSON多边形:
{
type : "Polygon",
coordinates : [
[ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ],
[ [ 2 , 2 ] , [ 3 , 3 ] , [ 4 , 2 ] , [ 2 , 2 ] ]
]
}
MultiPoint
Requires 2dsphere Indexes需要2dsphere
索引
GeoJSON MultiPointGeoJSON MultiPoint embedded documents encode a list of points.
嵌入文档对点列表进行编码。
{
type: "MultiPoint",
coordinates: [
[ -73.9580, 40.8003 ],
[ -73.9498, 40.7968 ],
[ -73.9737, 40.7648 ],
[ -73.9814, 40.7681 ]
]
}
MultiLineString
Requires 2dsphere Indexes需要2dsphere
索引
The following example specifies a GeoJSON MultiLineString以下示例指定GeoJSON MultiLineString:
:
{
type: "MultiLineString",
coordinates: [
[ [ -73.96943, 40.78519 ], [ -73.96082, 40.78095 ] ],
[ [ -73.96415, 40.79229 ], [ -73.95544, 40.78854 ] ],
[ [ -73.97162, 40.78205 ], [ -73.96374, 40.77715 ] ],
[ [ -73.97880, 40.77247 ], [ -73.97036, 40.76811 ] ]
]
}
MultiPolygon
Requires 2dsphere Indexes需要2dsphere
索引
The following example specifies a GeoJSON MultiPolygon以下示例指定GeoJSON MultiPolygon:
:
{
type: "MultiPolygon",
coordinates: [
[ [ [ -73.958, 40.8003 ], [ -73.9498, 40.7968 ], [ -73.9737, 40.7648 ], [ -73.9814, 40.7681 ], [ -73.958, 40.8003 ] ] ],
[ [ [ -73.958, 40.8003 ], [ -73.9498, 40.7968 ], [ -73.9737, 40.7648 ], [ -73.958, 40.8003 ] ] ]
]
}
GeometryCollection
Requires 2dsphere Indexes需要2dsphere
索引
The following example stores coordinates of GeoJSON type GeometryCollection以下示例存储GeoJSON类型GeometryCollection:
的坐标:
{
type: "GeometryCollection",
geometries: [
{
type: "MultiPoint",
coordinates: [
[ -73.9580, 40.8003 ],
[ -73.9498, 40.7968 ],
[ -73.9737, 40.7648 ],
[ -73.9814, 40.7681 ]
]
},
{
type: "MultiLineString",
coordinates: [
[ [ -73.96943, 40.78519 ], [ -73.96082, 40.78095 ] ],
[ [ -73.96415, 40.79229 ], [ -73.95544, 40.78854 ] ],
[ [ -73.97162, 40.78205 ], [ -73.96374, 40.77715 ] ],
[ [ -73.97880, 40.77247 ], [ -73.97036, 40.76811 ] ]
]
}
]
}