We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
gawa
16 - Nebula
16 - Nebula

The Advent of Code is a global programming challenge to solve 25 puzzles each year in December. Alteryx Community members solve these puzzles in Designer and share solutions to earn badges. This article is part of a blog series that shares advanced Alteryx problem-solving techniques for these challenges and more!

Introduction

 

If you're solving Advent of Code with Alteryx, don't you want to try a solution that feels like “this could only be done in Alteryx”? One such approach is spatial analytics.

 

Alteryx is often associated with SQL-based data processing, but spatial analysis using 2D spatial objects is another essential feature—it's actually one of Alteryx's original core capabilities and even part of the product’s name: “Alter X-Y” (this is off-topic, though).

 

A quick note of caution: the spatial objects in Alteryx are defined using spherical coordinates (on the Earth's surface), not flat 2D (Euclidean) coordinates. As a result, distances between two points aren’t perfectly straight-line distances as you’d get in a flat plane—they may differ slightly. However, the relative relationships between spatial objects (like touching, overlapping, containing, etc.) remain the same. (Imagine drawing geometric shapes on a deflated balloon—when you inflate it, the shapes may stretch, but their relationships remain.)

 

Advent of Code 2024 - Day 25 Example

 

Day 25 of AoC 2024 was a puzzle where spatial analysis worked beautifully. The task was to determine whether “Key” and “Pin” shapes overlapped, like in the diagram below.

 

Normally in programming languages, you’d handle this with numeric comparisons like [Z_key_min] > [Z_pin_max]. But here, let’s solve it using spatial analytics.

 

Key and Pin (#=filled, .=blank)Key and Pin (#=filled, .=blank)

 

Step 1: Create Spatial Objects for Key and Pin

 

Using the Create Points tool with X as the horizontal axis and Y as the vertical axis, we can build spatial objects. However, these points alone don’t yet look like “Keys” or “Pins”. So we convert them into polygons.

 

image.png

 

Step 2: Convert Points into Polygons

 

For each point object, create a square by plotting a diagonally opposite point and using the ST_BoundingRectangle function to form a square polygon.

 

image.png

 

By combining these individual polygons for each Key and Pin, we can construct spatial objects that properly represent the “Key” and “Pin” shapes.

 

image.png

 

Step 3: Check for Overlaps

 

The goal is to identify which Key and Pin combinations do not overlap.

 

First, generate all possible Key–Pin combinations using the Append Fields tool. Then, to check for overlaps, here are two methods:

 

Method 1: Use the ST_Intersects Function

 

ST_Intersects(object1, object2) returns a Boolean indicating whether the two objects intersect. Since we’re looking for non-overlapping pairs, we negate the result with a !—so !ST_Intersects(...) will be True if the objects do not intersect.

 

T-anchor of the Filter toolT-anchor of the Filter tool

 

⚠️ Note: Even if objects don’t overlap, their corners might touch. That’s why ST_Touches isn't appropriate in this context.

 

Method 2: Use the Spatial Process Tool

 

If you want to stick with Spatial tools, the Spatial Process tool is a great option. By selecting the “Create Intersection Object” option, you’ll get an output field [SpatialObj_Process] with the intersected geometry. If this field is NULL, it means there was no overlap between the Key and Pin. So just filter for records where [SpatialObj_Process] is NULL to get your answer.

 

Output anchor of  the Spatial Process toolOutput anchor of the Spatial Process tool

 

Closing Thoughts

 

This was a spatial solution to Day 25 of AoC2024. Spatial analysis provides an intuitive, visual, and often fun way to solve puzzles. So why not join the challenge in Advent of Code 2025, and try a spatially special solution together?