【问题标题】:Find coordinates in a polygon在多边形中查找坐标
【发布时间】:2020-12-09 17:30:51
【问题描述】:

如何找到存储在弹性索引中的多边形。 简单映射:

PUT /regions
{
    "mappings": {
        "properties": {
            "location": {
                "type": "geo_shape"
            }
        }
    }
}

还有简单的多边形:

/regions/_doc/1
{
    "location" : {
        "type" : "polygon",
        "coordinates" : [
            [ 
                [53.847332102970626,27.485155519098047],
                [53.84626875748117,27.487134989351038],
                [53.8449047241684,27.48501067981124],
                [53.84612634308789,27.482945378869765],
                [53.847411219859,27.48502677306532],
                [53.847332102970626,27.485155519098047] 
            ]
        ]
    }
}

根据文档,只有当多边形包含在请求Geo-polygon query 中时,我才能在多边形内搜索坐标,但我需要通过查询中的坐标查找多边形。 Elasticsearch 7.6 版本。

查询:

{
  "query": {
    "match_all": {}
  },
  "filter": {
    "geo_shape": {
      "geometry": {
        "shape": {
          "coordinates": [
            53.846415,
            27.485756
          ],
          "type": "point"
        },
        "relation": "whithin"
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-geo-shape


    【解决方案1】:

    您在正确的道路上,但您的查询严重错误。这是修复:

    {
      "query": {
        "bool": {
          "filter": {
            "geo_shape": {
              "location": {
                "shape": {
                  "coordinates": [
                    53.846415,
                    27.485756
                  ],
                  "type": "point"
                },
                "relation": "intersects"
              }
              
            }
          }
        }
      }
    }
    

    注意我是如何使用intersects 而不是within。这个GIS StackExchange answer解释了原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-02
      • 2019-02-09
      • 1970-01-01
      • 2012-09-20
      • 2013-03-13
      • 1970-01-01
      • 2019-02-14
      • 2018-02-14
      相关资源
      最近更新 更多