liveBook · Manning

St_within

As explained in Just Use Postgres!

ST_Within is a PostGIS spatial predicate that tests whether one geometry lies completely within another geometry.

ST_Within(geometry A, geometry B) checks whether every point of geometry A lies completely inside geometry B. In PostGIS, it supports containment queries such as finding parks inside a larger theme-park boundary or attractions inside a specific park. section 10.5.2

Find theme parks inside Walt Disney World

Select candidate polygons and join them to the Walt Disney World boundary with ST_Within(p.way, d.boundaries). Filter for theme parks and exclude the containing polygon with NOT ST_Equals. The query returns six distinct parks, including EPCOT and Magic Kingdom.

How Just Use Postgres! covers it

How deep it goes
Defines complete containment and demonstrates SQL joins, filters, and exclusion of equal geometries without examining predicate internals.
Examples
Uses Walt Disney World boundaries to locate nested theme parks, attractions, and amenities.
What you can do after
Apply it via PostGIS SQL to retrieve features whose geometries fall inside a selected boundary.
How it connects
Connects geometry containment with PostGIS, ST_Equals, polygons, points, and spatial reference systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.