Filter geo-temporal data by region

Use the geo.filterRows function to filter geo-temporal data by geographic region:

  1. Define a geographic region
  2. Use strict or non-strict filtering

The following example uses the sample bird migration data and queries data points within 200km of Cairo, Egypt:

  1. import "experimental/geo"
  2. sampleGeoData
  3. |> geo.filterRows(
  4. region: {lat: 30.04, lon: 31.23, radius: 200.0},
  5. strict: true
  6. )

Define a geographic region

Many functions in the Geo package filter data based on geographic region. Define a geographic region using one of the 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. }

polygon

Define a polygonal region with a record containing the latitude and longitude for each point in the polygon:

  • 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. }

Strict and non-strict filtering

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

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

Strict filtering is less performant, but more accurate than non-strict filtering.

S2 grid cell
Filter region
Returned point

Strict filtering

Filter by region - 图1

Non-strict filtering

Filter by region - 图2

Related articles