InfluxDB Docs

geo.strictFilter() function

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

The geo.strictFilter() function filters data by latitude and longitude in a specified region. This filter is more strict than geo.gridFilter(), but for the best performance, use geo.strictFilter() after geo.gridFilter(). See Strict and non-strict filtering below.

Function type: Transformation

import "experimental/geo"

geo.strictFilter(
  region: {lat: 40.69335938, lon: -73.30078125, radius: 20.0}
)

geo.strictFilter() requires lat and lon columns in each row. Use geo.toRows() to pivot lat and lon fields into each row before using geo.strictFilter().

Strict and non-strict filtering

In most cases, the specified geographic region does not perfectly align with S2 grid cells.

  • Strict filtering returns only points inside the specified region.
  • Non-strict filtering returns points that may be outside of the specified region but inside S2 grid cells partially covered by the region.

S2 grid cell
Filter region
Returned point

Strict filtering

Non-strict filtering

Parameters

region

The region containing the desired data points. Specify object properties for the shape. See Region definitions.

Data type: Object

Examples

Filter data in a box-shaped region
import "experimental/geo"

from(bucket: "example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "example-measurement")
  |> geo.toRows()
  |> geo.strictFilter(
    region: {
      minLat: 40.51757813,
      maxLat: 40.86914063,
      minLon: -73.65234375,
      maxLon: -72.94921875
    }
  )
Filter data in a circular region
import "experimental/geo"

from(bucket: "example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "example-measurement")
  |> geo.toRows()
  |> geo.strictFilter(
    region: {
      lat: 40.69335938,
      lon: -73.30078125,
      radius: 20.0
    }
  )
Filter data in a custom polygon region
import "experimental/geo"

from(bucket: "example-bucket")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "example-measurement")
  |> geo.toRows()
  |> geo.strictFilter(
    region: {
      points: [
        {lat: 40.671659, lon: -73.936631},
        {lat: 40.706543, lon: -73.749177},
        {lat: 40.791333, lon: -73.880327}
      ]
    }
  )

New! Cloud or OSS?