Name

ST_DWithin — Tests if two geometries are within a specified distance. Returns True if so, otherwise returns False.

Synopsis

boolean ST_DWithin(bytea GeomA, bytea GeomB, double Distance);

Alias

ST_DWithin

Description

Tests if two geometries are within a specified distance. Returns True if so, otherwise returns False. Distance units are those of the geometries.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
----

Examples

SELECT ST_Distance(A,B) as distance, ST_DWithin(A,B,5) as within5 , ST_DWithin(A,B,3) within3 FROM
(SELECT
ST_GeomFromText('POLYGON ((2 2, 2 6, 4 6, 4 2, 2 2))') as A,
ST_GeomFromText('POLYGON ((7 9, 7 11, 10 11, 10 9, 7 9))') as B
) as foo;
--Result
     distance     | within5 | within3
------------------+---------+---------
 4.24264068711928 | t       | f

Related functions

ST_Distance