geo_distance_2points()

计算地球上两个地理空间坐标之间的最短距离(米)。

语法

geo_distance_2points(p1_longitude,p1_latitude,p2_longitude,p2_latitude)

详细了解语法约定

参数

客户 类型​​ 必需 说明
p1_longitude real 第一个地理空间坐标的经度值(度)。 有效值在 [-180, +180] 范围内。
p1_latitude real 第一个地理空间坐标的纬度值(度)。 有效值在 [-90, +90] 范围内。
p2_longitude real 第二个地理空间坐标的经度值(度)。 有效值在 [-180, +180] 范围内。
p2_latitude real 第二个地理空间坐标的纬度值(度)。 有效值在 [-90, +90] 范围内。

返回

地球上两个地理位置之间的最短距离(以米为单位)。 如果坐标无效,则查询将生成 null 结果。

注意

  • 对按照 WGS-84 坐标参考系统表示的地理空间坐标进行解释。
  • 用于测量地球上的距离的大地基准是一个球体。

示例

下面的示例查找西雅图与洛杉矶之间的最短距离。

Distance between Seattle and Los Angeles.

print distance_in_meters = geo_distance_2points(-122.407628, 47.578557, -118.275287, 34.019056)

输出

distance_in_meters
1546754.35197381

下面是从西雅图到伦敦的最短路径的近似值。 该线路由沿线串分布的距其 500 米范围内的坐标组成。

Seattle to London LineString.

range i from 1 to 1000000 step 1
| project lng = rand() * real(-122), lat = rand() * 90
| where lng between(real(-122) .. 0) and lat between(47 .. 90)
| where geo_distance_point_to_line(lng,lat,dynamic({"type":"LineString","coordinates":[[-122,47],[0,51]]})) < 500
| render scatterchart with (kind=map)

以下示例查找其中的两个坐标之间的最短距离在 1 米到 11 米之间的所有行。

StormEvents
| extend distance_1_to_11m = geo_distance_2points(BeginLon, BeginLat, EndLon, EndLat)
| where distance_1_to_11m between (1 .. 11)
| project distance_1_to_11m

输出

distance_1_to_11m
10.5723100154958
7.92153588248414

下面的示例由于坐标输入无效而返回 null 结果。

print distance = geo_distance_2points(300,1,1,1)

输出

distance