Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: ✅ Microsoft Fabric ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Calculates the shortest distance in meters between two geospatial coordinates on Earth.
Syntax
geo_distance_2points(
p1_longitude,
p1_latitude,
p2_longitude,
p2_latitude,
[ use_spheroid ])
Learn more about syntax conventions.
Parameters
Name | Type | Required | Description |
---|---|---|---|
p1_longitude | real |
✔️ | The longitude value in degrees of the first geospatial coordinate. A valid value is in the range [-180, +180]. |
p1_latitude | real |
✔️ | The latitude value in degrees of the first geospatial coordinate. A valid value is in the range [-90, +90]. |
p2_longitude | real |
✔️ | The longitude value in degrees of the second geospatial coordinate. A valid value is in the range [-180, +180]. |
p2_latitude | real |
✔️ | The latitude value in degrees of the second geospatial coordinate. A valid value is in the range [-90, +90]. |
use_spheroid | bool |
If false will use a sphere as geodetic datum for measuring distance. If true will measure distance using spheroid. If unspecified, the default value false is used. |
Returns
The shortest distance, in meters, between two geographic locations on Earth. If the coordinates are invalid, the query produces a null result.
Note
- The geospatial coordinates are interpreted as represented by the WGS-84 coordinate reference system.
- Most applications should measure distance using sphere ('use_spheroid' = false) which is more performant. If extra precision is needed, 'use_spheroid' option can be set to 'true', for extra precision, which might be more relevant for bigger distances, which might get impacted due to earth curvature.
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)
Output
distance_in_meters |
---|
1546754.35197381 |
The following example finds an approximation of the shortest path from Seattle to London. 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)
Output
The following example finds all rows in which the shortest distance between two coordinates is between one meter 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
Output
distance_1_to_11m |
---|
10.5723100154958 |
7.92153588248414 |
The following example returns a null result because of the invalid coordinate input.
print distance = geo_distance_2points(300,1,1,1)
Output
distance |
---|