skmap.parallel.blocks.RasterBlockWriter#
- class RasterBlockWriter(reader=None)[source]#
Bases:
objectClass for writing results of block wise raster processing results into a new raster file.
- Parameters:
reader (
RasterBlockReader) – RasterBlockReader instance to use for reading rasters.
For full usage examples please refer to the block processing tutorial notebook [1].
References
[1] Raster block processing tutorial
Examples
>>> from skmap.parallel.blocks import RasterBlockReader, RasterBlockWriter >>> >>> fp = 'https://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_landcover.hcl_lucas.corine.rf_p_30m_0..0cm_2019_skmap_epsg3035_v0.1.tif' >>> >>> reader = RasterBlockReader(fp) >>> writer = RasterBlockWriter(reader)
Methods
Writes block wise calculation results to new raster file.
- write(src_path, dst_path, geometry, block_func=<function _id>, geometry_mask=True, reader_kwargs={}, **kwargs)[source]#
Writes block wise calculation results to new raster file.
Performs
block_funcon all blocks of file(s) listed insrc_paththat intersect withgeometryand writes the results to a new raster.- Parameters:
src_path (
Union[str,Iterable[str]]) – Path(s) (or URLs) of the raster file(s) to read. If aggregator is initialized withreader=None, the first file insrc_pathwill be used to initialize a new reader.dst_path (
str) – Path to write the result raster to.geometry (
dict) – The bounding geometry within which to read raster blocks, given as a dictionary (with the GeoJSON geometry schema).block_func (
Callable) – Callable to perform on the data for each block. Result must retain the shape of input data. Defaults to the identity function.geometry_mask (
bool) – Indicates wheather or not to use the geometry as a data mask. IfFalse, calculation will be performed on all of the block data, regardless if some of it falls outside of thegeometry.reader_kwargs (
dict) – Additional keyword arguments passed toRasterBlockReader.read_overlay().**kwargs –
Additional raster profile keyword arguments passed to the
rasteriodataset writer [1].
- Return type:
For full usage examples please refer to the block processing tutorial notebook [2].
References
[1] Writing datasets with Rasterio
[2] Raster block processing tutorial
Examples
>>> geom = { ... 'type': 'Polygon', ... 'coordinates': [[ ... [4765389, 2441103], ... [4764441, 2439352], ... [4767369, 2438696], ... [4761659, 2441949], ... [4765389, 2441103], ... ]], ... } >>> >>> def is_urban_fabric(lc): ... return lc == 1 >>> >>> writer.write(fp, 'urban_fabric.tif', geom, is_urban_fabric, dtype='uint8', nodata=0)