Raster mosaic creation

remote_sensing_processor.mosaic(inputs, output_dir, fill_nodata=False, fill_distance=250, clip=None, crs=None, nodata=None, reference_raster=None, resample='average', nodata_order=False, match_hist=False, keep_all_channels=True)[source]

Creates mosaic from several rasters.

Parameters:
  • inputs (list of strings) – List of pathes to rasters to be merged or to folders where multiband imagery data is stored in order from images that should be on top to images that should be on bottom.

  • output_dir (path to output directory as a string) – Path where mosaic raster or rasters will be saved.

  • fill_nodata (bool (default = False)) – Is filling the gaps in the raster needed.

  • fill_distance (int (default = 250)) – Fill distance for fill_nodata function.

  • clip (string (optional)) – Path to vector file to be used to crop the image.

  • crs (string (optional)) – CRS in which output data should be.

  • nodata (int or float (default = None)) – Nodata value. If not set then is read from file or set to 0.

  • reference_raster (path to reference raster as a string (optional)) – Reference raster is needed to bring output mosaic raster to same resolution and projection as other data source. Is useful when you need to use data from different sources together.

  • resample (resampling method from rasterio as a string (default = 'average')) – Resampling method that will be used to reshape to a reference raster shape. You can read more about resampling methods here. Use ‘nearest’ if you want to keep only class values.

  • nodata_order (bool (default = False)) – Is needed to merge images in order from images with less nodata on top (they are usually clear) to images with most nodata values on bottom (they usually are most distorted and cloudy).

  • match_hist (bool (default = False)) – Is needed to match histograms of merged images. Improve mosaic uniformity, but change original data.

  • keep_all_channels (bool (default = True)) – Is needed only when you are merging Landsat images from different generations. If True, all bands are processed, if False, only bands that are present in all input images are processed and others are omited.

Returns:

List of paths to mosaic rasters.

Return type:

list of strings

Examples

>>> import remote_sensing_processor as rsp
>>> input_sentinels = ['/home/rsp_test/sentinels/L1C_T42VWR_A032192_20210821T064626/',
...                    '/home/rsp_test/sentinels/L1C_T42WXS_A032192_20210821T064626/',
...                    '/home/rsp_test/sentinels/L1C_T43VCL_A032192_20210821T064626/',
...                    '/home/rsp_test/sentinels/L1C_T43VDK_A031391_20210626T063027/',
...                    '/home/rsp_test/sentinels/L1C_T43VDL_A023312_20210823T063624/',
...                    '/home/rsp_test/sentinels/L1C_T43VDL_A031577_20210709T064041/']
>>> border = '/home/rsp_test/border.gpkg'
>>> mosaic_sentinel = rsp.mosaic(input_sentinels,
...     '/home/rsp_test/mosaics/sentinel/',
...     clip=border,
...     crs='EPSG:4326',
...     nodata_order=True,
... )
Processing completed
>>> print(mosaic_sentinel)
['/home/rsp_test/mosaics/sentinel/B1.tif',
 '/home/rsp_test/mosaics/sentinel/B2.tif',
 '/home/rsp_test/mosaics/sentinel/B3.tif',
 '/home/rsp_test/mosaics/sentinel/B4.tif',
 '/home/rsp_test/mosaics/sentinel/B5.tif',
 '/home/rsp_test/mosaics/sentinel/B6.tif',
 '/home/rsp_test/mosaics/sentinel/B7.tif',
 '/home/rsp_test/mosaics/sentinel/B8.tif',
 '/home/rsp_test/mosaics/sentinel/B8A.tif',
 '/home/rsp_test/mosaics/sentinel/B9.tif',
 '/home/rsp_test/mosaics/sentinel/B11.tif',
 '/home/rsp_test/mosaics/sentinel/B12.tif']
>>> lcs = glob('/home/rsp_test/landcover/*.tif')
>>> print(lcs)
['/home/rsp_test/landcover/ESA_WorldCover_10m_2020_v100_N60E075_Map.tif',
 '/home/rsp_test/landcover/ESA_WorldCover_10m_2020_v100_N63E072_Map.tif',
 '/home/rsp_test/landcover/ESA_WorldCover_10m_2020_v100_N63E075_Map.tif']
>>> mosaic_landcover = rsp.mosaic(
...     lcs,
...     '/home/rsp_test/mosaics/landcover/',
...     clip=border,
...     reference_raster='/home/rsp_test/mosaics/sentinel/B1.tif',
...     nodata=-1,
... )
Processing completed
>>> print(mosaic_landcover)
['/home/rsp_test/mosaics/landcover/ESA_WorldCover_10m_2020_v100_N60E075_Map_mosaic.tif']