Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Tool Mastery

Explore a diverse compilation of articles that take an in-depth look at Designer tools.
Become a Tool Master

Learn how you can share your expertise with the Community

LEARN MORE

Tool Mastery | Distance

SydneyF
Alteryx Alumni (Retired)
Created
Distance.png

Thisarticle is part of the Tool Mastery Series, a compilation of Knowledge Base contributions to introduce diverse working examples for Designer Tools. Here we’ll delve into uses of the Distance Tool on our way to mastering the Alteryx Designer:

Often referred to as the first law of geography, Tobler’s first law is this: “everything is related to everything else, but near things are more related than distant things”. The Distance Toolallows us to figure out just how far apart spatial objects are, which is powerful knowledge in a variety of different applications.

Getting Started

The Distance Tool calculates the direct point to point or point to edge distance or even the driving distance between two spatial objects. The Distance Tool will only accept one input, so the spatial objects need to be in the same dataset but in in different fields. The distance will be calculated between your two object fields by row.

You may notice in the help document that the distance tool says its calculating the ellipsoidal distance (specifically WGS84)- all that this means is that the distance formula is taking into account that the Earth is round and not a flat surface.

2017-10-23_9-53-47.png

Use Case 1: Point to Point Distances

The most straight forward distance calculation is a straight distance between two points - say a customer’s home and local businesses.

Let’s say you’re interested in finding how many of your stores are within a 20 mile radius of a list of customers.

You would first append your customer location data to your business location file so that every row in your data set has a column for the customer point, and a separate column for the store point.

2017-10-23_9-55-20.png

In the Distance Tool, we are going to accept the default configuration, which calculates distance “as the crow flies”. We first need to set the two fields you are measuring distance between. The object you select on the left-hand side will be your “source” and on the right, your “destination." Because we are calculating the distance between two point objects, we do not need to set any other parameters in the Output Distance box.

We can also choose to output fields for the direction between the two points, as cardinal direction (N, S, E, W) or in degrees. The default is to output a cardinal direction. You also have the option change your distance units to miles, kilometers, feet, or meters depending on what unit makes the most sense for your analysis. If you are not interested in outputting direction, to optimize processing speed you want to set your larger spatial object as the destination to optimize processing time.

The red box variables need to be set by the user. Variables in the blue boxes are default settings.The red box variables need to be set by the user. Variables in the blue boxes are default settings.

Because unlike crows, customers typically don’t fly, maybe you want to change your distance calculation from linear to driving distance, which considers street data and even traffic data (Alteryx Spatial Data and license required).

2017-10-23_9-54-52.png

When the Output Drivetime & Distance option is selected, you have the option to optimize your routes either by distance or by drive time.


2017-10-23_9-55-38.png

If you have more than one drivetime dataset installed, you will be able to change the dataset used in the dropdown option. If you only have one dataset installed this option will not be available to you.

Time is the default setting for Route optimized by: This finds the fastest driving route between the two points based on your dataset values. This method returns both drivetime and drive distance.

For parity, we will select 20 miles driving distance, which ignores route speed and determines the route with the shortest distance between points. This option does not return drivetime.

Allow Reversed Routing for Optimum Speed option allows the engine to check if you have significantly more “source” points (left side input) than “destination” points. If it finds that this is true, the engine will reverse the two to optimize performance speed. This reversal may result in slightly different drive times due to traffic or one-way streets.

Use Case 2: Point to Polygon

The Distance Tool will also allow you to calculate the distance between a point and a line or a point and a polygon. Your first input (labeled point or centroid source) will always be considered as a point, so if you are interested in finding the distance between two polygons, your first polygon will be converted to a point (the center of the polygon you’re comparing). The distance will be calculated to the edge closest of the line or polygon.

2017-10-23_9-55-57.png

Imagine you’re stranded in the Maui Channel (with Alteryx and spatial data), and you need to swim to the shore of Hawaii. You can create a workflow to figure out how far you need to swim (and in what direction) by bringing in the Hawaii spatial data and your GPS coordinates, appending the two files, and then calculating distance.

2017-10-23_9-56-11.png

When calculating the distance to a line or polygon, you have the option to select the Create the Nearest Interior Point Inside of the Polygon option, which will return the distance to the nearest edge of the destination object. You could use this point to figure out the exact coordinates of your target landing point, if you wanted to use the destination coordinates feature on your GPS instead of your calculated direction and distance.


You’re the green dot, the nearest points in the polygons are blue. It’s only 10 miles further to get to the shore of Maui than The Big island…You’re the green dot, the nearest points in the polygons are blue. It’s only 10 miles further to get to the shore of Maui than The Big island…

For the workflows shown in these use cases, please see the supplementary v11.3 Alteryx package DistanceToolMastery.yxzp.

By now, you should have expert-level proficiency with the Distance Tool! If you can think of a use case we left out, feel free to use the comments section below! Consider yourself a Tool Master already? Let us know atcommunity@alteryx.comif you’d like your creative tool uses to be featured in the Tool Mastery Series.

Stay tuned with our latest posts every#ToolTuesdayby following@alteryxon Twitter! If you want to master all the Designer tools, considersubscribingfor email notifications.

Attachments
Comments
MichaelTNZ
6 - Meteoroid

Thanks for this. I had been wondering about a screen I saw that said it only calculated the straight-line distance, because I saw the options, but wasn't able to try it out to make sure.

Now I know I need to subscribe to a db with drive time data - thanks.