- paint(xds: Union[str, DataArray, Dataset, DatasetReader], shapes: Union[GeoDataFrame, Polygon, list], value: int, invert: bool = False, **kwargs) Union[DataArray, Dataset] #
Painting a dataset: setting values inside the given shapes. To set outside the shape, set invert=True. Pay attention that this behavior is the opposite of the
The original nodata is kept. This means if your shapes intersects the original nodata, the value of the pixel will be set to nodata rather than to the wanted value.
Overload of rasterio mask function in order to create a
maskfunction docs can be seen here.
>>> raster_path = "path/to/raster.tif" >>> shape_path = "path/to/shapes.geojson" # Any vector that geopandas can read >>> shapes = gpd.read_file(shape_path) >>> paint1 = paint(raster_path, shapes, value=100) >>> # or >>> with rasterio.open(raster_path) as ds: >>> paint2 = paint(ds, shapes, value=100) >>> paint1 == paint2 True
xds (PATH_XARR_DS) – Path to the raster or a rasterio dataset or a xarray
shapes (Union[gpd.GeoDataFrame, Polygon, list]) – Shapes with the same CRS as the dataset (except if a
GeoDataFrameis passed, in which case it will automatically be converted)
value (int) – Value to set on the shapes.
invert (bool) – If invert is True, set value outside the shapes.
**kwargs – Other rasterio.mask options
Painted array as a xarray
- Return type: