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

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

$geoWithin

指定した形状内に完全に存在する地理空間データを含むドキュメントを選択します。

The specified shape can be either a GeoJSON Polygon (either single-ringed or multi-ringed), a GeoJSON MultiPolygon, or a shape defined by legacy coordinate pairs. The $geoWithin operator uses the $geometry operator to specify the GeoJSON object.

デフォルトの座標参照システム(CRS)を使用して GeoJSON 多角形またはマルチポリゴンを指定するには、次の構文を使用します。

{
<location field>: {
$geoWithin: {
$geometry: {
type: <"Polygon" or "MultiPolygon"> ,
coordinates: [ <coordinates> ]
}
}
}
}

For $geoWithin 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.

カスタム MongoDB CRS を使用して単一リングの GeoJSON多角形を指定するには、 $geometry式でカスタム MongoDB CRS を指定する次のプロトタイプを使用します。

{
<location field>: {
$geoWithin: {
$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 $geoWithin 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 $geoWithin with the MongoDB CRS is the same as with the default CRS. See also "Big" Polygons.

平面上の legacy coordinate pairs で定義された形状に含めるかどうかをクエリする場合は、次の構文を使用します。

{
<location field>: {
$geoWithin: { <shape operator>: <coordinates> }
}
}

利用可能な形状演算子は次のとおりです。

重要

経度と緯度を使用する場合は、longitude, latitude の順に座標を指定します。

$geoWithin does not require a geospatial index. However, a geospatial index will improve query performance. Both 2dsphere and 2d geospatial indexes support $geoWithin.

The $geoWithin operator does not return sorted results. As such, MongoDB can return $geoWithin queries more quickly than geospatial $near or $nearSphere queries, which sort results.

$geoWithin ジオメトリの一部がそのコンポーネント ジオメトリを含むと見なされたり、コンポーネント ジオメトリを共有する別の多角形と見なされたりすることを保証するものではありません。

For $geoWithin, 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, $geoWithin queries for the complementary geometry. For all other GeoJSON polygons with areas greater than a hemisphere, $geoWithin queries for the complementary geometry.

次の例では、GeoJSON Polygon 内に完全に存在するすべての loc データを選択します。多角形の面積は 1 つの半球の面積よりも小さくなります。

db.places.find(
{
loc: {
$geoWithin: {
$geometry: {
type : "Polygon" ,
coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ]
}
}
}
}
)

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

単一の半球よりも大きい面積を持つ単一リングの GeoJSON 多角形でクエリを実行するには、 $geometry式でカスタム MongoDB 座標参照システムを指定する必要があります。 例:

db.places.find(
{
loc: {
$geoWithin: {
$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" }
}
}
}
}
}
)
このページを評価

項目一覧