Within (spatial predicate)
True if geometry A lies completely inside geometry B (the inverse of Contains).
Category: Topology · Also known as: ST_Within, within predicate
Definition (expanded)
Within answers: is A entirely inside B? It is commonly used for spatial joins and filters. Like Contains, boundary behavior depends on the exact predicate semantics in the library/database you use.
Examples
PostGIS within
SQL
SELECT ST_Within(a.geom, b.geom) FROM a, b;
Common mistakes
- Using Within when you meant Intersects (Within is stricter).
- Assuming boundary contact counts the same everywhere (it doesn’t).
Related terms
Contains (spatial predicate)True if geometry A completely contains geometry B (B is inside A, not just touching the edge).Intersects (spatial predicate)True when two geometries share any point in common (touching or overlapping).Touches (spatial predicate)True when two geometries touch at the boundary but do not overlap in area (or interior).Disjoint (spatial predicate)True when two geometries share no points at all (no intersection).Point-in-polygon (PIP)A test that checks whether a point lies inside a polygon (often used for geofencing and joins).