Tableau's New Length Spatial Function (Version 2023.2)

Tableau Desktop 2023.2 has introduced a new feature that allows you to easily calculate the length of a line or a multi-line geometry directly within Tableau Desktop. With this feature, you no longer have to aggregate lengths and distances from external sources. The caveat is, you have the spatial object available in Tableau and it only works with line and multi-line strings, if you have that data you are all set.

Let’s walk through how to use this feature and explore some use cases.

Prepping the dataset

To start I have used a US Flight Routes dataset. It's an example that will allow me to show this feature. To begin, the dataset already has the Geographic fields: [Origin Latitude] and [Origin Longitude] as well as [Destination Latitude], and [Destination Longitude] but we need to separate points in order for Tableau to recognize an origin point and destination point. To create these points I used two calculated fields using MAKEPOINT, one for the origin point and the other for the destination point. Take a closer look at the calculations below:

Origin Point Calculation:

Destination Point:

Now that I have my Origin Point and Destination Point, we need to build out the map layers.

1. For the first map layer, let’s drag Latitude to Rows and Longitude to Columns. Then we want to drag Origin Point, Origin Airport, and Destination Airport to Details on the Marks Card.


2.  Next we want to create our second map layer to show  our routes. We have to create our Route Lines using a calculated field (see below), and then we want to drag Route Line onto our map to add a map layer called Route Line. Additionally, we will want to drag Origin Airport and Destination Airport to Details on the Marks Card.

Route Line Calculation:

Origin Point and Route Line Map Layers:

3. Finally, we want to isolate a few routes to utilize the length function. We are going to drag Origin Airport to Filters and select only JFK and drag Destination Airport to Filters and select only LAX and SEA. Now we have two routes visible.

4. Now it's time to use the length function, first, we right-click on the Route Line calculated field we created earlier and create a new calculated field. We will call this new field "Route Length."

5. Now, that we have the length function and quick formatting of the numbers, we can Annotate both routes to show the route lengths in miles. Note that you could also drag this newly created length field onto the label to visualize the route lengths.

Potential Use Cases

This feature is useful but more so for analytics. For instance, the dataset above shows airline routes and corresponding geometries. You can skip the geometry calculations and use the length of each route for various types of analysis. For example, you might want to determine the longest airline route in the US originating in New York, which, in this dataset, is New York to Houston with a route length of 4,272 miles. The accuracy of these calculations will depend on the detail of your geometries, with detailed data resulting in larger file sizes.

Here are some practical use cases:

Route Optimization: Spatial objects using GPS can be brought into Tableau to analyze different routes taken by modes of transport such as buses, airlines, etc. This can be invaluable for optimizing supply chains or other commercial routes, and identifying the most efficient paths.

OR

Boundary Line Calculations: This feature could be used to calculate the length of the outline created from a polygon and can be useful for determining the length of county or district boundaries required around a specific state or visualizing the coverage of a boundary.

I am sure there are many other possible applications of this feature.

Tableau's new Length Spatial Function in version 2023.2 opens up exciting possibilities for spatial analysis. Whether you're optimizing routes, or simply measuring boundaries, this feature simplifies complex calculations.

Author:
Michael Bellamy
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