rasterio.merge module

Copy valid pixels from input files to an output file.

rasterio.merge.merge(datasets, bounds=None, res=None, nodata=None, precision=7, indexes=None, method='first')

Copy valid pixels from input files to an output file.

All files must have the same number of bands, data type, and coordinate reference system.

Input files are merged in their listed order using the reverse painter’s algorithm (default) or another method. If the output file exists, its values will be overwritten by input values.

Geospatial bounds and resolution of a new output file in the units of the input file coordinate reference system may be provided and are otherwise taken from the first input file.

Parameters
  • datasets (list of dataset objects opened in 'r' mode) – source datasets to be merged.

  • bounds (tuple, optional) – Bounds of the output image (left, bottom, right, top). If not set, bounds are determined from bounds of input rasters.

  • res (tuple, optional) – Output resolution in units of coordinate reference system. 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.

  • precision (float, optional) – Number of decimal points of precision when computing inverse transform.

  • indexes (list of ints or a single int, optional) – bands to read and merge

  • method (str or callable) –

    pre-defined method:

    first: reverse painting last: paint valid new on top of existing min: pixel-wise min of existing and new max: pixel-wise max of existing and new

    or custom callable with signature:

    def function(old_data, new_data, old_nodata, new_nodata):

    old_dataarray_like

    array to update with new_data

    new_dataarray_like

    data to merge same shape as old_data

    old_nodata, new_dataarray_like

    boolean masks where old/new data is nodata same shape as old_data

Returns

Two elements:

dest: numpy ndarray

Contents of all input rasters in single array

out_transform: affine.Affine()

Information for mapping pixel coordinates in dest to another coordinate system

Return type

tuple