onstove.VectorLayer.rasterize#

VectorLayer.rasterize(raster: RasterLayer = None, attribute: str = None, value: int | float = 1, width: int = None, height: int = None, transform: AffineTransform = None, cell_width: int | float = None, cell_height: int | float = None, nodata: int | float = 0, all_touched: bool = True, output_path: str | None = None) RasterLayer[source]#

Converts the vector data into a gridded raster dataset.

It rasterizes the vector data by taking either a transform, the width and height of the image, or the cell width and height of the output raster. It uses the rasterio.features.rasterize function.

Parameters:
attribute: str, optional

Name of the column in the GeoDataFrame to rasterize. If defined then the values of such column will be burned in the output raster.

value: int or float, default 1

If attribute is not defined, then a fixed value to burn can be defined here.

width: int, optional

The width of the output raster. This parameter needs to be passed along with the height.

height: int, optional

The height of the output raster. This parameter needs to be passed along with the width.

transform: Affine or sequence of GroundControlPoint or RPC

Transform suitable for input to AffineTransformer, GCPTransformer, or RPCTransformer according to rasterio Transform.

cell_width: int of float, optional

The width of the cell in the output raster. This parameter needs to be passed along with the cell_height parameter.

cell_height: int of float, optional

The height of the cell in hte output raster. This parameter needs to be passed along with the cell_width parameter.

nodata: int of float, default 0

No data value to be used for the cells with values outside the target values.

all_touched: bool, default True

Defines if all cells touched are considered for the rasterization.

output_path: str, optional

A folder path where to save the output dataset. If not defined then the rasterized dataset is not saved.

Returns:
RasterLayer

RasterLayer with the rasterized dataset of the current VectorLayer.