Bewerken

Delen via


geo_line_centroid()

Applies to: ✅ Microsoft FabricAzure Data ExplorerAzure MonitorMicrosoft Sentinel

Calculates the centroid of a line or a multiline on Earth.

Syntax

geo_line_centroid(lineString)

Learn more about syntax conventions.

Parameters

Name Type Required Description
lineString dynamic ✔️ A LineString or MultiLineString in the GeoJSON format.

Returns

The centroid coordinate values in GeoJSON Format and of a dynamic data type. If the line or the multiline is invalid, the query produces a null result.

Note

  • 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. Line edges are geodesics on the sphere.
  • If input line edges are straight cartesian lines, consider using geo_line_densify() in order to convert planar edges to geodesics.
  • If input is a multiline and contains more than one line, the result will be the centroid of lines union.

LineString definition and constraints

dynamic({"type": "LineString","coordinates": [[lng_1,lat_1], [lng_2,lat_2], ..., [lng_N,lat_N]]})

dynamic({"type": "MultiLineString","coordinates": [[line_1, line_2, ..., line_N]]})

  • LineString coordinates array must contain at least two entries.
  • Coordinates [longitude, latitude] must be valid where longitude is a real number in the range [-180, +180] and latitude is a real number in the range [-90, +90].
  • Edge length must be less than 180 degrees. The shortest edge between the two vertices is chosen.

Examples

The following example calculates line centroid.

let line = dynamic({"type":"LineString","coordinates":[[-73.95796, 40.80042], [-73.97317, 40.764486]]});
print centroid = geo_line_centroid(line);

Output

centroid
{"type": "Point", "coordinates": [-73.965567057230942, 40.782453249627416]}

The following example calculates line centroid longitude.

let line = dynamic({"type":"LineString","coordinates":[[-73.95807266235352,40.800426144169315],[-73.94966125488281,40.79691751000055],[-73.97317886352539,40.764486356930334],[-73.98210525512695,40.76786669510221],[-73.96004676818848,40.7980870753293]]});
print centroid = geo_line_centroid(line)
| project lng = centroid.coordinates[0]

Output

lng
-73.9660675626837

The following example visualizes line centroid on a map.

let line = dynamic({"type":"MultiLineString","coordinates":[[[-73.95798683166502,40.800556090021466],[-73.98193359375,40.76819171855746]],[[-73.94940376281738,40.79691751000055],[-73.97317886352539,40.76435634049001]]]});
print centroid = geo_line_centroid(line)
| render scatterchart with (kind = map)

Screenshot of the New York City Central Park line centroid.

The following example returns true because of the invalid line.

print is_bad_line = isnull(geo_line_centroid(dynamic({"type":"LineString","coordinates":[[1, 1]]})))

Output

is_bad_line
true