PostGISSpatial Relationships

ST_CoveredBy

What is ST_CoveredBy?

ST_CoveredBy is a PostGIS spatial predicate that returns true when no point of geometry A lies in the exterior of geometry B. Unlike ST_Within, boundary contact is allowed — a point sitting exactly on B's edge is still "covered by" B.

SQL
1ST_CoveredBy(geometry geomA, geometry geomB)boolean
2ST_CoveredBy(geography geogA, geography geogB)boolean

It is the inverse of ST_Covers: ST_CoveredBy(A, B) is equivalent to ST_Covers(B, A).

When would you use ST_CoveredBy?

Use ST_CoveredBy when you want "inside or on the boundary" semantics and ST_Within is too strict. Typical cases include matching features to the administrative polygon they fall inside when some features sit precisely on shared borders, or confirming that a road segment stays entirely within a corridor polygon including touching its edges.

SQL
1SELECT r.id
2FROM roads r
3WHERE ST_CoveredBy(r.geom, (SELECT geom FROM corridors WHERE name = 'A1'));

FAQs

How is ST_CoveredBy different from ST_Within?

ST_Within requires geometry A's interior to intersect B's interior. A point that lies exactly on B's boundary is not within B but is covered by B. ST_CoveredBy is therefore the safer choice whenever boundary contact is semantically acceptable, which avoids the famous "point on edge" false negatives.

Does ST_CoveredBy work with geography?

Yes — PostGIS provides a geography overload that evaluates the predicate on the sphere, which is what you want for global datasets. For planar data, the geometry version is faster.

Is ST_CoveredBy index-accelerated?

Yes. The planner uses the bounding-box operator @ (A is contained by B's bbox) as an index filter before evaluating the exact predicate. Make sure both geometry columns have a GiST index for spatial joins.

Which DE-9IM pattern does ST_CoveredBy correspond to?

ST_CoveredBy(A, B) returns true when DE-9IM matches any of T*F**F***, *TF**F***, **FT*F***, or **F*TF*** — essentially, A has no point in B's exterior. This is a superset of the ST_Within relation.