Tableau is a very flexible data visualisation tool. It allows us to play around with geospatial data to make interactive maps and find insights from spatial relationships. This blog will explain the process of finding nearby geospatial points in Tableau step-by-step, a very useful technique for spatial analysis!

Before we start, we need to understand what a geospatial data type is in Tableau. We have Latitude and Longitude coordinates, but they are simply decimal numbers (“floating” data type). We can then plot the latitude and longitude coordinates in the Tableau in-built map function. This plot/point will then become a “Spatial” data type. We can also create a polygon spatial area surrounding that point with a “buffer” function in Tableau. Let’s get into the step-by-step process of how we can achieve this! In this blog, we will use the sample data from this exercise from “Workout Wednesday”.

Step 1: Create spatial data (points and surrounding areas) from the latitude and longitude coordinates.

Create a calculated field with this formula;

MAKEPOINT( [Latitude], [Longitude] )

To create polygon area surrounding this point, create another calculated field with this formula;

BUFFER( [Spatial point], Distance in number, ‘unit of measure’ )

For instance using the Workout Wednesday example, I have this formula;

 

Now to spice this up, let us try to find other points (from another dataset) that are still within the buffer area we just created. To do so, we need to join the dataset first!

Step 2: Joining datasets using spatial formula.

Go to the datasource page, on the datapane, select Add and ‘More’ under the ‘To a file’ to add the second dataset.

 

After fetching the second dataset, double click the starting table in the canvas.

 

Drag the second dataset beside the first dataset to join them.

 

Click on the join icon (overlapping circles in the middle of the datasets), keep the inner join (because we are interested in the intersection of the first dataset’s surrounding areas and the points from second dataset). Now we need to setup the spatial data connection between these two sets. But we do not have the spatial data in the original datasets! (the calculated fields created in step 1 were Tableau artifacts and were not created in the datasource itself). So we need to recreate the buffer area for the first dataset (the hotel buffer area in this example), and points for the second dataset (pub points in this example). Click on the dropdown arrow in the box shown below to create the spatial data, then select ‘create join calculation’.

 

Now we need to recreate our buffer area, just like in step 1, and then create the spatial points for our second dataset.

 

 

 

 

 

Lastly, select ‘intersect’ as the relationship type.

 

Now that our joined data is finally ready, we can then create the spatial points for the second dataset in Tableau just like in step 1. In this example, I created points for the pubs; MAKEPOINT([Pubs Lat], [Pubs Lon]).

 

Step 3: Visualise them.

On the datapane, click on the spatial points created in step one to generate the map. As of now, Tableau treats all of these points as one entity, to separate them, drag the ID of each point into the detail card. In this example, I double clicked “Hotel spatial points” to generate the map, then I dragged the ‘Hotel name’ into details.

 

Next we need to add the ‘buffer’ area to the map. Drag the created buffer field into the canvas ‘add layer’. Again, to separate them from being one entity, drag the ID field into the details (in this example, it is still the hotel name).

 

We can add the second dataset created field (in my example, the pub points) as well by dragging it into the ‘add layer’, and then drag the ID field into the details (Pub name in this example).

Step 4: Format them.

We can change the size, colour and opacity, as well as the label by playing with the options in the marks card there. We can also change the map background by going into the Map menu option, then select background maps, and select any option you desire there.

 

And this is my final product!

With Tableau’s capability to handle geospatial data, we can perform complex spatial analyses easily and enhance our visualisation to identify patterns. Hope this helps and happy vizzing!

 

The Data School
Author: The Data School