$geoIntersects
定義
$geoIntersects
Selects documents whose geospatial data intersects with a specified GeoJSON object; i.e. where the intersection of the data and the specified object is non-empty.
The
$geoIntersects
operator uses the$geometry
operator to specify the GeoJSON object. To specify a GeoJSON polygons or multipolygons using the default coordinate reference system (CRS), use the following syntax:{ <location field>: { $geoIntersects: { $geometry: { type: "<GeoJSON object type>" , coordinates: [ <coordinates> ] } } } } For
$geoIntersects
queries that specify GeoJSON geometries with areas greater than a single hemisphere, the use of the default CRS results in queries for the complementary geometries.A complementary geometry is the smaller of two geometries. If a specified geometry covers more than a hemisphere, the default CRS query returns documents for the complementary geometry.
For example, if you define a geometry to be an area covering 75% of Earth's surface, CRS uses the remaining 25% as the complementary area. The query returns results from that smaller complementary 25% area instead of the larger 75%.
The 例 section on this page shows how to specify smaller and larger areas.
カスタム MongoDB CRS を使用して単一リングの GeoJSON多角形を指定するには、
$geometry
式でカスタム MongoDB CRS を指定する次のプロトタイプを使用します。{ <location field>: { $geoIntersects: { $geometry: { type: "Polygon" , coordinates: [ <coordinates> ], crs: { type: "name", properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } } } } } } The custom MongoDB CRS uses a counter-clockwise winding order and allows
$geoIntersects
to support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere. If the specified polygon is smaller than a single hemisphere, the behavior of$geoIntersects
with the MongoDB CRS is the same as with the default CRS. See also "大きな" 多角形.重要
緯度と経度の座標を指定する場合は、最初に経度、次に緯度を指定します。
有効な経度の値は、
-180
以上、180
以下です。有効な緯度の値は
-90
以上、90
以下です。
動作
地理空間インデックス
$geoIntersects
uses spherical geometry.
$geoIntersects
does not require a geospatial index. However, a
geospatial index will improve query performance. Only the
2dsphere geospatial index supports
$geoIntersects
.
退化ジオメトリ
$geoIntersects
does not guarantee that it will consider a
polygon to intersect with its own edges; its own vertices; or another
polygon sharing vertices or edges but no interior space.
"大きな" 多角形
$geoIntersects
の場合、単一の半球よりも大きい面積を持つ単一リングの多角形を指定する場合は、 $geometry
式にカスタム MongoDB 座標参照システムを含めます。それ以外の場合、 $geoIntersects
補完ジオメトリを照会します。半球より大きい面積を持つその他すべての GeoJSON 多角形については、 $geoIntersects
補完的なジオメトリを照会します。
例
Intersects a Polygon
The following example uses $geoIntersects
to select all
loc
data that intersect with the Polygon
defined by
the coordinates
array. The area of the polygon is less than the
area of a single hemisphere:
db.places.find( { loc: { $geoIntersects: { $geometry: { type: "Polygon" , coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ] } } } } )
For single-ringed polygons with areas greater than a single hemisphere, see Intersects a "Big" Polygon.
Intersects a "Big" Polygon
単一の半球よりも大きい面積を持つ単一リングの GeoJSON 多角形でクエリを実行するには、 $geometry
式でカスタム MongoDB 座標参照システムを指定する必要があります。 例:
db.places.find( { loc: { $geoIntersects: { $geometry: { type : "Polygon", coordinates: [ [ [ -100, 60 ], [ -100, 0 ], [ -100, -60 ], [ 100, -60 ], [ 100, 60 ], [ -100, 60 ] ] ], crs: { type: "name", properties: { name: "urn:x-mongodb:crs:strictwinding:EPSG:4326" } } } } } } )