Intersects Spatial Function

This new spatial function, introduced in 2022.4, makes it possible to determine if two spatial objects overlap without needing to perform a spatial join. It works with the following combinations of spatial objects:

  • Point and polygon
  • Line and polygon
  • Polygon and polygon

The function takes two mandatory spatial object arguments in the following format:

INTERSECTS( [geometry_1], [geometry_2] )

And returns either True or False.

Points and Polygons Example

In this example, I connected to a dataset with Airbnb locations (Airbnb Points) in a specific area of London. Then I created a buffer spatial object around an (imaginary) point of interest (POI 1) within that same area. 

I then used the following calculation to determine which Airbnb points intersect with the buffer


This returns True or False and, when added the Colour shelf, can be used to colour encode the Airbnb locations:


The buffer size is controlled with a parameter. When this is increased, we can see that the number of Airbnb locations colour encoded as intersecting the buffer object increases: 

Count the number of Airbnbs that intersect the buffer

The following calculation returns a count of the number of Airbnb IDs of those that intersect with the buffer object.


We can also return the above number as a percentage of the total number of Airbnbs:

Add Labels to the View

Adding these two calculations to the Label shelf, we can see them dynamically update as the buffer size is changed:

Lines and Polygon Example

The below example uses a spatial file with rivers and waterways, which are all line spatial objects. Again, a buffer object has been added and those waterways that intersect with the buffer have been colour encoded using an intersects calculation.

As the intersects function is being applied to a line and a polygon, only part of the line needs to intersect with the buffer (polygon) for the whole line to be encoded, which is why some parts of the waterways are encoded red (intersecting) even though they are outside of the buffer


Below is the calculation used to colour encode the waterways above:


Again, changing the buffer size will alter which lines (waterways) the buffer intersects:

Data: OS Open Rivers
Contains OS data © Crown copyright and database right 2021

Previous methods using the Distance function

For the point and buffer (polygon) example, it was previously possible to achieve this same encoding effect using the DISTANCE function to check if distance from the centre of the buffer to the point was less than or equal to the buffer size: 


When using other combinations of spatial objects, including regular (non-buffer) polygons, however, this approach won’t work and would require a spatial join, so this new Intersects function provides more flexibility. 

Alternative for Spatial Joins

When performing an inner Intersects spatial join, only rows that meet the join condition will be available for analysis. 


An alternative is to join (or create a relation) on join calculation fields such as 1=1, which will not filter any data and allow you to then use the Intersects function during your analysis to create the same effect – i.e. by then filtering out records where the result of the Intersects function is True. This provides more flexibility and lets you effectively turn the spatial join on or off dynamically within your analysis.

Note that if you use the 1=1 join technique, you will create duplicate rows (assuming both data sources have more than one row), so you need to account for that in your analysis.

You can also use the Intersects function to encode data (as we’ve seen in earlier examples above) instead of filtering, again providing more options and flexibility in your analysis. 

See this blog post to learn more about spatial joins in Tableau.

Video Tutorial

This video walks through a couple of scenarios for using the new Intersects spatial function in Tableau

Conclusion

In summary, the Intersects spatial function is a great addition to the spatial functions currently available in Tableau, providing more flexibility as you analyse your data. 

Thanks for reading.

Marc

Latest YouTube video
This video demonstrates combining Cloudinary’s dynamic image creation service with Tableau’s new Image Role feature.

Comments are closed.

Create a website or blog at WordPress.com

Up ↑