onstove.RasterLayer.mask#

RasterLayer.mask(mask_layer: VectorLayer, output_path: str | None = None, crop: bool = True, all_touched: bool = False)[source]#

Creates a masked version of the layer, based on an input shape given by a VectorLayer.

It uses the rasterio.mas.mask function to create a masked version of the raster, based on input shapes that are defined by a VectorLayer.

Parameters:
mask_layer: VectorLayer

Layer that contains the shapes that are used to create the mask. Every pixel of the raster outside the mask, will be set to the raster’s nodata value.

output_path: str, optional

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

crop: bool, default True

Boolean indicating if the raster extent should be cropped to the mask_layer extent.

all_touched: bool, default True

Include a pixel in the mask if it touches any of the shapes. If False, include a pixel only if its center is within one of the shapes, or if it is selected by Bresenham’s line algorithm.