How to create lines in Alteryx (and calculate their distances)

by Jose Valero

Using fundamental Spatial analysis in Alteryx fun an easy! In my previous blog post about Spatial in Alteryx, we covered how to create points (centroids) and calculate the distance between points using the “Distance” tool.

This time we will do something similar, but instead of using points, we will first create lines, connecting all those points, and after, we will calculate the distance of those lines using the “Spatial info” tool.

We will use again the London Bus dataset that you can download here.

In order to create lines, we will first need to create our centroids for each bus stop and then join them using the tool “Poly-Build”, which can be used to create lines or areas (convex hull).

Let’s start!

1.      Prep the data

First, we will prepare the data. Let’s input our dataset using the tool “Input” and looking for the file where you saved it. For our purpose we only care about one route direction, so we will have to filter in “Run” either 1 or 2, it does not matter.

Prep the data

2.       Create centroids (Points)

Let’s create the points for each of our bus stops. We will use the tool “Create Points” and set our Latitude and Longitude.

In this case, we do not have the classics Latitude and Longitude, but instead, we have “Location_Easting” and Location_Northing” (British Latitude and Longitude).

Due to this, we need to set the type of “Projection” to “EPSG:27700”, which is the British National grid.

Create centroids

3.      Create Lines

Let’s now create our lines that will connect each bus stops for each route.

In order to tell Alteryx that we want to join points in each route independently, we need to use the functionality “Group” within the tool. In this case, we want to group by Bus route.

Create Lines

4.      Calculate the distances

Now that we have all Bus routes as lines, we can calculate the distance for each of them using the “Spatial Info” tool.

This tool allows you to ask a lot of question to the polygon created, but for our goal, we will only need to select the box “Length (Kilometres)”

Calculate Distances using “Spatial Info”

And now we can see all the routes distances! We can also see how the Bus N199 has the longest route in London, with 33.82 Km, the same answer that we obtained in the previous blog post using dots distances.

Hope this blog helps you understand the basics of building polygons in Alteryx and feel free to drop a comment!


Jose Valero

Fri 23 Aug 2019

Thu 22 Aug 2019

Wed 21 Aug 2019

Mon 19 Aug 2019