content/flux/v0/stdlib/experimental/geo/totaldistance.md
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).
(<-tables: stream[{B with lon: float, lat: float}], ?outputColumn: A) => stream[C] where C: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Total distance output column. Default is _value.
Input data. Default is piped-forward data (<-).
import "experimental/geo"
data
|> geo.totalDistance()
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *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 |
| *id | _value |
|---|---|
| ABC1 | 4157.144498077607 |
| *id | _value |
|---|---|
| DEF2 | 4428.129653320098 |
{{% /expand %}} {{< /expand-wrapper >}}
import "experimental/geo"
option geo.units = {distance: "mile"}
data
|> geo.totalDistance()
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| *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 |
| *id | _value |
|---|---|
| ABC1 | 2583.129833073356 |
| *id | _value |
|---|---|
| DEF2 | 2751.5122020650015 |
{{% /expand %}} {{< /expand-wrapper >}}