I want to align many rasters in some pixel size, extent and projection system using Python or PyQGIS.
First think is to use GDAL:
gdalinfo (to find information from reference raster)
gdalwarp (to convert projection system and pixel size)
gdal_translate (to convert extent)
They work, but it is not easy to use those tools together in Python and they need much time to finish this work. Also, it can be done easily using QGIS and Align Rasters Tool.
Does a tool doing this work using PyQGIS or Python exist? (I want to work more programming automatically)
UPDATE
I find this code from this question:
from osgeo import gdal, gdalconst
inputfile = #Path to input file
input = gdal.Open(inputfile, gdalconst.GA_ReadOnly)
inputProj = input.GetProjection()
inputTrans = input.GetGeoTransform()
referencefile = #Path to reference file
reference = gdal.Open(referencefile, gdalconst.GAReadOnly)
referenceProj = reference.GetProjection()
referenceTrans = reference.GetGeoTransform()
bandreference = reference.GetRasterBand(1)
x = reference.RasterXSize
y = reference.RasterYSize
outputfile = #Path to output file
driver= gdal.GetDriverByName('GTiff')
output = driver.Create(outputfile, x, y, 1, bandreference.DataType)
output.SetGeoTransform(referenceTrans)
output.SetProjection(referenceProj)
gdal.ReprojectImage(input, output, inputProj, referenceProj, gdalconst.GRA_Bilinear)
del output
That code works fine except raster clip. Any idea how to update this code to clip input raster to extent of reference raster in code?