GeoJSON オブジェクト
Overview
MongoDB supports the GeoJSON object types listed on this page.
GeoJSON データを指定するには、以下の埋め込みドキュメントを使用します。
GeoJSON オブジェクト タイプを指定する
type
という名前を持つフィールド、オブジェクトの座標を指定する
coordinates
というフィールド。
<field>: { type: <GeoJSON type> , coordinates: <coordinates> }
重要
緯度と経度の座標を指定する場合は、最初に経度、次に緯度を指定します。
有効な経度の値は、
-180
以上、180
以下です。有効な緯度の値は
-90
以上、90
以下です。
GeoJSON オブジェクトに対する MongoDB の地理空間クエリは球体上で計算されます。MongoDB は、GeoJSON オブジェクトに対する地理空間クエリに WGS84 参照システムを使用します。
Point
The following example specifies a GeoJSON 点:
{ type: "Point", coordinates: [ 40, 5 ] }
LineString
The following example specifies a GeoJSON LineString:
{ type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] }
Polygon
Polygons consist of
an array of GeoJSON LinearRing
coordinate arrays. These
LinearRings
are closed LineStrings
. Closed LineStrings
have
at least four coordinate pairs and specify the same position as the
first and last coordinates.
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 Polygon
with an exterior
ring and no interior rings (or holes). 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.
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:
{ type : "Polygon", coordinates : [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ], [ [ 2 , 2 ] , [ 3 , 3 ] , [ 4 , 2 ] , [ 2 , 2 ] ] ] }
MultiPoint
Requires 2dsphere インデックス
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
Requires 2dsphere インデックス
The following example specifies a 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 インデックス
The following example specifies a 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 インデックス
The following example stores coordinates of GeoJSON type 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 ] ] ] } ] }