Skip to main content
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.
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.
For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the Affine Transformations section.

Signatures

RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double, noDataValue: Double)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double, noDataValue: Double, useGeometryExtent: Boolean)

Parameters

geom
Geometry
required
The geometry to be rasterized.
raster
Raster
required
The reference raster to be used for overlaying the geometry on.
pixelType
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).
allTouched
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.
value
Double
default:"1.0"
The value to be used for assigning pixels covered by the geometry.
noDataValue
Double
default:"null"
Used for assigning the no data value of the resultant raster.
useGeometryExtent
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.

Return type

The resulting raster.

Examples

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

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

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