Documentation

geo.ST_LineString() function

The geo.ST_LineString() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

The geo.ST_LineString() function converts a series of geographic points into linestring. Group data into meaningful, ordered paths to before converting to linestring. Rows in each table must have lat and lon columns. Output tables contain a single row with a st_linestring column containing the resulting linestring.

Function type: Aggregate

import "experimental/geo"

geo.ST_LineString()

Examples

Convert a series of geographic points into linestring

Input data
_timeidlonlat
2020-01-01T00:00:00Za213b39.751514.01433
2020-01-02T00:00:00Za213b38.352713.9228
2020-01-03T00:00:00Za213b36.997815.08433
import "experimental/geo"

data
  |> geo.ST_LineString()
Output data
idst_linestring
a213b39.7515 14.01433, 38.3527 13.9228, 36.9978 15.08433

Function definition

ST_LineString = (tables=<-) =>
  tables
    |> reduce(fn: (r, accumulator) => ({
        __linestring: accumulator.__linestring + (if accumulator.__count > 0 then ", " else "") + string(v: r.lat) + " " + string(v: r.lon),
        __count: accumulator.__count + 1
      }), identity: {
        __linestring: "",
        __count: 0
      }
    )
    |> rename(columns: {__linestring: "st_linestring"})

New! Cloud or OSS?