Spatial Analytics in Alteryx (Part 1)

One feature from Alteryx that impressed me is Spatial Analytics. From Spatial Analytics in Alteryx, I can do most analytics in spatial including finding the boundary, finding the distance between points, and calculating the area,... In this blog, I am so excited to share Spatial tools in Alteryx. However, before introducing the tools and their features, I will talk about the Spatial Objects in Alteryx first. The content in this blog includes:

1/ Spatial Objects in Alteryx
2/ How to create Spatial Objects in Alteryx
* Create Point Objects
* Create Line Objects (Sequence Line)
* Create Polygon Objects (Convex Hull and Sequence Polygon)

Are you ready to explore the Spatial Analytics in Alteryx with me? If yes, let's get started now!


1/ Spatial Objects in Alteryx

Alteryx Databases (.yxdb), ESRI Shapefiles (.shp), Google Earth Key Markup Language (.kml), and Map Info TAB (.tab) can be used to import Spatial Objects. But what are Spatial Objects?

In Alteryx, there are 3 main Spatial Objects: Point, Line, and Polygon.

Image 1: 3 main Spatial Objects in Alteryx

Point Object: A point object includes latitude and longitude coordinates to decide a point on the Earth. Both latitude and longitude are measured in degree units; for smaller units, it would be minutes (') and seconds (''). Both latitude and longitude can also be in decimal formatting with positive and negative signs.

Line Object: is a connection of 2 points.

Polygon Object: a combination of multiple points or lines that create a boundary.

2/ Create Spatial Objects in Alteryx

Before getting started, I download a dataset from the National Weather Service in the U.S. https://www.weather.gov/gis/USStates. This dataset includes the data of U.S. States and territories. After downloading the dataset and extracting the zip file, I imported the ESRI shape file (.shp) into Alteryx Designer (Image 2).

Image 2: Import the dataset into the Alteryx Designer

In the dataset, there are many fields: State Abbreviation, State name, FIPS, Longitude (LON), Latitude (LAT), and a Spatial Object. From the result window, I can recognize the spatial object is a Polygon type.

Create Point Objects

Requirement: Longitude and Latitude

First of all, I will build a point from the longitude and latitude first. In Alteryx, to create a point, we need longitude and latitude values. Then, I used the Create Points tool to help me create the point.

From the Spatial palette, I drag the Create Points tool to connect with the Input tool. Then, Alteryx automatically filled in the Longitude (LON) and Latitude (LAT) in the Create Points tool. I run the workflow. In the Result window below, a new Centroid column was created with Point Spatial Object (Image 3).

Image 3: Create a Point from Longitude and Latitude in the dataset

I connect the Browse tool to the Create Points tool and run the workflow. By clicking on the Browse tool, in the Configuration window, it shows the U.S. territory map. Polygon objects are the boundary with red color while the green diamond shapes are Point objects (Image 4).

Image 4: Points and Polygon in the Browse tool

How to create lines and polygons from Point Objects in Alteryx?

Create Line Objects

Requirement: at least 2 Point Objects

To create a Line Object, we need at least 2 points to create a line. As we have many Point Objects now, so we are ready to create a Line. Before going to create a line, I need to create a field called "Day". I assumed that was the day that I visited. For one day, I can visit many states :)

We have 59 states in the United States, so I use the RandInt() function to random the day number. I put 25 into the RandInt() function, so it will random integer numbers from 0 to 25 (Image 5). Note that every time you run the workflow, the value in the Day field will be different.

Image 5: Create a random day to group by day later

Now, let's create a Line.

I drag the Poly-Build tool from the Spatial palette and connect it with the Formula tool (Image 6). In the configuration window, I set:

  • Build Method: Sequence Polyline because we are creating a Line Object. There are 2 other options but I will mention later.
  • Source Field: to create a Line, we need a Point Object. We cannot make a line from a Polygon Object.
  • Group Field: I want to group by the Day field I just created.
  • Sequence Field: I chose FIPS, so the line will be created based on the order of the sequence field.
Image 6: Create a Line Object based on the Centroid (Point Objects)

Note that in Image 6, in the Result window, you can see there are many Null values. It means on that day, there is only 1 Point Object. We cannot make a Line with only 1 Point Object.

I used the Summarize tool to group by day to check (Image 7).

Image 7: Some days only have 1 Point Object, so cannot make a Line

Create Polygon Objects

To build a Polygon Object, there are 2 Build Methods: Convex Hull and Sequence Polygon. I will go through each Build Method.

  • Convex Hull

Requirement: Point, Line, or Polygon Object for Source Field.

The Convex Hull method will need a set of points, lines, and Polygon to build Polygon objects. In this case, I am grouping by the Day field. (Image 8)

If my source field is Point Objects, then it could return Polygon, Line, or Point Objects. If there is only 1 Point Object in a day, then it will return a Point Object. If there are 3 Point Objects in a day, then it will return a Line Object. For 3 Point Objects or more, it will return a Polygon.

If my source field is Line Objects, then it returns Line or Polygon Objects. If there is only 1 Line Object in a day, it will return a Line Object. However, if there are more than 2 Line Objects, it will return a Polygon Object.

If the source field is Polygon Objects, then it all returns Polygon Objects because it's already a Polygon.

Image 8: Compare different source fields in the Convex Hull method grouped by Day

How does it look if I don't group by any fields?

If I don't group by any fields (choosing None in Group Field), then the result only returns 1 Polygon Object. If the Source Field is Line Objects or Point Objects, the result looks similar. But if the Source field is Polygon, the result is different from other Source Fields. (Image 9)

Image 9: Only return 1 Polygon Object if don't group by any fields
  • Sequence Polygon

Requirement: Only Point Objects

In Convex Hull, you can input any type of Object into the Source Field to create a Polygon Object only, or Polygon, Point, or Line Objects (depending on using the Group Field). You cannot use Sequence Field in Convex Hull.

In Sequence Polygon, you can use Group Field, Sequence Field; but only accept Point Objects. (Image 10)

Image 10: Sequence Polygon only accepts Point Objects

From Image 10 above, if I use either group field and/or sequence field, the result doesn't have a hole. However, there are some Null values because some days only have 1 or 2 Point Object(s). To create a Polygon Object, we should need more than 3 Point Objects.

If I don't use the group field and sequence field, the result only returns 1 Polygon Object. However, there are many holes in the Polygon Object. (Image 11)

Image 11: Zoom in from the most right Image 10

In summary, in this blog, I introduced the type of Spatial Object in Alteryx, and how to create Point, Line, and Polygon Objects. I also distinguished some differences when creating Polygon Objects (Convex Hull and Sequence Polygon) and the requirements for each method.

This blog is quite long, so I will write another blog about Spatial Analytics in Alteryx (Part 2). In that part, I will share how to find the distance, area, and other information about Spatial Analytics. I hope this blog is helpful to you if you are exploring the Spatial topic in Alteryx.

Thank you for reading and hope to see you 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
© 2024 The Information Lab