Work with geo-temporal data
This page documents an earlier version of InfluxDB. InfluxDB v2.1 is the latest stable version. See the equivalent InfluxDB v2.1 documentation: Work with geo-temporal data.
Use the Flux Geo package to filter geo-temporal data and group by geographic location or track.
The Geo package is experimental and subject to change at any time. By using it, you agree to the risks of experimental functions.
To work with geo-temporal data:
-
Import the
experimental/geo
package.import "experimental/geo"
-
Load geo-temporal data. See below for sample geo-temporal data.
-
Do one or more of the following:
- Shape data to work with the Geo package
- Filter data by region (using strict or non-strict filters)
- Group data by area or by track
Shape data to work with the Geo package
Functions in the Flux Geo package require lat and lon fields and an s2_cell_id tag. Rename latitude and longitude fields and generate S2 cell ID tokens.
import "experimental/geo"
sampleGeoData
|> geo.shapeData(latField: "latitude", lonField: "longitude", level: 10)
Filter geo-temporal data by region
Use the geo.filterRows
function to filter geo-temporal data by box-shaped, circular, or polygonal geographic regions.
import "experimental/geo"
sampleGeoData
|> geo.filterRows(
region: {lat: 30.04, lon: 31.23, radius: 200.0},
strict: true
)
Group geo-temporal data
Use the geo.groupByArea()
to group geo-temporal data by area and geo.asTracks()
to group data into tracks or routes.
import "experimental/geo"
sampleGeoData
|> geo.groupByArea(newColumn: "geoArea", level: 5)
|> geo.asTracks(groupBy: ["id"],sortBy: ["_time"])
Sample data
Many of the examples in this section use a sampleGeoData
variable that represents
a sample set of geo-temporal data.
The Bird Migration Sample Data
available on GitHub provides sample geo-temporal data that meets the
requirements of the Flux Geo package.
Load annotated CSV sample data
Use the experimental csv.from()
function
to load the sample bird migration annotated CSV data from GitHub:
import `experimental/csv`
sampleGeoData = csv.from(
url: "https://github.com/influxdata/influxdb2-sample-data/blob/master/bird-migration-data/bird-migration.csv"
)
csv.from(url: ...)
downloads sample data each time you execute the query (~1.3 MB).
If bandwidth is a concern, use to()
to write the data to a bucket, and then query the bucket with from()
.
Write sample data to InfluxDB with line protocol
Use curl
and the influx write
command to write bird migration line protocol to InfluxDB.
Replace db/rp
with your destination bucket:
curl https://raw.githubusercontent.com/influxdata/influxdb2-sample-data/master/bird-migration-data/bird-migration.line --output ./tmp-data
influx write -b db/rp @./tmp-data
rm -f ./tmp-data
Use Flux to query the bird migration data and assign it to the sampleGeoData
variable:
sampleGeoData = from(bucket: "db/rp")
|> range(start: 2019-01-01T00:00:00Z, stop: 2019-12-31T23:59:59Z)
|> filter(fn: (r) => r._measurement == "migration")
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, the following resources are available:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.