> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_DWithin

Returns true if 'leftGeometry' and 'rightGeometry' are within a specified 'distance'.

<img src="https://mintcdn.com/wherobots/fqh3gPDE0J25Lra_/images/sql-functions/ST_DWithin/ST_DWithin_true.svg?fit=max&auto=format&n=fqh3gPDE0J25Lra_&q=85&s=383540080a291db4dae25d8fb6aa80ef" alt="ST_DWithin returning true" width="400" height="300" data-path="images/sql-functions/ST_DWithin/ST_DWithin_true.svg" />

<img src="https://mintcdn.com/wherobots/fqh3gPDE0J25Lra_/images/sql-functions/ST_DWithin/ST_DWithin_false.svg?fit=max&auto=format&n=fqh3gPDE0J25Lra_&q=85&s=47be95ca6adfb5ca856415e3c8684976" alt="ST_DWithin returning false" width="400" height="300" data-path="images/sql-functions/ST_DWithin/ST_DWithin_false.svg" />

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

`ST_DWithin` also accepts two `Box2D` inputs — `ST_DWithin(a: Box2D, b: Box2D, distance: Double)` — returning true if the minimum planar (Euclidean) distance between the two rectangles is at most `distance`. This uses closed-interval semantics, so overlapping or edge/corner-touching boxes have distance `0` and match any non-negative radius. It throws `IllegalArgumentException` on inverted bounds. Between two `Box2D` columns the predicate routes through Sedona's distance-join planner — see [Box2D spatial join](/reference/wherobots-db/geometry-data/optimizer#box2d-spatial-join).

## Signatures

```sql theme={"system"}
ST_DWithin (leftGeometry: Geometry, rightGeometry: Geometry, distance: Double, useSpheroid: Optional(Boolean) = false)
```

```sql theme={"system"}
ST_DWithin (a: Box2D, b: Box2D, distance: Double)
```

## Parameters

<ParamField body="leftGeometry" type="Geometry" required>
  The left geometry value.
</ParamField>

<ParamField body="rightGeometry" type="Geometry" required>
  The right geometry value.
</ParamField>

<ParamField body="distance" type="Double" required>
  The distance value.
</ParamField>

<ParamField body="useSpheroid" type="Boolean">
  Whether to use spheroidal distance calculation. Defaults to `false`.
</ParamField>

## Return type

<ResponseField type="Boolean">
  Returns `true` or `false`.
</ResponseField>

## Examples

```sql theme={"system"}
SELECT ST_DWithin(ST_GeomFromWKT('POINT (0 0)'), ST_GeomFromWKT('POINT (1 0)'), 2.5)
```

```
true
```

```text theme={"system"}
Check for distance between New York and Seattle (< 4000 km)
```

```sql theme={"system"}
SELECT ST_DWithin(ST_GeomFromWKT(-122.335167 47.608013), ST_GeomFromWKT(-73.935242 40.730610), 4000000, true)
```

```
true
```

Box2D example — two rectangles within 1.0 of each other:

```sql theme={"system"}
SELECT ST_DWithin(
    ST_MakeBox2D(ST_Point(0.0, 0.0), ST_Point(10.0, 10.0)),
    ST_MakeBox2D(ST_Point(11.0, 0.0), ST_Point(12.0, 1.0)),
    1.0)
```

```
true
```
