As you all probably know doing analyses using mapping in Tableau is relatively simple. Lately, Tableau added some new functionalities called 'Spatial Functions' by which you can really improve your mapping analyses. And most importantly, they’re still easy to use!
These functions were initially introduced in version 2019.2 with the MAKEPOINT and MAKELINE functions and were expanded in 2019.3 with the DISTANCE function. For the upcoming version 2020.1 a new function will be released which I already tested out at the end of this blog post 😎.
These functions can be found when you create a calculated field and select 'Spatial' in the drop-down menu. The MAKEPOINT function creates a point that is based on the latitude and longitude of a location. These points, also called spatial objects, can be used for the MAKELINE and the DISTANCE function afterwards. These two functions need two points as an input, a starting and an ending point.
Spatial functions in a calculated field
When dragged into the view, the spatial fields created by MAKEPOINT and MAKELINE are automatically aggregated with the COLLECT function. This function can be used with spatial fields only. You can always disaggregate these fields such as shown in the first example below.
One thing to note is that Tableau doesn't allow the measures Latitude (generated) and Longitude (generated) to be used in a calculated field because these are no real data fields (they are generated on the fly by Tableau). In order to use latitudes and longitudes with a spatial function they have to be present in the data set.
In this blog post, two use cases will be given for the use of spatial functions. The first one will cover the different clients that are served by different warehouses in the port of Antwerp. Here, the use of the MAKEPOINT function will be shown. The second example will cover the top 5 domestic flight routes in the USA and will mainly focus on the MAKELINE and the DISTANCE function.
Warehouses and their clients in the port of Antwerp
In this example, we have a data source with the latitude and longitude of two warehouses in the port of Antwerp (second largest seaport in Europe in terms of freight volumes, based in Belgium). Each of these warehouses provides the same materials to their five clients in the area. From these clients the latitude and longitude are also in the data source. Like mentioned previously we need these latitudes and longitudes from the database itself and not the generated ones from Tableau. Here are the steps:
Here you can see all the steps in one animation
Small conclusion: maybe the warehouse that is delivering client 4 should be reconsidered... 🤔
A downloadable version of this workbook can be found here.
In this example we have a database that consists of all the origin airports with all its connected destination airports in the world. Each row in the database represents a flight route from one airport to another. The latitude and longitude from both origin and destination airports are included in the database. Here are the steps:
A downloadable version of this workbook can be found here.
Using these spatial functions is actually very straightforward once you have a data source with the location coordinates in it. But having these data sources with the correct coordinates from all your clients, suppliers, etc will be the biggest challenge.
*Amazed by the spatial functions*
In Tableau Desktop 2020.1 a new spatial function will be released named the BUFFER function. This will generate a buffer around a given distance from a point. Check it out here. I already tried it with the beta version to see which clients fall within a buffer of 5 km from each warehouse.
Buffer of 5km from each warehouse
Jochem Brinckman | Analytics consultant