All Products
Search
Document Center

ApsaraDB RDS:ST_DFullyWithin

Last Updated:Mar 28, 2026

Returns true if g2 is entirely within distance of g1 — that is, every point on g2 falls within a distance buffer around g1. Returns false if any point on g2 falls outside that buffer.

Syntax

boolean ST_DFullyWithin(geometry g1, geometry g2, double precision distance);

Parameters

ParameterTypeDescription
g1geometryThe reference geometry object.
g2geometryThe geometry object to test against g1.
distancedouble precisionThe distance threshold. The unit is determined by the spatial reference system (SRS) of the geometry objects.

Usage notes

  • Both g1 and g2 must use the same projection and have the same spatial reference identifier (SRID).

  • The function automatically uses bounding box comparisons and all available indexes on the geometry objects to optimize performance.

ST_DFullyWithin vs. ST_DWithin

ST_DFullyWithin requires that every point on g2 is within distance of g1. ST_DWithin requires only that the two geometries have at least one point within distance of each other. ST_DFullyWithin is the stricter of the two.

The following example applies both functions to the same geometries at distance = 2:

SELECT
    ST_DFullyWithin(g1, g2, 2) AS dfullywithin2,
    ST_DWithin(g1, g2, 2)      AS dwithin2
FROM (
    VALUES (
        'LINESTRING(0 1,1 1)'::geometry,
        'LINESTRING(0 0,0 -1)'::geometry
    )
) AS t(g1, g2);

 dfullywithin2 | dwithin2
---------------+----------
 f             | t
(1 row)

g2 has points that extend beyond the distance-2 buffer of g1, so ST_DFullyWithin returns f. The closest points of the two line strings are within distance 2 of each other, so ST_DWithin returns t.

See also

  • ST_DWithin — Tests whether two geometries have any point within a specified distance of each other.