ST_Equals tests whether two geometries are topologically equal: they share the same dimension and occupy the same point set. It is useful for excluding a containing boundary when finding distinct geometries inside it. section 10.5.2
Exclude the containing theme park boundary
Use ST_Within to find theme parks inside Walt Disney World, then remove the boundary itself with ST_Equals: AND NOT ST_Equals(p.way, d.boundaries) The query returns six distinct theme parks rather than the Walt Disney World polygon. section 10.5.2
Listing 10.18 Finding distinct parks within Walt Disney World
WITH disney_world AS ( SELECT way AS boundaries FROM florida.planet_osm_polygon WHERE name = 'Walt Disney World' ) SELECT p.name, p.tourism FROM florida.planet_osm_polygon AS p JOIN disney_world AS d ON ST_Within(p.way, d.boundaries) WHERE p.name IS NOT NULL AND p.tourism = 'theme_park' AND NOT ST_Equals(p.way, d.boundaries) ORDER BY p.name;
Browse the complete SQL query that combines ST_Within with ST_Equals to identify distinct theme parks within a larger polygon. section 10.5.2
