【问题标题】:Find Geopoint with radius which are overlapping geopoint查找具有重叠地理点的半径的地理点
【发布时间】:2020-05-04 11:29:55
【问题描述】:

正如你在下面看到的,我有

具有一定半径的 3 个地理点 A、B、C
1 个地理点 K,

我想找到所有半径重叠K Geo的GeoPoint

所以答案应该是 B、C。

那么如何才能做到这一点呢?

目前我正在使用 Mongodb。但任何其他数据库也可以。

【问题讨论】:

  • 我认为你需要一个第三方库,例如Turf.js。您应该为几乎所有语言找到类似的开源包。一个好的起点可能是GEOS

标签: sql mongodb elasticsearch geolocation geometry


【解决方案1】:

这个问题是基于意见的,就像“任何其他数据库都可以”的陈述一样。 但是为了记录,在ES中的实现方式如下:

PUT circles
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape",
        "strategy": "recursive"
      }
    }
  }
}

PUT circles/_doc/A
{
  "location": {
    "type": "circle",
    "coordinates": [
      16.34817123413086,
      48.20968893477074
    ],
    "radius": "2km"
  }
}

PUT circles/_doc/B
{
  "location": {
    "type": "circle",
    "coordinates": [
      16.374435424804688,
      48.20122291334052
    ],
    "radius": "3km"
  }
}

PUT circles/_doc/C
{
  "location": {
    "type": "circle",
    "coordinates": [
      16.386451721191406,
      48.21586595914765
    ],
    "radius": "4km"
  }
}

GET circles/_search
{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "point",
          "coordinates": [
            16.386795043945312,
            48.208773756674425
          ]
        },
        "relation": "intersects"
      }
    }
  }
}

屈服

[
  {
    "_index":"circles",
    "_type":"_doc",
    "_id":"B",
    "_score":1.0,
    "_source":{

    }
  },
  {
    "_index":"circles",
    "_type":"_doc",
    "_id":"C",
    "_score":1.0,
    "_source":{

    }
  }
]

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
相关资源
最近更新 更多