对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

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

互补几何图形是两个几何图形中较小的一个。如果指定的几何图形覆盖的范围超过半球,默认CRS查询会返回互补几何图形的文档。

示例,如果您将几何图形定义为覆盖地球表面 75% 的区域,则 CRS 会使用剩余的 25% 作为补充区域。查询会从较小的互补 25% 区域而不是较大的 75% 中返回结果。

The Examples section on this page shows how to specify smaller and larger areas.

要使用自定义 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" }
}
}
}
}
}
)
给本页内容打分

在此页面上