How do you mask an area in rasterio?

How do you mask an area in rasterio?

Mask the area outside of the input shapes with no data. Creates a masked or filled array using input shapes. Pixels are masked or set to nodata outside the input shapes, unless invert is True. If shapes do not overlap the raster and crop=True, a ValueError is raised.

What happens when a mask is applied to a raster?

Data contained in the raster after applying the mask. If filled is True and invert is False, the return will be an array where pixels outside shapes are set to the nodata value (or nodata inside shapes if invert is True ). If filled is False, the return will be a MaskedArray in which pixels outside shapes are True (or False if invert is True ).

What are the parameters for rasterio in Python?

Parameters ———- raster : string, pathlib.Path or rasterio.io.DataSetReader Location of or already opened raster. boundary : string, pathlib.Path or geopandas.GeoDataFrame The polygon by which to clip the raster. boundary_layer : string, optional For multi-layer files (like GeoPackage), specify the layer to be used.

What kind of resolution is used in rasterio?

If not set, the resolution of the first raster is used. If a single value is passed, output pixels will be square. nodata ( float, optional) – nodata value to use in output file. If not set, uses the nodata value in the first input raster. dtype ( numpy dtype or string) – dtype to use in outputfile.

Why is rasterio not resampling over no data area?

When calling RasterIO with resampling enabled (eg bilinear) over a no-data area, if the output buffer type is different than the input native type, the no-data pixels are not set properly. Steps to reproduce the problem. The following program shows the issue.

How to mask a raster using a shapefile?

Using rasterio with fiona, it is simple to open a shapefile, read geometries, and mask out regions of a raster that are outside the polygons defined in the shapefile. This shapefile contains a single polygon, a box near the center of the raster, so in this case, our list of features is one element long.