Rainbow Deals - hours only!Up to 80% off on all courses and bundles.-Close
Relationships Between Geometries
9. ST_Touches
ST_Distance and ST_Dwithin
Spatial joins practice



Yet another interesting function is ST_Touches(geometryA, geometryB). This function checks whether two geometries touch each other at their boundaries. In other words, it's a collision-detection function. Note that the two geometries cannot have any interior space in common.


This function can be used to find neighboring districts, additional segments/extensions of bicycle routes, and much more. Take a look at the following query:

FROM sf_bicycle_routes s1
JOIN sf_bicycle_routes s2
ON ST_Touches(s1.course, s2.course)

The query above will find all the bicycle routes that connect to the another bicycle route at one point.


Great news! Mark got a job in the Downtown district! Now he can look for a more permanent place to live instead of a hotel. He wants to have an apartment close to his workplace. Check which districts are adjacent to Downtown. Show the name column.

Stuck? Here's a hint!

Use ST_Touches in the JOIN clause. You will have to join the table with itself.