翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
$geoWithin
Amazon DocumentDB の $geoWithin演算子は、位置データ (GeoJSON オブジェクトとして表されます) がポリゴンやマルチポリゴンなどの指定されたシェイプ内に完全に含まれているドキュメントを検索するために使用されます。これは、特定の地理的リージョン内にあるオブジェクトのクエリに役立ちます。
パラメータ
-
$geometry: クエリ対象のシェイプを表す GeoJSON オブジェクト。
例 (MongoDB シェル)
次の例は、 $geoWithin演算子を使用して、ニューヨーク州内にあるすべての空港を検索する方法を示しています。
サンプルドキュメントを作成する
// Insert state document db.states.insert({ "name": "New York", "loc": { "type": "Polygon", "coordinates": [[ [-79.76278, 45.0], [-73.94, 45.0], [-73.94, 40.5], [-79.76278, 40.5], [-79.76278, 45.0] ]] } }); // Insert airport documents db.airports.insert([ { "name": "John F. Kennedy International Airport", "type": "airport", "code": "JFK", "loc": { "type": "Point", "coordinates": [-73.7781, 40.6413] } }, { "name": "LaGuardia Airport", "type": "airport", "code": "LGA", "loc": { "type": "Point", "coordinates": [-73.8772, 40.7769] } }, { "name": "Buffalo Niagara International Airport", "type": "airport", "code": "BUF", "loc": { "type": "Point", "coordinates": [-78.7322, 42.9403] } } ]);
クエリの例
var state = db.states.findOne({"name": "New York"}); db.airports.find({ "loc": { "$geoWithin": { "$geometry": state.loc } } }, { "name": 1, "type": 1, "code": 1, "_id": 0 });
出力
[
{
"name": "John F. Kennedy International Airport",
"type": "airport",
"code": "JFK"
},
{
"name": "LaGuardia Airport",
"type": "airport",
"code": "LGA"
}
]
コードの例
$geoWithin コマンドを使用するコード例を表示するには、使用する言語のタブを選択します。