Flux Geo package

The Geo package is experimental and subject to change at any time. By using this package, you accept the risks of experimental functions.

The Flux Geo package provides tools for working with geo-temporal data, such as filtering and grouping by geographic location. Import the experimental/geo package:

  1. import "experimental/geo"

Geo schema requirements

The Geo package uses the Go implementation of the S2 Geometry Library. Functions in the Geo package require the following:

  • a s2_cell_id tag containing an S2 cell ID as a token (more information below)
  • a lat field containing the latitude in decimal degrees (WGS 84)
  • a lon field containing the longitude in decimal degrees (WGS 84)

Schema recommendations

  • a tag that identifies the data source
  • a tag that identifies the point type (for example: start, stop, via)
  • a field that identifies the track or route (for example: id, tid)
Examples of geo-temporal line protocol
  1. taxi,pt=start,s2_cell_id=89c2594 tip=3.75,dist=14.3,lat=40.744614,lon=-73.979424,tid=1572566401123234345i 1572566401947779410
  2. bike,id=biker-007,pt=via,s2_cell_id=89c25dc lat=40.753944,lon=-73.992035,tid=1572588100i 1572567115

S2 Cell IDs

Use latitude and longitude with the s2.CellID.ToToken endpoint of the S2 Geometry Library to generate s2_cell_id tags. Specify your S2 Cell ID level.

To filter more quickly, use higher S2 Cell ID levels, but know that that higher levels increase series cardinality.

Language-specific implementations of the S2 Geometry Library provide methods for generating S2 Cell ID tokens. For example:

Add S2 Cell IDs to existing geo-temporal data

Use the geo.shapeData() function to add s2_cell_id tags to data that includes fields with latitude and longitude values.

  1. //...
  2. |> shapeData(
  3. latField: "latitude",
  4. lonField: "longitude",
  5. level: 10
  6. )

Latitude and longitude values

Flux supports latitude and longitude values in decimal degrees (WGS 84).

CoordinateMinimumMaximum
Latitude-90.090.0
Longitude-180.0180.0

Region definitions

Many functions in the Geo package filter data based on geographic region. Define geographic regions using the following shapes:

box

Define a box-shaped region by specifying a record containing the following properties:

  • minLat: minimum latitude in decimal degrees (WGS 84) (Float)
  • maxLat: maximum latitude in decimal degrees (WGS 84) (Float)
  • minLon: minimum longitude in decimal degrees (WGS 84) (Float)
  • maxLon: maximum longitude in decimal degrees (WGS 84) (Float)
Example box-shaped region
  1. {
  2. minLat: 40.51757813,
  3. maxLat: 40.86914063,
  4. minLon: -73.65234375,
  5. maxLon: -72.94921875
  6. }

circle

Define a circular region by specifying a record containing the following properties:

  • lat: latitude of the circle center in decimal degrees (WGS 84) (Float)
  • lon: longitude of the circle center in decimal degrees (WGS 84) (Float)
  • radius: radius of the circle in kilometers (km) (Float)
Example circular region
  1. {
  2. lat: 40.69335938,
  3. lon: -73.30078125,
  4. radius: 20.0
  5. }

point

Define a point region by specifying a record containing the following properties:

  • lat: latitude in decimal degrees (WGS 84) (Float)
  • lon: longitude in decimal degrees (WGS 84) (Float)
Example point region
  1. {
  2. lat: 40.671659,
  3. lon: -73.936631
  4. }

polygon

Define a custom polygon region using a record containing the following properties:

  • points: points that define the custom polygon (Array of records)

    Define each point with a record containing the following properties:

    • lat: latitude in decimal degrees (WGS 84) (Float)
    • lon: longitude in decimal degrees (WGS 84) (Float)
Example polygonal region
  1. {
  2. points: [
  3. {lat: 40.671659, lon: -73.936631},
  4. {lat: 40.706543, lon: -73.749177},
  5. {lat: 40.791333, lon: -73.880327}
  6. ]
  7. }

GIS geometry definitions

Many functions in the Geo package manipulate data based on geographic information system (GIS) data. Define GIS geometry using the following:

linestring

Define a geographic linestring path using a record containing the following properties:

  • linestring: string containing comma-separated longitude and latitude coordinate pairs (lon lat,):

    1. {
    2. linestring: "39.7515 14.01433, 38.3527 13.9228, 36.9978 15.08433"
    3. }

Distance units

The Geo package supports the following units of measurement for distance:

  • m - meters
  • km - kilometers (default)
  • mile - miles

Define distance units

Use the Geo package units option to define custom units of measurement:

  1. import "experimental/geo"
  2. option geo.units = {distance: "mile"}

Related articles

functions package geo