PostGISSpatial Relationships

ST_ContainsProperly

What is ST_ContainsProperly?

ST_ContainsProperly is a stricter form of ST_Contains. It returns true when every point of geometry B lies in the interior of geometry A — no part of B may touch A's boundary. The DE-9IM pattern is T**FF*FF*.

SQL
ST_ContainsProperly(geometry geomA, geometry geomB)boolean

Because the predicate forbids any boundary contact, it can be evaluated using prepared geometries with a very fast cached code path, which makes it ideal for large spatial joins.

When would you use ST_ContainsProperly?

Use ST_ContainsProperly when you need strict interior containment — for example, selecting addresses that are unambiguously inside a single administrative polygon (and not on any shared boundary), or filtering wildlife sightings that lie well within a reserve rather than on its edge. It is also a performance-oriented choice inside spatial joins when the stricter semantics are acceptable, because PostGIS can short-circuit many boundary cases.

SQL
1SELECT p.id
2FROM parcels p
3JOIN hazards h ON ST_ContainsProperly(h.geom, p.geom)
4WHERE h.risk = 'high';

FAQs

How does ST_ContainsProperly differ from ST_Contains?

ST_Contains returns true even if B touches A's boundary, provided B also has an interior point inside A. ST_ContainsProperly rejects any boundary contact — every single point of B must be in A's interior. For two polygons sharing an edge, ST_Contains can return true, but ST_ContainsProperly will not.

When is the performance benefit real?

ST_ContainsProperly is particularly fast when the same geometry A is tested against many Bs (common in a spatial join), because PostGIS can use a prepared geometry cache and avoid re-indexing A for each comparison. You'll notice the biggest wins on dense point-in-polygon joins.

Does it support geography types?

No. ST_ContainsProperly only accepts geometry. If your data is stored as geography, cast it to geometry first, but be aware that the predicate is evaluated in planar coordinates, so results for large areas near the poles or crossing the antimeridian may be surprising.

Is ST_ContainsProperly a standard OGC predicate?

No. It is a PostGIS extension beyond the OGC Simple Features specification. OGC defines only ST_Contains, ST_Within, ST_Covers, and related predicates. Use ST_ContainsProperly when you specifically want the stricter semantics and aren't constrained by OGC compatibility.