【问题标题】:How to use one of the current document field as coordinates in $geoIntersects query如何在 $geoIntersects 查询中使用当前文档字段之一作为坐标
【发布时间】:2022-01-15 16:17:42
【问题描述】:

我正在尝试创建一个聚合管道以将某些形状与其他一些形状相交。一个简化的管道是这样的:

[
   {
    '$match': {
      'loc.type': {
        '$eq': 'Polygon'
      }
    }
  }, {
    '$addFields': {
      'cor': [
        [
          -11.337890625, 56.31653672211301
        ], [
          13.1396484375, 42.8115217450979
        ]
      ]
    }
  }, {
    '$match': {
      'loc': {
        '$geoIntersects': {
          '$geometry': {
            'type': 'LineString', 
            'coordinates': '$cor'
          }
        }
      }
    }
  }
]

在第一步中,我从集合中选择了每个多边形形状,在下一阶段为其添加了一些坐标,最后将多边形与在阶段 2 中添加的形状匹配。 问题出在第 3 阶段,我无法使用在第 2 阶段创建的cor 字段填充coordinates 字段。

我得到的错误是:GeoJSON coordinates must be an array of coordinates.


另一个类似的问题是这样的:

[
  {
    '$match': {
      'loc.type': {
        '$eq': 'Polygon'
      }
    }
  }, {
    '$addFields': {
      'myshape': {
        'type': 'LineString', 
        'coordinates': [
          [
            -11.337890625, 56.31653672211301
          ], [
            13.1396484375, 42.8115217450979
          ]
        ]
      }
    }
  }, {
    '$match': {
      'loc': {
        '$geoIntersects': {
          '$geometry': '$myshape'
        }
      }
    }
  }
]

在第 2 阶段,我创建了一个完整的 GeoJson 形状(字段 myshape)。我也不能使用myshape 作为$geometry 的形状。我得到的错误是:unknown geo specifier: $geometry: "$myshape"

如何使用当前文档中的字段作为$geometry$geometry.coordinates 字段的值?

【问题讨论】:

    标签: mongodb mongodb-query aggregation-framework gis geospatial


    【解决方案1】:

    很遗憾,Geospatial Queries 不支持使用来自文档字段的地理空间数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 1970-01-01
      • 2013-03-11
      • 2013-05-26
      • 1970-01-01
      • 2017-04-26
      • 1970-01-01
      相关资源
      最近更新 更多