Skip to content

line

Utilities for validating geographic lines and computing their length.

A line is represented as an array of geographic positions in [longitude, latitude] order.

isValidLine

Signature

js
isValidLine (line)

Description

Check whether a line is valid.

A valid line is an array containing at least two valid geographic positions.

Parameters

NameTypeRequiredDescription
lineArrayyesThe line to validate

Returns

TypeDescription
booleantrue if the line is valid, otherwise false

Examples

js
isValidLine([[2.3522, 48.8566], [4.8357, 45.7640]]) // true
isValidLine([[2.3522, 48.8566]])                    // false
isValidLine([])                                     // false

lineLength

Signature

js
lineLength (line)

Description

Compute the total geodesic length of a line by summing the distances between consecutive positions.

Parameters

NameTypeRequiredDescription
lineArrayyesThe line whose length is computed

Returns

TypeDescription
numberThe total length of the line in meters

Examples

js
lineLength([
  [2.3522, 48.8566],
  [4.8357, 45.7640]
])
// approximately 392000