我正在使用mongo存储一些地理本地化数据,目的是使用$geointerch检索它们。具体地说,我将此文档存储在数据库中:

  {
    "loc": {
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              -179.875,
              -89.875
            ],
            [
              179.875,
              -89.875
            ],
            [
              179.875,
              89.875
            ],
            [
              -179.875,
              89.875
            ],
            [
              -179.875,
              -89.875
            ]
          ]
        ]
      },
      "crs": {
        "type": "name",
        "properties": {
          "name": "urn:x-mongodb:crs:strictwinding:EPSG:4326"
        }
      },
      "type": "Feature",
      "properties": {}
    },
    "_id": "576af8e31d41c87fa1f1d04f"
  }

你可能会注意到它几乎覆盖了整个世界。现在不管我为$geointerch查询输入了什么坐标,都不会返回…有人知道为什么吗?
我正在使用的查询示例可能是:
[
  {
    "loc.geometry": {
      "$geoIntersects": {
        "$geometry": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                13.4307861328125,
                41.599013054830216
              ],
              [
                13.9801025390625,
                41.599013054830216
              ],
              [
                13.9801025390625,
                41.80407814427234
              ],
              [
                13.4307861328125,
                41.80407814427234
              ],
              [
                13.4307861328125,
                41.599013054830216
              ]
            ]
          ]
        }
      }
    }
  },
  {
    "loc": 1
  }
]

当然,查询的坐标包含在保存的文档中的多边形内(我的意思是…它和世界一样大,啊!)但不知为什么它找不到匹配的…我有点迷路了。

最佳答案

现在就调查一下。如果多边形是实心的并且比地球的半球大,mongo将返回该区域之外的所有内容。查看geoin文档中的大型poly和crs

关于mongodb - MongoDB geointersect无法找到大多边形,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38045081/

10-12 12:47
查看更多