I am trying to align rasters in pyqgis (snap raster ArcMap equivalent).
There is a class reference in documentation, which is doing exactly what I need. QgsAlignRaster class.
Anyway, my problem is I can't get the extent right. If I put 2 rasters with different extent, like 2 overlapping rasters, the one which I want aligned will get clipped by the other, so I am missing almost half of the original raster.
Is there a way to set that I do not want to clip it?
My code is:
def alignRaster(raster, raster_to_align, output, proj, cell_size): alignClass = QgsAlignRaster() item1 = QgsAlignRaster.Item(raster, "") item2 = QgsAlignRaster.Item(raster_to_align, output) alignClass.setRasters([item1, item2]) alignClass.setParametersFromRaster(raster, proj) alignClass.setCellSize(cell_size,cell_size) alignClass.checkInputParameters() alignClass.createAndWarp(item2)
What i tried is setting the extent of raster with:
rLyr = QgsRasterLayer(raster) clipExtent = rLyr.extent() alignClass.setClipExtent(clipExtent)
I also tried setting clip extent to null, which is the default option I believe, since if I try to read the the clip extent, its says this:
print(alignClass.clipExtent()) >> <QgsRectangle: 0 0, 0 0>
I am out of ideas, is there a solution to my problem?
In the picture below, you can see how it gets clipped (gray raster is the new one)...