geo-registry

Measure Length

The length of each line, as a number or a new attribute.

Pitfall. In a geographic CRS, planar engines return degrees.
Pitfall. For polygons, some functions return the perimeter and others 0 (PostGIS ST_Length); use a perimeter function for outlines.
About this operation
Also called Calculate Geometry (length), line length, shape length, perimeter
Group vector/measure
Checks crs.measure
Pitfalls 2 listed above
Columbus tool Not stated
Notes Not stated
Status active
Broader Not stated
Narrower Not stated
Related

Parameters

Name Type Required Default Values Note
unit enum no m m, ft, us-ft, km, mi Not stated

Inputs and outputs

Direction Name Type Geometry Note
Input layer vector line Not stated
Output output any Not stated The lengths, or the layer with a length attribute.

In each engine

Engine Tool Parameters Differences
apache-sedona sedona.sql.ST_Length
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • layer → geometry
  • A Spark SQL function: arguments are columns or column names, run over a Spark DataFrame.
geopandas geopandas.GeoSeries.length
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • A property of the GeoSeries; for polygons, the perimeter.
grass v.to.db
  • unit → units : m = meters; ft = feet; km = kilometers; mi = miles. not supported: us-ft
  • layer → map
  • Writes into the map's own attribute table (this mapping names the column length).
Preset: {"option":"length","columns":"length"}
postgis st_length
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • layer → #1
  • Returns 0 for polygons (ST_Perimeter measures outlines); on geography, metres on the spheroid.
qgis native:exportaddgeometrycolumns
  • unit always crs-units. CRS units (metres in a metric CRS); METHOD 2 measures on the ellipsoid.
  • layer → INPUT
  • output → OUTPUT
  • Adds a length field to lines (area and perimeter to polygons).
sf sf::st_length
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • layer → x
  • Returns a units object; 0 for polygons (st_perimeter measures outlines).
shapely shapely.length
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • layer → geometry
  • For polygons, returns the perimeter.
terra terra::perim
  • unit always crs-units. CRS units (metres in a metric CRS); convert afterwards for other units.
  • layer → x
  • For polygons, the perimeter.
turf-js turf.length
  • unit → options.units : m = meters; ft = feet; km = kilometers; mi = miles. not supported: us-ft
  • layer → geojson
  • units defaults to kilometers, so pass the unit even when it is the canonical default (metres); one total for all features.
  • Turf works on GeoJSON in longitude/latitude (WGS 84); data in another CRS must be reprojected first.