TL;DR Geo-Temporal Data and InfluxDB
Susannah Brodnitz /
Product, Use Cases, Developer
Jul 07, 2022
Geo-temporal data has both location and time. It’s used for all sorts of applications, from tracking shipments, to predicting weather patterns, to building fitness apps. It’s powerful because it lets you know where and when events happen, so you can understand them better and connect them with other events.
Time series data can be big and unwieldy without the proper tools, like InfluxDB. When you add in the spatial dimensions of geo-temporal data, things can quickly get out of hand. If you don’t have the right tools, code for analyzing geo-temporal data can take a very long time to run and make your project a lot less efficient. InfluxDB’s geo-temporal package is designed to handle this kind of data, so you can store and query it with much faster results.
The power of S2 geometry
Geo-temporal tools in InfluxDB get a lot of their power from their use of S2 geometry. S2 geometry is a system of dividing the Earth into cells. It’s based on a spherical projection of the earth instead of a flat one, which eliminates gaps or overlapping areas. Knowing what cell(s) two points are in can give you a good estimate of how far apart they are without doing computationally expensive trigonometry to calculate distance from latitude and longitude. You can specify a level for how big the cells are to decide how precise you want to be. This can range anywhere from a hemisphere down to a few millimeters depending on what you need.
To start, you write data to InfluxDB with latitude and longitude as fields, along with your other data and whatever tags you may need. Flux’s geo package has a function called shapeData which takes latitude and longitude data and converts it to an S2 cell ID.
There are countless things you can do once your data has an S2 cell ID. One example is to use the filterRows function to subset your data to a region you choose. This can be a box, circle, or any arbitrary polygon. If you were trying to track when a truck pulls into a loading area, you could specify that region and set up alerts. Using S2 cells instead of trigonometry makes it easier to program real-time applications.
When you have the huge volumes of data inherent to time series analysis, the time saved with S2 calculations really adds up. Our documentation has more information about different geo-temporal functions included in Flux.
Watch our three part video series on geo-temporal data to learn more.
Part 1 has an introduction to geo-temporal data.
Part 2 goes into S2 geometry.
Part 3 has some example queries.