本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
$geometry
Amazon DocumentDB 中的$geometry运算符用于在地理空间查询中指定 GeoJSON 几何对象。此运算符可与其他地理空间查询运算符(如$geoWithin和)结合使用$geoIntersects,对您的数据执行空间查询。
在亚马逊 DocumentDB 中,$geometry运算符支持以下 GeoJSON 几何类型:
-
Point
-
LineString
-
Polygon
-
MultiPoint
-
MultiLineString
-
MultiPolygon
-
GeometryCollection
参数
-
type: geoJSON 几何对象的类型,例如PointPolygon、等 -
coordinates:表示几何形状的坐标数组。坐标数组的结构取决于几何类型。
示例(MongoDB 外壳)
以下示例演示如何使用$geometry运算符在 Amazon DocumentDB 中执行$geoIntersects查询。
创建示例文档
db.locations.insertMany([ { "_id": 1, "name": "Location 1", "location": { "type": "Point", "coordinates": [-73.983253, 40.753941] } }, { "_id": 2, "name": "Location 2", "location": { "type": "Polygon", "coordinates": [[ [-73.998427, 40.730309], [-73.954348, 40.730309], [-73.954348, 40.780816], [-73.998427, 40.780816], [-73.998427, 40.730309] ]] } } ]);
查询示例
db.locations.find({ "location": { "$geoIntersects": { "$geometry": { "type": "Polygon", "coordinates": [[ [-73.998, 40.730], [-73.954, 40.730], [-73.954, 40.781], [-73.998, 40.781], [-73.998, 40.730] ]] } } } })
输出
[
{
"_id": 2,
"name": "Location 2",
"location": {
"type": "Polygon",
"coordinates": [
[
[-73.998427, 40.730309],
[-73.954348, 40.730309],
[-73.954348, 40.780816],
[-73.998427, 40.780816],
[-73.998427, 40.730309]
]
]
}
}
]
代码示例
要查看使用该$geometry命令的代码示例,请选择要使用的语言的选项卡: