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*

  1. import "experimental/geo"
  2. geo.strictFilter(
  3. region: {lat: 40.69335938, lon: -73.30078125, radius: 20.0}
  4. )

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

geo.strictFilter - 图1

Non-strict filtering

geo.strictFilter - 图2

Parameters

region

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

*Data type: Record*

Examples

Filter data in a box-shaped region
  1. import "experimental/geo"
  2. from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> filter(fn: (r) => r._measurement == "example-measurement")
  5. |> geo.toRows()
  6. |> geo.strictFilter(
  7. region: {
  8. minLat: 40.51757813,
  9. maxLat: 40.86914063,
  10. minLon: -73.65234375,
  11. maxLon: -72.94921875
  12. }
  13. )
Filter data in a circular region
  1. import "experimental/geo"
  2. from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> filter(fn: (r) => r._measurement == "example-measurement")
  5. |> geo.toRows()
  6. |> geo.strictFilter(
  7. region: {
  8. lat: 40.69335938,
  9. lon: -73.30078125,
  10. radius: 20.0
  11. }
  12. )
Filter data in a custom polygon region
  1. import "experimental/geo"
  2. from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> filter(fn: (r) => r._measurement == "example-measurement")
  5. |> geo.toRows()
  6. |> geo.strictFilter(
  7. region: {
  8. points: [
  9. {lat: 40.671659, lon: -73.936631},
  10. {lat: 40.706543, lon: -73.749177},
  11. {lat: 40.791333, lon: -73.880327}
  12. ]
  13. }
  14. )

Related articles

functions geo