首页 > 解决方案 > 如何从中心坐标和半径计算地理边界框

问题描述

我有纬度、经度和位置半径:

lat = 38.7199877874397
long = -116.717434703125
radius = 6477937.81256012 - radius in metrs.

我需要根据此示例计算用于在 Elasticsearch 中过滤的地理边界框: https ://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html#query -dsl-geo-bounding-box-query

地理边界框,例如应该看起来像

"geo_bounding_box": {
          "pin.location": {
            "top_left": {
              "lat": 40.73,
              "lon": -74.1
            },
            "bottom_right": {
              "lat": 40.01,
              "lon": -71.12
            }
          }

我尝试使用这个公式:

(X - dX, Y - dY) and (X + dX, Y + dY)
Where:
X - longitude
Y - latitude
dY = 360 * r / R - the earth radius is R, in the same units as r
dX = dY * cos (radians (Y))

但我有错误的数字:

((-397.59384191845777, -321.2800122125603), (164.1589725122078, 398.7199877874397))

我如何计算地理边界框赖特?将不胜感激。

标签: elasticsearchmathgeometry

解决方案


推荐阅读