Skip to main content
Returns true if ‘leftGeometry’ and ‘rightGeometry’ are within a specified ‘distance’. ST_DWithin returning true ST_DWithin returning false If useSpheroid is passed true, ST_DWithin uses Sedona’s ST_DistanceSpheroid to check the spheroid distance between the centroids of two geometries. The unit of the distance in this case is meter. If useSpheroid is passed false, ST_DWithin uses Euclidean distance and the unit of the distance is the same as the CRS of the geometries. To obtain the correct result, please consider using ST_Transform to put data in an appropriate CRS. If useSpheroid is not given, it defaults to false

Signatures

ST_DWithin (leftGeometry: Geometry, rightGeometry: Geometry, distance: Double, useSpheroid: Optional(Boolean) = false)

Parameters

leftGeometry
Geometry
required
The left geometry value.
rightGeometry
Geometry
required
The right geometry value.
distance
Double
required
The distance value.
useSpheroid
Boolean
Whether to use spheroidal distance calculation. Defaults to false.

Return type

Returns true or false.

Examples

SELECT ST_DWithin(ST_GeomFromWKT('POINT (0 0)'), ST_GeomFromWKT('POINT (1 0)'), 2.5)
true
Check for distance between New York and Seattle (< 4000 km)
SELECT ST_DWithin(ST_GeomFromWKT(-122.335167 47.608013), ST_GeomFromWKT(-73.935242 40.730610), 4000000, true)
true