On this page本页内容
MongoDB supports the GeoJSON object types listed on this page.MongoDB支持此页面上列出的GeoJSON对象类型。
To specify GeoJSON data, use an embedded document with:要指定GeoJSON数据,请使用具有以下内容的嵌入式文档:
type
that specifies the GeoJSON object type andtype
的字段,指定GeoJSON对象类型,并且a field named 名为coordinates
that specifies the object's coordinates.coordinates
的字段,用于指定对象的坐标。
If specifying latitude and longitude coordinates, list the longitude first and then latitude:如果指定纬度和经度坐标,请先列出经度,然后列出纬度:
-180
and 180
, both inclusive.-180
和180
之间,两者都包括在内。-90
and 90
, both inclusive.-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:以下示例指定了GeoJSON点:
{ type: "Point", coordinates: [ 40, 5 ] }
LineString
The following example specifies a GeoJSON LineString:以下示例指定了GeoJSONLineString:
{ type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] }
Polygon
Polygons多边形 consist of an array of GeoJSON 由GeoJSON LinearRing
coordinate arrays. LinearRing
坐标数组组成。These 这些LinearRings
are closed LineStrings
. LinearRings
是闭合的LinearRings
。Closed 闭合LineStrings
have at least four coordinate pairs and specify the same position as the first and last coordinates.LinearRings
至少有四个坐标对,并指定与第一个和最后一个坐标相同的位置。
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.仔细检查点,以避免共享边错误,以及重叠和其他类型的交点。
The following example specifies a GeoJSON 以下示例指定了一个带有外环而没有内环(或孔)的GeoJSONPolygon
with an exterior ring and no interior rings (or holes). Polygon
。The first and last coordinates must match in order to close the polygon:第一个和最后一个坐标必须匹配才能闭合多边形:
{ type: "Polygon", coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ] }
For Polygons with a single ring, the ring cannot self-intersect.对于具有单个环的多边形,环不能自相交。
For Polygons with multiple rings:对于具有多个环的多边形:
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
GeoJSON 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
The following example specifies a GeoJSON MultiLineString:以下示例指定了GeoJSONMultiLineString
:
{ 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 Versions
The following example specifies a GeoJSON MultiPolygon:以下示例指定了GeoJSONMultiPolygon
:
{ 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 Versions
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 ] ] ] } ] }