geo_distance_2points()geo_distance_2points()

计算两个地理空间坐标在地球上的最短距离。Calculates the shortest distance between two geospatial coordinates on Earth.

语法Syntax

geo_distance_2points(p1_longitude, p1_latitude, p2_longitude, p2_latitude)geo_distance_2points(p1_longitude, p1_latitude, p2_longitude, p2_latitude)

参数Arguments

  • p1_longitude:第一个地理空间坐标,经度值(度)。p1_longitude: First geospatial coordinate, longitude value in degrees. 有效值为 [-180, +180] 范围内的实数。Valid value is a real number and in the range [-180, +180].
  • p1_latitude:第一个地理空间坐标,纬度值(度)。p1_latitude: First geospatial coordinate, latitude value in degrees. 有效值为 [-90, +90] 范围内的实数。Valid value is a real number and in the range [-90, +90].
  • p2_longitude:第二个地理空间坐标,经度值(度)。p2_longitude: Second geospatial coordinate, longitude value in degrees. 有效值为 [-180, +180] 范围内的实数。Valid value is a real number and in the range [-180, +180].
  • p2_latitude:第二个地理空间坐标,纬度值(度)。p2_latitude: Second geospatial coordinate, latitude value in degrees. 有效值为 [-90, +90] 范围内的实数。Valid value is a real number and in the range [-90, +90].

返回Returns

地球上两个地理位置之间的最短距离(以米为单位)。The shortest distance, in meters, between two geographic locations on Earth. 如果坐标无效,则查询将生成 null 结果。If the coordinates are invalid, the query will produce a null result.

备注

  • 对按照 WGS-84 坐标参考系统表示的地理空间坐标进行解释。The geospatial coordinates are interpreted as represented by the WGS-84 coordinate reference system.
  • 用来测量地球上距离的大地测量基准是一个球体。The geodetic datum used to measure distance on Earth is a sphere.

示例Examples

下面的示例查找西雅图与洛杉矶之间的最短距离。The following example finds the shortest distance between Seattle and Los Angeles.

西雅图与洛杉矶之间的距离

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

下面是从西雅图到伦敦的最短路径的近似值。Here is an approximation of shortest path from Seattle to London. 该线路由沿线串分布的距其 500 米范围内的坐标组成。The line consists of coordinates along the LineString and within 500 meters from it.

西雅图到伦敦的线串

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) // map rendering available in Kusto Explorer desktop

以下示例查找其中的两个坐标之间的最短距离在 1 到 11 米之间的所有行。The following example finds all rows in which the shortest distance between two coordinates is between 1 and 11 meters.

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_11mdistance_1_to_11m
10.572310015495810.5723100154958
7.921535882484147.92153588248414

下面的示例由于坐标输入无效而返回 null 结果。The following example returns a null result because of the invalid coordinate input.

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