Spatial Analytics in Alteryx (Part 2)

Continue to the first part of Spatial Analytics in Alteryx, in this second part, I am going to share about other Spatial tools in Alteryx. When you first hear about Spatial data, what will you do with that data? To me, I think about finding the distance between 2 points or finding the short distance to go from one point to another point. It happens to me every day when I go from my home to the office. Alteryx includes all the Spatial tools to help us find the distance, area, finding the nearest path, or finding the intersection of 2 areas and more.

I am going to share some features to solve some problems in daily life. In this blog, I am going to share about:

1/ Finding the distance between 2 points or from one point to a Line/ Polygon Object
2/ Finding the nearest distance
3/ Combine/ Cut 2 Polygon Objects
* Combine Objects
* Cut the 1st Object from the 2nd Object
* Cut the 2nd Object from the 1st Object
* Create Intersection Object
* Create Inverse Intersection Object


1/ Finding the distance between 2 points or from one point to a Line or Polygon

There are many ways to calculate the distance between 2 points depending on the case you are working on. In some cases, the dataset includes 2 Point Object fields or 1 Point Object field in one dataset and a Point Object field in another dataset.

The dataset already included 2 Point Object fields, so I only need to find the distance between 2 points on each row. If 2 Point Object fields are not in the same dataset I will use the Distance tool to find the distance between 2 Point Objects on each row.

Image 1: A dataset includes 2 Point Object fields

In Image 1, I have a dataset with a Customer Point field and a Store Point field. Those fields are Point Object type. If your dataset does not have the Point Object type but you have the longitude and latitude coordinates, you should use the Create Point tool to create the Point Object. I showed how to create a Point Object in Part 1. Now, you only need to drag the Distance tool to connect with the dataset.

Image 2: Use the Distance tool to calculate the distance between 2 points

In the Configuration window, for the Spatial Object Fields, I choose Customer Point in the Point or Centroid Source in the left dropdown menu and Store Point in Point, Line, or Polygon Destination in the right dropdown menu. Then, in the Output Distance part, I check the box to output the distance. There are many options below, I will mention them later in another case. Finally, in the Units dropdown menu, I choose Miles to output the distance in miles. You can change it to kilometers, feet, and meters. Then run the workflow (Image 2).

In the result window, there is a new column called DistanceMiles. That is the distance in miles between Customer Point and Store Point. However, there are more options to show more details by choosing options Output Cardinal Direction (North, West, East, South) or the Output Direction in Degrees (Image 3).

Image 3: Showing Direction and Direction in Degrees

You can also do the same way from one point to a Line or a Polygon. Note that, if you choose to find the distance between a Poing and a Polygon, you should pay attention to the option "When a point is inside a polygon".

2/ Finding the nearest distance

If you have a dataset with multiple Point Objects and another dataset with multiple Point Objects, you want to find the nearest distance from the origin point to the destination point. You can use the Nearest Distance tool to find which point is the nearest point to the other point.

For example, I have 2 datasets. One is the Airport dataset, another is the University dataset. I got 2 of those datasets from https://www.latlong.net/. I would like to find out which university is near the airport where the distance should be less than 50 miles.

Image 4: Get 2 example datasets from Latlong.net

After getting 2 datasets with longitude and latitude values, I used the Create Point tool to create Point Objects. Then, I drag the Find Nearest tool from the Spatial palette. The Create Point tool from the Airport data will connect to the T (Target) anchor and connect the Create Point tool from the University data to the U (Universe) anchor.

In the configuration window, I choose the Centroid from the Airport data for the Target Spatial Object field and the Centroid from the University data for the Universe Spatial Object field. Next, I need to specify how many universities are near the airport (I specified 2). Then, specify the maximum distance from the airport to the university (I set 50 miles). (Image 5)

Image 5: Use the Find Nearest tool to find which objects are near another object

In the result window, you can see there are 3 new columns (FindNearestRank, DistanceMiles, and Direction). The FindNearestRank field will rank which Universities are near the airport. Besides that, the DistanceMiles will show the distance from the airport to that university in miles (the shortest distance from the target will be the 1st rank).

3/ Combine or Cut 2 Polygon Objects

This feature is the same as joining 2 datasets together. You can combine 2 Polygon Objects, get only the first Object (not including the matching area and the second Object), get only the second Object (not including the matching area and the first Object), get the matching area, get both Objects (not including the matching area). In this blog, I will walk through all of those features. Those features are the same as you join datasets. I have a blog about all joining types, you can take a look at it here.

First of all, I prepared 2 datasets (Hospital data and University data) from the latlong.net page. (Image 6)

Image 6: Prepare 2 datasets including the latitude and longitude values

I used the Create Point tool for each dataset to create the Point Object. Then, I join both datasets together on the State by using the Join tool. In the next step, I use the Trade Area tool to create a Polygon (a circle) with the center point the the Point Object, and the specified radius. I used one Trade Area tool for a Hospital Centroid with a radius of 20 miles and another for a University Centroid with a radius of 15 miles. (Image 7)

Image 7: Create a Polygon Object for each Point with a specified radius

I drag the Browse tool to connect to the Trade Area tool. In the configuration window, the map will show up. The hospital Polygon Object is a Blue circle with a red center point while the university Polygon Object is a Green circle with a green center point (Image 8).

Image 8: Showing Hospital Polygon Objects and University Polygon Objects on Browse tool

Then, I use the Select tool to remove some unnecessary fields (Long, Lat, and radius size).

  • Combine Objects (same as Union datasets)

In Image 8, you can see the Hospital Polygon Objects and University Polygon Objects are distinguished by color. Combining Objects means I group the Hospital Objects and University Objects if they are overlapping.

To do that, I drag the Spatial Process tool to connect to the previous tool. In the Configuration window, I chose the first and second Spatial fields. In the Action part, I chose to Combine Objects. The visualization is easy to understand when you combine the first (#1) and second (#2) Objects, it will return only 1 #3 Object (Image 9).

Image 9: Use the Spatial Process tool to combine 2 Polygon Objects

I connect with the Browse tool and see the result in the Configuration window. In Image 10, there is only 1 Polygon Object after combining Hospital and University Polygon Objects. Now, there is only 1 red object.

Image 10: Result after combining 2 Polygon Objects
  • Cut 1st from 2nd (same as Right Exclusive Join datasets)

In this option, the result only returns the second Object and removes all areas belonging to the first Object (including the matching area).

Image 11: Cut 1st From 2nd in the Configuration window

In Image 12, I cut the hospital Polygon Objects out of the University Polygon Objects. I only keep the second Polygon Object. However, if the University Polygon Objects are included in the Hospital Polygon Objects, it will return Null (Record 3 in Image 11).

Image 12: Cut the first Polygon Object from the second Polygon Object

In Image 13, the result clearly shows how it transformed. The blue circle of the Hospital Polygon Object was removed; it only keeps the University Polygon Object. However, I marked a question mark in the above circle.

That University Polygon Object is inside the Hospital Polygon Object, why does it still exist there?

Image 13: Before and after cutting the first Object from the second Object

To answer that question, let's look at Image 8 by zooming out a little bit. There are 4 data rows related to the Washington State. There are a total of 2 Hospital Polygon Objects and 2 University Polygon Objects. I used the Join tool to join all Polygon Objects in that State together. It means that 1 Hospital Object will join with 2 different University Objects => so we have 4 rows for WA State.

In Image 14, you can see I am highlighting the first row. That is Legacy Salmon Creek Medical Center (Blue Highlight Circle) and the University of Washington (Yellow highlight circle). Those 2 Polygon Objects are far away and have no overlapping between those Objects, so the yellow circle for the University of Washington still shows in the result (Image 14).

Image 14: The second Object does not overlap with the first Object
  • Cut the second Object from the first Object (same as Left Exclusive Join datasets)

Opposite to the previous option, the result will return only the Left Polygon Object but not include the second Objects and the matching area (Image 15).

Image 15: Cut 2nd from 1st in the Configuration window

In Image 16, if we compare the Blue Hospital Circle with the other 2 green University circles, the result will return the Blue circle (red highlight area) without the matching area. There is another red circle near Portland which is also a Hospital Polygon Object.

Image 16: Cut 2nd Object from the 1st Object
  • Create Intersection Object (same as Inner Join datasets)

For this option, the result will return only the matching area between 2 Polygon Objects (Image 17). This option is similar to the Inner Join when you join 2 datasets together. The result also returns the matching data between 2 datasets.

Image 17: Create an Intersection Object in the Configuration window

In Image 18, there are 2 Null rows because there is 1 Hospital Polygon Object below that does not overlap with the other 2 University Polygon Objects. For the Hospital Polygon Object (blue circle), it overlap with the other 2 University Polygon Objects. One University Polygon Object is totally inside the Hospital Polygon Object, so the result is the whole University Polygon Object. Another University Polygon Object only has a small piece overlap with the Hospital Object, so the result returns only that small piece.

Image 18: The result of creating an Intersection Object
  • Create Inverse Intersection Object (same as Full Outer Exclusive Join Datasets)

Opposite to creating Intersection Object, this option returns both the first and second Polygon Objects but does not include the matching area (Image 19).

Image 19: Create an Inverse Intersection Object in the Configuration window

In Image 20, that is the result of the option Create Inverse Intersection Object. From the left image, it shows the pair of Hospital and University Polygon Object (highlighted). There is no overlap between those objects, so the result returns both. However, if you look at 2 images from the right, the matching area was removed.

Image 20: Result of Create Inverse Intersection Object

In summary, in this blog, I introduced how to find the distance between 2 points or from 1 point to another point/ line/ polygon object by using the Distance tool. I also show how to find which route has the shortest distance by using the Find Nearest tool. In the last part, I used the Trade Area tool to create a Polygon from the centroid point; then, I compared options in the Spatial Process tool.

Thank you so much for reading. I know this blog is long, so I end up here. However, there are some interesting Spatial tools in Alteryx. I am going to continue in the next blog.

I hope this blog is useful to you and hope to see you soon in the next blog!

Author:
Le Luu
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
© 2025 The Information Lab