Spatial in Tableau

This week we learned about several spatial functions within Tableau including Makepoint, Makeline, and Distance. In this blog post, we will explore these functions and understand their practical applications.

We will be using the following data from the table below for demonstration. Within this dataset, you will find 10 flight records encompassing both the departure and arrival airports, along with the corresponding latitude and longitude coordinates of the airports

MAKEPOINT

With a MAKEPOINT() function we can create spatial object or point for the origin airport and destination airport with the following calculation.

Point: Origin Airport

MAKEPOINT([Origin Latitude], [Origin Longitude])

Point: Destination Airport

MAKEPOINT([Destination Latitude], [Destination Longitude])

Now, let's drag the 'Point: Origin Airport' to the view to create points of the Origin Airport on the map. Then, drag 'Origin Airport' in the 'Detail' mark to create individual points. Change the visualization type into 'Circle', change the color to 'Black', and adjust the size.

Now, to create the destination points on the map we cannot use the same layer as the latitude and longitude has already been used in the view. However, we can use 'Mask Layer' to create a layer of destination points in the same view.

Drag the 'Point: Destination Airport' in the view and drop it into 'Mask Layer' as shown in the screenshot below.

This creates a second layer in the view and an additional mark for 'Point: Destination' appears on the marks shelf. Now, drag 'Destination Airport' in the 'Detail' in the new mark to create individual points. Change the visualization type into 'Circle', change the color to 'Red', and adjust the size. As a result, we have created the origin airports (black circles) and the destination airports (red circles) as shown in the screenshot below.

MAKELINE

With the MAKELINE() function we can create the line or path between the two points. In our case, we are creating a route path between the origin and destination airport.

Before creating the line let us give the name to the route by concatenating the 'Origin Airport' and 'Destination Airport' by using the following calculation in a calculation field.

Now, let's create a line between the origin and destination airport using the MAKELINE([start], [end]) function in a calculated field as shown in the screenshot below.

Like in the process we used to create the destination airports, we need to use a third 'Mask Layer' to create the lines on the view.

Drag 'Line: Route' into the view and drop it into the 'Mask Layer' as shown in the screenshot below.

This creates a third layer in the view and an additional mark for 'Line: Route' appears on the marks shelf. Now, drag 'Route Name' in the 'Detail' on the new mark to create individual lines for the route. A line is created in the view for each route as shown in the screenshot below.

DISTANCE

With the DISTANCE() function, we can calculate the distance between two points either in miles or kilometers. Let's calculate the distance in miles between origin and destination airports in a calculated field as shown in the screenshot below.

Now, drag the 'Distance' field on the 'Tooltips' of the 'Line: Route' mark shelf. As a result, you can see the distance between origin and destination airports can be viewed in the tooltip.

Author:
Nitesh Shrestha
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab