Use Grafana to Visualize Geospatial Data Stored in TimescaleDB
Grafana includes a WorldMap visualization that will help you see geospatial data overlaid atop a map of the world. This can be helpful to understand how data changes based on its location.
To complete this tutorial, you will need a cursory knowledge of the Structured Query Language (SQL). The tutorial will walk you through each SQL command, but it will be helpful if you’ve seen SQL before.
- To start, install TimescaleDB.
Once your installation of TimescaleDB and Grafana are complete, ingest the data found in the tutorial and configure Grafana to connect to that database. Be sure to follow the full tutorial if you’re interested in background on how to use TimescaleDB.
The NYC Taxi Cab data also contains the location of each ride pickup. In the Hello, Timescale! Tutorial, we examined rides that originated near Times Square. Let’s build on that query and visualize rides whose distance traveled was greater than five miles in Manhattan.
We can do this in Grafana using the ‘Worldmap Panel’. We will start by creating a new panel, selecting ‘New Visualization’, and selecting the ‘Worldmap Panel’.
Let’s dissect this query. First, we’re looking to plot rides with visual markers that denote the trip distance. Trips with longer distances will get different visual treatments on our map. We will use the as the value for our plot. We will store this result in the value
field.
In the second and third lines of the SELECT
statement, we are using the pickup_longitude
and pickup_latitude
fields in the database and mapping them to variables longitude
and , respectively.
In the WHERE
clause, we are applying a geospatial boundary to look for trips within 2000m of Times Square.
Finally, in the GROUP BY
clause, we supply the trip_distance
and location variables so that Grafana can plot data properly.
WARNING:This query may take a while, depending on the speed of your Internet connection. This is why we’re using the
LIMIT
statement for demonstration purposes.
Now let’s configure our Worldmap visualization. Select the ‘Visualization’ tab in the far left of the Grafana user interface. You’ll see options for ‘Map Visual Options’, ‘Map Data Options’, and more.
In the ‘Map Visual Options’, set the ‘Min Circle Size’ to 1 and the ‘Max Circle Size’ to 5.
In the ‘Threshold Options’ set the ‘Thresholds’ to ‘2,5,10’. This will auto configure a set of colors. Any plot whose value
is below 2 will be a color, any value
between 2 and 5 will be another color, any value
between 5 and 10 will be a third color, and any value
over 10 will be a fourth color.
Your configuration should look like this:
At this point, data should be flowing into our Worldmap visualization, like so:
Complete your Grafana knowledge by following .