AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

$geoIntersects(クエリ述語演算子)

$geoIntersects

地理空間データが指定されたGeoJSONオブジェクトと交差するドキュメントを選択します。すなわち データと指定されたオブジェクトの共通部分が空でない場合。

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.

補完ジオメトリは、2 つのジオメトリのうち小さい方です。指定されたジオメトリが複数の半球をカバーする場合、デフォルトのCRS クエリは補完ジオメトリのドキュメントを返します。

例、ジオメトリを地球の表面の 75% をカバーする領域として定義すると、CRS は残りの 25% を補完領域として使用します。クエリでは、大きな 75% 領域ではなく、小さな補完 25% から結果が返されます。

このページの 例 セクションでは、小さい領域と大きい領域を指定する方法を示します。

カスタム 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 "Big" Polygons.

重要

緯度と経度の座標を指定する場合は、最初に経度、次に緯度を指定します。

  • 有効な経度の値は、-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 は、多角形が独自のエッジと交差するために考慮されることを保証するものではありません。独自の冗長性。または 冗長 または エッジを共有するが、内部スペースは含まない別の多角形。

For $geoIntersects, if you specify a single-ringed polygon that has an area greater than a single hemisphere, include the custom MongoDB coordinate reference system in the $geometry expression. Otherwise, $geoIntersects queries for the complementary geometry. For all other GeoJSON polygons with areas greater than a hemisphere, $geoIntersects queries for the complementary geometry.

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 ] ]
]
}
}
}
}
)

単一の半球よりも大きい面積を持つ単一リングの多角形については、「「大きな」多角形と交差する を参照してください。

単一の半球よりも大きい面積を持つ単一リングの 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" }
}
}
}
}
}
)
このページを評価

項目一覧