2

Intersects Spatial Function

 1 year ago
source link: https://datavis.blog/2022/12/28/intersects-spatial-function/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

00-tableau-intersects-function.png?w=545

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

01-tableau-intersects-point-and-polygon.png?w=842

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: 

02-tableau-intersects-point-and-polygon.png?w=843

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.

05-number-of-points-that-intersect-calculation.png?w=630

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

06-percentage-of-points-that-intersect-calculation.png?w=484

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:

07-labels.png?w=227
tableau-intersects-function-gif.gif?w=736

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

08-intersects-waterways-line-polygon.png?w=916

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

09-intersects-line-polygon-calculation.png?w=426

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

intersects-line-buffer-gif.gif?w=736

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: 

10-distance-function.png?w=531

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. 

11-spatial-join.png?w=614

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.

Latest YouTube video
Tutorial walking through two examples of the new INTERSECTS() spatial function in Tableau 2022.4


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK