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*

  1. import "experimental/geo"
  2. 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
  1. import "experimental/geo"
  2. data
  3. |> geo.ST_LineString()
Output data
idst_linestring
a213b39.7515 14.01433, 38.3527 13.9228, 36.9978 15.08433

Function definition

  1. ST_LineString = (tables=<-) =>
  2. tables
  3. |> reduce(fn: (r, accumulator) => ({
  4. __linestring: accumulator.__linestring + (if accumulator.__count > 0 then ", " else "") + string(v: r.lat) + " " + string(v: r.lon),
  5. __count: accumulator.__count + 1
  6. }), identity: {
  7. __linestring: "",
  8. __count: 0
  9. }
  10. )
  11. |> rename(columns: {__linestring: "st_linestring"})

Related articles

functions geo GIS