ST_DFullyWithin
What is ST_DFullyWithin?
ST_DFullyWithin returns true if every point of geometry g1 is within a given distance of geometry g2, and vice versa. Equivalently, it tests whether the maximum distance between the two geometries is less than or equal to the threshold. This is a stricter test than ST_DWithin, which only checks the minimum distance.
ST_DFullyWithin(geometry g1, geometry g2, float distance) → booleanDistance is in the CRS units of the inputs. There is no geography overload.
When would you use ST_DFullyWithin?
Use ST_DFullyWithin when you need to guarantee that two features are entirely close to each other, not merely that they touch. Typical uses include verifying that an entire asset lies inside a buffer of a reference feature, confirming two trajectories never diverge beyond a tolerance, or checking that a polygon is everywhere within a distance of a centre point — useful for certifying compliance zones.
1-- Trails that never wander more than 50 m from their reference alignment
2SELECT t.id
3FROM trails t, alignments a
4WHERE t.id = a.id
5 AND ST_DFullyWithin(t.geom, a.geom, 50);FAQs
How does it differ from ST_DWithin?
ST_DWithin uses the minimum distance — true if any point of g1 is within d of g2. ST_DFullyWithin uses the maximum distance — true only if every point of each is within d of the other. It is a much stricter condition.
Is it index-accelerated?
Yes. ST_DFullyWithin uses the bounding box "contained within expanded envelope" check against a GiST index to prune candidates before exact computation. Ensure your geometry column has a GiST index.
Does it work in 3D?
Yes — ST_3DDFullyWithin is the 3D version. It requires an N-D GiST index for acceleration.
What units does the distance parameter use?
The CRS units of the inputs — degrees for EPSG:4326, metres for most projected CRSs. There is no geography overload; reproject or cast if you need metre-based thresholds on lat/lon data.