I got a problem with gdal.wrap - it works REALLY slow. On 10m raster of Poland, matching the origin of 2 rasters takes like 30 minutes.
Is there an easy and fast way to take 2 rasters (of different origins) and to load their overlapping part into the numpy arrays?
Rasters are having the same resolution and crs.
def run_mosaic_script(self, resample_alg: any = None, x_res=13.9, y_res=13.9, compress_algorithm="LZW",
dstSRS="EPSG:32634") -> bool:
"""
Method for run mosaic script
:param compress_algorithm: compression algorithm example LZW
:type compress_algorithm: str or None
:param resample_alg: resample algorithm
:type resample_alg: any
:param x_res: x resolution of pixel
:type x_res: numeric (int or float) or None
:param y_res: resolution of pixel
:type y_res:numeric (int or float) or None
:return: True if correct, False if incorrect
:rtype: bool
"""
creation_option: List[str] = ["BIGTIFF=YES"]
if compress_algorithm is not None:
creation_option.append("COMPRESS=" + compress_algorithm)
gdal_warp_options = gdal.WarpOptions(srcNodata=0, dstNodata=0, multithread=True,
warpOptions="NUM_THREADS=ALL_CPUS", xRes=x_res, yRes=y_res,
dstSRS=dstSRS,
resampleAlg=resample_alg, creationOptions=creation_option,
cutlineDSName=self.shp_file.__str__(), cropToCutline=True,
overviewLevel='AUTO')
image_to_mosaic: list = list()
for file_name in self.input_image_list:
image_to_mosaic.append(file_name.__str__())
gdal.Warp(destNameOrDestDS=self.output_image.__str__(),
srcDSOrSrcDSTab=image_to_mosaic,
options=gdal_warp_options)
return True
I am just cropping it to some simple extent. Both of the rasters.
merge
module that makes this easy: rasterio.readthedocs.io/en/latest/api/rasterio.merge.html