【问题标题】:$centerSphere is not returning any geojson polygons (mongoDB)$centerSphere 没有返回任何 geojson 多边形(mongoDB)
【发布时间】:2023-03-28 10:36:01
【问题描述】:

我在使用以下 Mongo 查询时遇到了很多问题

location: { $geoWithin: { $centerSphere: [[lon,lat],radians] } }

由于某种原因,它只返回 geoJSON 点并忽略我所有的 geoJSON 多边形。 documentation 声明:

您可以在 GeoJSON 对象和旧坐标对上使用 $centerSphere 运算符。

我正在使用 Mongoose 运行查询,我的 geoJSON 被 NPM 模块 wellknown 从 WellKnown Text 中覆盖。这就是我的 geoJSON 在知名模块转换它们后的样子:

 "location": {
    "coordinates": [
        22.1,
        33.3
    ],
    "type": "Point"
}

"location": {
    "coordinates": [
        [
            [
                43,
                30
            ],
            [
                40,
                28
            ],
            [
                49,
                27
            ],
            [
                43,
                30
            ]
        ],
        [
            [
                44,
                28
            ],
            [
                44.7,
                28.8
            ],
            [
                46,
                28
            ],
            [
                44,
                28
            ]
        ]
    ],
    "type": "Polygon"
}

我的 Mongoose 架构定义为:

location: {
  type: schema.Types.Mixed,
  index: '2dsphere',
  required: false
}

我应该补充一点,withinPolygon 方法按预期工作,并且我得到了 Points 和 Polygons 返回。以下工作完全正常:

location: { $geoWithin: { $geometry: geoJSON } }

感谢您的帮助。我已阅读文档,但看不到任何地方提到 $centerSphere 仅返回 geoJSON 点。

【问题讨论】:

    标签: mongodb mongoose polygon geojson point


    【解决方案1】:

    随着最近发布的 MongoDB 版本 3.6.0-rc0,您现在可以使用 $geoWithin 地理空间运算符 $centerSphere 查询 GeoJSON LineStrings 和 Polygons。

    另请参阅SERVER-27968 有关更新的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-23
      • 2015-02-17
      • 2017-07-13
      • 1970-01-01
      • 2017-03-15
      • 2022-12-22
      • 2015-08-22
      • 2013-08-24
      相关资源
      最近更新 更多