sieve#
- sieve(array: ~numpy.ndarray | ~numpy.ma.MaskedArray, out_meta: dict, sieve_thresh: int, connectivity: int = 4) -> (typing.Union[numpy.ndarray, numpy.ma.MaskedArray], <class 'dict'>)[source]#
Sieving, overloads rasterio function with raster shaped like (1, h, w).
Forces the output to
np.uint8
(as only classified rasters should be sieved)- Parameters:
- Returns:
Sieved array and updated meta
- Return type:
(AnyNumpyArray, dict)
Example
>>> raster_path = "path/to/raster.tif" # classified raster >>> >>> # Read raster >>> raster, meta = read(raster_path) >>> >>> # Rewrite it >>> sieved, sieved_meta = sieve(raster, meta, sieve_thresh=20) >>> >>> # Write it >>> raster_out = "path/to/raster_sieved.tif" >>> write(sieved, raster_out, sieved_meta)