Tableau 2019.3 brought with it some improvements to spatial calculations. In this blog I want to focus on the makepoint, makeline and distance functions. To do this I will use a data set that details the various flight paths from Cincinnati airport. Here is a snapshot of the data:
As you can see, each row contains a unique destination airport, and their respective latitude and longitude. Note that every row for origin latitude and origin longitude has the same value, because Cincinnati ariport is always the origin in this dataset.
Makepoint and Makeline Calculation
Looking at this data, it is possible to create a flight path for each row. The key is that we have a latitude and longitude for both the origin and destination. Using spatial calculations in Tableau we can create origin and destination points, and then use them as the start and end points to make a line (more specifically, a flight path). We can actually combine the makepoint and makeline functions into one calculated field, as shown below:
To create the view, start by bringing destination latitude to rows and destination longitude to columns (make sure the aggregation is an average). Then simply drag the flight path calculation to the level of detail. An optional step is to bring destination longitude to columns again and create a dual axis. On the second axis, bring destination airport to the level of detail and change the mark type to a circle.
If we want to calculate the distance between the origin and destination, we need to use the distance function instead of the makeline function, as well as select the unit of measurement. Then we can use this calculation as a label. Here it is:
The view should now look something like this:
And there you have it! As you can see it’s now relatively easy to create spatial calculations in Tableau. However, there is more we can do by editing our calculation slightly.
Parameterised Spatial Calculation
We can parameterise the flight path calculation to create a more interactive experience for the user. Lets say we wanted to see all possible flight paths from any given airport, i.e. we want to dynamically choose the origin airport. To do this, we first have to create two parameters: one for chosen latitude and one for chosen longitude. Make sure the data type is float and allow all values. Then its just a case of substituting origin latitude and origin longitude with chosen latitude and chosen longitude respectively in our calculation, as shown below:
Now we need to set up two parameter actions: one change the chosen latitude and one to change the chosen longitude. Here is the configuration for the chosen longitude parameter action:
The configuration for the chosen latitude parameter action is similar, just select the corresponding target parameter and field. Now look what we’ve created:
As you can see in the above GIF, spatial calculations are powerful yet quite easy to create, and they are always evolving with every Tableau update. In fact, at the Tableau Conference in Las Vegas last week, more spatial functions were unveiled. Here is a link to the live stream. It details a buffer function that should be incorporated some time next year. Nevertheless, I hope you found this blog to be useful!