Definition定义
$geoIntersectsSelects 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.选择地理空间数据与指定GeoJSON对象相交的文档;即,数据和指定对象的交集不是空的。The$geoIntersectsoperator uses the$geometryoperator to specify the GeoJSON object.$geoIntersects运算符使用$geometry运算符指定GeoJSON对象。To specify a GeoJSON polygons or multipolygons using the default coordinate reference system (CRS), use the following syntax:要使用默认坐标参考系(CRS)指定GeoJSON多边形或多多边形,请使用以下语法:{
<location field>: {
$geoIntersects: {
$geometry: {
type: "<GeoJSON object type>" ,
coordinates: [ <coordinates> ]
}
}
}
}For对于指定面积大于单个半球的GeoJSON几何体的$geoIntersectsqueries that specify GeoJSON geometries with areas greater than a single hemisphere, the use of the default CRS results in queries for the complementary geometries.$geoIntersects查询,使用默认CRS会导致对互补几何体的查询。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.互补几何体是两个几何体中较小的一个。如果指定的几何体覆盖了多个半球,则默认的CRS查询将返回互补几何体的文档。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%.例如,如果将几何体定义为覆盖地球表面75%的区域,CRS将剩余的25%用作补充区域。查询返回的结果来自较小的互补25%区域,而不是较大的75%区域。The Examples section on this page shows how to specify smaller and larger areas.本页的示例部分显示了如何指定更小和更大的区域。To specify a single-ringed GeoJSON polygon with a custom MongoDB CRS, use the following prototype that specifies the custom MongoDB CRS in the要使用自定义MongoDB CRS指定一个单环GeoJSON多边形,请使用以下原型在$geometryexpression:$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自定义MongoDB CRS使用逆时针缠绕顺序,并允许$geoIntersectsto support queries with a single-ringed GeoJSON polygon whose area is greater than or equal to a single hemisphere.$geoIntersects支持使用面积大于或等于单个半球的单个环形GeoJSON多边形的查询。If the specified polygon is smaller than a single hemisphere, the behavior of如果指定的多边形小于单个半球,则$geoIntersectswith the MongoDB CRS is the same as with the default CRS. See also "Big" Polygons.$geoIntersects与MongoDB CRS的行为与默认CRS的行为相同。另请参见“大”多边形。Important
If specifying latitude and longitude coordinates, list the longitude first, and then latitude.如果指定纬度和经度坐标,请先列出经度,然后再列出纬度。Valid longitude values are between有效的经度值介于-180and180, both inclusive.-180和180之间,包括-180和180。Valid latitude values are between有效的纬度值介于-90and90, both inclusive.-90和90之间,包括-90和90。
Behavior行为
Geospatial Indexes地理空间索引
$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.2dsphere地理空间索引支持$geoIntersects。
Degenerate Geometry退化几何
$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.不保证它会认为多边形与其自身的边相交;其自身的顶点;或者共享顶点或边但没有内部空间的另一个多边形。
"Big" Polygons“大”多边形
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. $geoIntersects,如果指定面积大于单个半球的单个环形多边形,请在$geometry表达式中包含自定义MongoDB坐标参考系。Otherwise, 否则,$geoIntersects queries for the complementary geometry. $geoIntersects将查询互补几何体。For all other GeoJSON polygons with areas greater than a hemisphere, 对于面积大于半球的所有其他GeoJSON多边形,$geoIntersects queries for the complementary geometry.$geoIntersects会查询互补几何体。
Examples示例
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:$geoIntersects选择与coordinates数组定义的多边形相交的所有loc数据。多边形的面积小于单个半球的面积:
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与“大”多边形相交
To query with a single-ringed GeoJSON polygon whose area is greater than a single hemisphere, the 要使用面积大于单个半球的单个环形GeoJSON多边形进行查询,$geometry expression must specify the custom MongoDB coordinate reference system. For example:$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" }
}
}
}
}
}
)