docs-v2/content/flux/v0/stdlib/experimental/geo/totaldistance.md

4.1 KiB

title description menu weight flux/v0/tags introduced
geo.totalDistance() function `geo.totalDistance()` calculates the total distance covered by subsequent points in each input table.
flux_v0_ref
name parent identifier
geo.totalDistance experimental/geo experimental/geo/totalDistance
201
transformations
geotemporal
aggregates
0.192.0

geo.totalDistance() calculates the total distance covered by subsequent points in each input table.

Each row must contain lat (latitude) and lon (longitude) columns that represent the geographic coordinates of the point. Row sort order determines the order in which distance between points is calculated. Use the geo.units option to specify the unit of distance to return (default is km).

Function type signature
(<-tables: stream[{B with lon: float, lat: float}], ?outputColumn: A) => stream[C] where C: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

outputColumn

Total distance output column. Default is _value.

tables

Input data. Default is piped-forward data (<-).

Examples

Return the total distance travelled per input table

import "experimental/geo"

data
    |> geo.totalDistance()

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

*id _time lat lon
ABC1 2022-01-01T00:00:00Z 85.1 42.2
ABC1 2022-01-01T01:00:00Z 71.3 50.8
ABC1 2022-01-01T02:00:00Z 63.1 62.3
ABC1 2022-01-01T03:00:00Z 50.6 74.9
*id _time lat lon
DEF2 2022-01-01T00:00:00Z -10.8 -12.2
DEF2 2022-01-01T01:00:00Z -16.3 -0.8
DEF2 2022-01-01T02:00:00Z -23.2 12.3
DEF2 2022-01-01T03:00:00Z -30.4 24.9

Output data

*id _value
ABC1 4157.144498077607
*id _value
DEF2 4428.129653320098

{{% /expand %}} {{< /expand-wrapper >}}

Return the total distance travelled in miles

import "experimental/geo"

option geo.units = {distance: "mile"}

data
    |> geo.totalDistance()

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

*id _time lat lon
ABC1 2022-01-01T00:00:00Z 85.1 42.2
ABC1 2022-01-01T01:00:00Z 71.3 50.8
ABC1 2022-01-01T02:00:00Z 63.1 62.3
ABC1 2022-01-01T03:00:00Z 50.6 74.9
*id _time lat lon
DEF2 2022-01-01T00:00:00Z -10.8 -12.2
DEF2 2022-01-01T01:00:00Z -16.3 -0.8
DEF2 2022-01-01T02:00:00Z -23.2 12.3
DEF2 2022-01-01T03:00:00Z -30.4 24.9

Output data

*id _value
ABC1 2583.129833073356
*id _value
DEF2 2751.5122020650015

{{% /expand %}} {{< /expand-wrapper >}}