I have several raster files (.tif) in a folder that have different resolution and extent but are all in the same study area.
Before merging them, I want to bring them to the same resolution (5 m) and extent. For this, I used the Raster Calculator inside of QGIS and manually defined Xmin, Xmax, Ymin and Ymax and the number of columns and rows. This solution worked fine and I could merge the resulting files.
I want to automate this processing with the Python Plugin, but so far I am not getting the correct results, because I struggling with defining the extent in the RasterCalculator. My code looks like this:
import os
pathin = r'C:\Documents\Raster_files'
pathout = r'C:\Documents\Processed'
filelist = os.listdir(pathin)
llc = QgsPointXY(319660,4624088)# lower left corner
urc = QgsPointXY(396425,4742843)# upper right corner
aoi = QgsRectangle(llc,urc)
for f in filelist:
lyr1 = QgsRasterLayer(f)
output = os.path.join(pathout,'5m_'+f)
entries = []
ras = QgsRasterCalculatorEntry()
ras.ref = 'ras@1'
ras.raster = lyr1
ras.bandNumber = 1
entries.append(ras)
calc = QgsRasterCalculator('ras@1', output, 'GTiff', aoi, 15353, 23751, entries)
calc.processCalculation()
So far, he is creating new files like expected but they are in a completetly wrong location and have values from -inf to +inf (probably because he does not use the UTM crs of the raster files). Does anybode have suggestions?
After this part is working, I intend to include gdal merging of the resulting files with very high compression.