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

Converts a Geometry to a Raster dataset. Unlike `RS_Clip`, which extracts a subset of an existing raster while preserving its original values, `RS_AsRaster` generates a new Raster where the Geometry is rasterized onto a raster grid. The function supports all geometry types.

<Note>
  The function doesn't support rasters that have any one of the following properties:

  ```
  ScaleX < 0
  SkewX != 0
  SkewY != 0
  ```

  If a raster is provided with any one of these properties then IllegalArgumentException is thrown.
</Note>

For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the [Affine Transformations](/reference/wherobots-db/raster-data/raster-affine-transformation) section.

## Signatures

```sql theme={"system"}
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String)
```

```sql theme={"system"}
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean)
```

```sql theme={"system"}
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double)
```

```sql theme={"system"}
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double, noDataValue: Double)
```

```sql theme={"system"}
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double, noDataValue: Double, useGeometryExtent: Boolean)
```

## Parameters

<ParamField body="geom" type="Geometry" required>
  The geometry to be rasterized.
</ParamField>

<ParamField body="raster" type="Raster" required>
  The reference raster to be used for overlaying the geometry on.
</ParamField>

<ParamField body="pixelType" type="String" required>
  Defines data type of the output raster. Accepts one of: `D` (double), `F` (float), `I` (integer), `S` (short), `US` (unsigned short) or `B` (byte).
</ParamField>

<ParamField body="allTouched" type="Boolean" default="false">
  Decides the pixel selection criteria. If set to `true`, the function selects all pixels touched by the geometry. If `false`, selects only pixels whose centroids intersect the geometry.
</ParamField>

<ParamField body="value" type="Double" default="1.0">
  The value to be used for assigning pixels covered by the geometry.
</ParamField>

<ParamField body="noDataValue" type="Double" default="null">
  Used for assigning the no data value of the resultant raster.
</ParamField>

<ParamField body="useGeometryExtent" type="Boolean" default="true">
  Defines the extent of the resultant raster. When set to `true`, it corresponds to the extent of `geom`. When set to `false`, it corresponds to the extent of `raster`.
</ParamField>

## Return type

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

## Examples

```sql theme={"system"}
SELECT RS_AsRaster(
    ST_GeomFromWKT('POLYGON((15 15, 18 20, 15 24, 24 25, 15 15))'),
    RS_MakeEmptyRaster(2, 255, 255, 3, -215, 2, -2, 0, 0, 4326),
    'D', false, 255.0, 0d
)
```

```
GridCoverage2D["g...
```

### With default parameters

```sql theme={"system"}
SELECT RS_AsRaster(
    ST_GeomFromWKT('POLYGON((15 15, 18 20, 15 24, 24 25, 15 15))'),
    RS_MakeEmptyRaster(2, 255, 255, 3, -215, 2, -2, 0, 0, 4326),
    'D'
)
```

```
GridCoverage2D["g...
```

### Using allTouched and useGeometryExtent

```sql theme={"system"}
SELECT RS_AsRaster(
    ST_GeomFromWKT('POLYGON((15 15, 18 20, 15 24, 24 25, 15 15))'),
    RS_MakeEmptyRaster(2, 255, 255, 3, 215, 2, -2, 0, 0, 0),
    'D', true, 255, 0d, false
)
```

```
GridCoverage2D["g...
```
