> ## 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.

# RS_DWithin

Returns true if the raster or geometry on the left side is within `distance` **meters** of the raster or geometry on the right side. The convex hull of the raster is considered in the test. At least one of the two shape arguments must be a raster — for the geometry-only case use [ST\_DWithin](/reference/wherobots-db/geometry-data/predicates/ST_DWithin) instead.

Rules for testing the spatial relationship:

* If the raster or geometry does not have a defined SRID, it is assumed to be in WGS84.
* Both sides are unconditionally projected to WGS84 before the test, so `distance` is **always** measured in meters regardless of the input CRS.
* The per-row test computes the **minimum geodesic distance** between the two shapes — the raster is represented by its convex hull, and the geodesic distance is measured between the closest pair of points on the two hulls (not centroid-to-centroid). Two raster footprints that overlap or touch therefore satisfy `RS_DWithin(a, b, 0)`, mirroring [RS\_Intersects](/reference/wherobots-db/raster-data/predicates/RS_Intersects).

When used as a join condition, Sedona plans the join as an optimized distance join (`BroadcastIndexJoinExec` or `DistanceJoinExec`): each side's WGS84 envelope is computed, the distance-side envelope is expanded by `distance` meters using the Haversine polar-radius approximation (the same expansion `ST_DistanceSphere` uses), and the resulting envelopes drive an R-tree filter before the per-row `RS_DWithin` check refines the result.

## Signatures

```sql theme={"system"}
RS_DWithin(raster: Raster, geom: Geometry, distance: Double)
```

```sql theme={"system"}
RS_DWithin(geom: Geometry, raster: Raster, distance: Double)
```

```sql theme={"system"}
RS_DWithin(raster0: Raster, raster1: Raster, distance: Double)
```

## Parameters

<ParamField body="raster / geom" type="Raster | Geometry" required>
  The left-side shape. At least one of the two shape arguments must be a raster.
</ParamField>

<ParamField body="raster / geom (right)" type="Raster | Geometry" required>
  The right-side shape. At least one of the two shape arguments must be a raster.
</ParamField>

<ParamField body="distance" type="Double" required>
  The maximum distance, in meters.
</ParamField>

## Return type

<ResponseField type="Boolean">
  `true` if the two shapes are within `distance` meters of each other.
</ResponseField>

## Example

```sql theme={"system"}
SELECT RS_DWithin(
    RS_MakeEmptyRaster(1, 20, 20, 2, 22, 1),
    ST_SetSRID(ST_PolygonFromEnvelope(30, 30, 40, 40), 4326),
    5000000.0  -- 5 000 km, in meters
) AS within_5000km
```

```
+-------------+
|within_5000km|
+-------------+
|         true|
+-------------+
```

Using `RS_DWithin` as a distance-join condition (`distance` in meters):

```sql theme={"system"}
SELECT r.id, p.id
FROM rasters r
JOIN points p ON RS_DWithin(r.raster, p.geom, 1000)  -- within 1 km
```
