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, write_stac=True)[source]
Creates mosaic from several rasters.
- Parameters:
inputs (list of strings or list of STAC Items) – List of pathes to rasters to be merged or to folders where multiband imagery data is stored or to STAC Items 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 a 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 inputs.
reference_raster (string or STAC Item (optional)) – Reference raster is needed to bring output mosaic raster to the same resolution and projection as another data source. It 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 reproject and reshape to a reference raster shape. You can read more about resampling methods here. Use ‘nearest’ if you want to keep only the same values that exist in the input raster.
nodata_order (bool (default = False)) – Is it needed to merge images in order from images with less nodata on top (they are usually clear) to images with more nodata values on bottom (they are usually the most distorted and cloudy).
match_hist (bool (default = False)) – Is it needed to match histograms of merged images. Improve mosaic uniformity, but change the original data.
keep_all_channels (bool (default = True)) – Is needed only when you are merging images that have different number of channels (e.g., 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 omitted.
write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.
- Returns:
Path to mosaic rasters.
- Return type:
pathlib.Path
Examples
>>> # Mosaic multiple Sentinel 2 multi-band products >>> import remote_sensing_processor as rsp >>> input_sentinels = [ ... "/home/rsp_test/sentinels/Sentinel1/meta.json", ... "/home/rsp_test/sentinels/Sentinel2/meta.json", ... "/home/rsp_test/sentinels/Sentinel3/meta.json", ... "/home/rsp_test/sentinels/Sentinel4/meta.json", ... "/home/rsp_test/sentinels/Sentinel5/meta.json", ... "/home/rsp_test/sentinels/Sentinel6/meta.json", ... ] >>> border = "/home/rsp_test/border.gpkg" >>> mosaic_sentinel = rsp.mosaic( ... inputs=input_sentinels, ... output_dir="/home/rsp_test/mosaics/sentinel/", ... clip=border, ... crs="EPSG:4326", ... nodata_order=True, ... ) Processing completed >>> print(mosaic_sentinel) '/home/rsp_test/mosaics/sentinel/S2A_MSIL2A_20210821T064626_N0209_R063_T42VWR_20210821T064626_mosaic.json'
>>> from glob import glob >>> # Mosaic multiple DEM files and matching it with a reference raster (Sentinel band) >>> 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( ... inputs=lcs, ... output_dir="/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.json'