geodata.Mask.merge_layer

geodata.Mask.merge_layer#

geodata.Mask.merge_layer(method: MergingMethods = 'and', weights: dict[str, float] | None = None, layers: Iterable[str] | None = None, trim: bool = False, show_raster: bool = True, reference_layer: str | None = None, attribute_save: bool = True, **kwargs) rasterio.DatasetReader#

Merge multiple and flatten multiple layers from self.layers using either ‘and’ and ‘sum’ method. By default, ‘and’ method is used, and we would save the result to merged_mask attribute.

Adjusted from rasterio’s documentation on merging: https://rasterio.readthedocs.io/en/latest/api/rasterio.merge.html

Geospatial bounds and resolution of a new output file in the units of the input file coordinate reference system may be provided, but by default, the method will use the layer with the best resolution for the output bounds/resolution, unless a reference layer is provided.

Parameters:
  • method (str) – The method to merge the layers. By default, ‘and’ method is used. ‘and’ method will perform “AND” operation over the overlapping pixels. ‘sum’ method will take the sum of the overlapping pixels.

  • weights (dict) – The weight of each layer to be merged. By default, all layers will have the same weight of 1.

  • layers (Iterable[str]) – The list of layers to be merged. If not specified, all layers in the object will be merged.

  • trim (bool) – Whether the method will trim the all-empty row/column border of the raster. By default, this is set to False.

  • show_raster (bool) – Whether the method will plot the merged raster. By default, this is set to True.

  • reference_layer (str) – The name of the layer to be used as the reference layer. If not specified, the method will use the layer with the best (highest) resolution.

  • attribute_save (bool) – Whether the method will save the merged raster to the merged_mask attribute. By default, this is set to True.

  • **kwargs – Additional arguments passed to the rasterio.merge method.

Returns:

The merged raster.

Return type:

rasterio.DatasetReader

Raises:

ValueError – If the specified method is other than ‘and’ and ‘sum’.