Skip to main content
Tests whether two geographies are within a given geodesic distance (in meters) of each other on the sphere. The minimum great-circle distance between any two points on the two geographies is compared against the threshold; the test is inclusive (returns true when the minimum distance equals the threshold). ST_DWithin returning true ST_DWithin returning false

Signatures

ST_DWithin (A: Geography, B: Geography, distance: Double)

Parameters

A
Geography
required
The first geography.
B
Geography
required
The second geography.
distance
Double
required
The maximum geodesic distance, in meters.

Return type

true if A and B are within distance meters of each other.

Example

SELECT ST_DWithin(
  ST_GeogFromWKT('POINT (0 0)', 4326),
  ST_GeogFromWKT('POINT (0 1)', 4326),
  200000.0
);
true
The same pair of points with a tighter threshold:
SELECT ST_DWithin(
  ST_GeogFromWKT('POINT (0 0)', 4326),
  ST_GeogFromWKT('POINT (0 1)', 4326),
  100000.0
);
false