RS_AsRaster¶
Introduction: RS_AsRaster converts a vector geometry into a raster dataset by assigning a specified value to all pixels covered by the geometry. 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 and takes the following parameters:
geom: The geometry to be rasterized.raster: The reference raster to be used for overlaying thegeomon.pixelType: Defines data type of the output raster. This can be one of the following, D (double), F (float), I (integer), S (short), US (unsigned short) or B (byte).allTouched(Since:v1.7.1): Decides the pixel selection criteria. If set totrue, the function selects all pixels touched by the geometry, else, selects only pixels whose centroids intersect the geometry. Defaults tofalse.value: The value to be used for assigning pixels covered by the geometry. Defaults to using1.0if not provided.noDataValue: Used for assigning the no data value of the resultant raster. Defaults tonullif not provided.useGeometryExtent: Defines the extent of the resultant raster. When set totrue, it corresponds to the extent ofgeom, and when set to false, it corresponds to the extent ofraster. Default value istrueif not set.
Format:
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean, value: Double, noDataValue: Double, useGeometryExtent: Boolean)
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)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String, allTouched: Boolean)
RS_AsRaster(geom: Geometry, raster: Raster, pixelType: String)
Return type: Raster
Since: v1.5.0
Note
The function doesn't support rasters that have any one of the following properties:
ScaleX < 0
ScaleY > 0
SkewX != 0
SkewY != 0
For more information about ScaleX, ScaleY, SkewX, SkewY, please refer to the Affine Transformations section.
SQL Example
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
)
Output:
GridCoverage2D["g...
SQL Example
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'
)
Output:
GridCoverage2D["g...
SQL Example
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
)
Output:
GridCoverage2D["g...