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

Returns a raster that is clipped by the given geometry.

If `crop` is not specified then it will default to `true`, meaning it will make the resulting raster shrink to the geometry's extent and if `noDataValue` is not specified then the resulting raster will have the minimum possible value for the band pixel data type.

The `allTouched` parameter (Since `v1.7.1`) determines how pixels are selected:

* When true, any pixel touched by the geometry will be included.
* When false (default), only pixels whose centroid intersects with the geometry will be included.

<Note>
  - Since `v1.5.1`, if the coordinate reference system (CRS) of the input `geom` geometry differs from that of the `raster`, then `geom` will be transformed to match the CRS of the `raster`. If the `raster` or `geom` doesn't have a CRS then it will default to `4326/WGS84`.
  - Since `v1.7.0`, `RS_Clip` function will return `null` if the `raster` and `geometry` geometry do not intersect. If you want to throw an exception in this case, you can set the `lenient` parameter to `false`.
</Note>

<img src="https://mintcdn.com/wherobots/AayJA2u8CknIeTgt/images/sql-functions/RS_Clip/RS_Clip.svg?fit=max&auto=format&n=AayJA2u8CknIeTgt&q=85&s=405cd1c3b02f826cf5fc7551b8f006f5" alt="RS_Clip" width="900" height="380" data-path="images/sql-functions/RS_Clip/RS_Clip.svg" />

## Signatures

```sql theme={"system"}
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double, crop: Boolean, lenient: Boolean)
```

```sql theme={"system"}
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double, crop: Boolean)
```

```sql theme={"system"}
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean, noDataValue: Double)
```

```sql theme={"system"}
RS_Clip(raster: Raster, band: Integer, geom: Geometry, allTouched: Boolean)
```

```sql theme={"system"}
RS_Clip(raster: Raster, band: Integer, geom: Geometry)
```

## Parameters

<ParamField body="raster" type="Raster" required>
  The input raster.
</ParamField>

<ParamField body="band" type="Integer" required>
  The band index.
</ParamField>

<ParamField body="geom" type="Geometry" required>
  The input geometry.
</ParamField>

<ParamField body="allTouched" type="Boolean">
  The all touched value.
</ParamField>

<ParamField body="noDataValue" type="Double">
  The NoData value to use for pixels outside the raster extent.
</ParamField>

<ParamField body="crop" type="Boolean">
  The crop value.
</ParamField>

<ParamField body="lenient" type="Boolean">
  The lenient value.
</ParamField>

## Return type

<ResponseField type="Raster">
  The resulting raster.
</ResponseField>

## Examples

```sql theme={"system"}
SELECT RS_Clip(
        RS_FromGeoTiff(content), 1,
        ST_GeomFromWKT('POLYGON ((236722 4204770, 243900 4204770, 243900 4197590, 221170 4197590, 236722 4204770))'),
        false, 200, true
    )
```

```sql theme={"system"}
SELECT RS_Clip(
        RS_FromGeoTiff(content), 1,
        ST_GeomFromWKT('POLYGON ((236722 4204770, 243900 4204770, 243900 4197590, 221170 4197590, 236722 4204770))'),
        false, 200, false
    )
```
