When multiplying two rasters together using code in PyQGIS, the resultant raster is much larger than expected.
Each input raster takes up ~ 11KB as .tif
files, but when I multiply two together it becomes a much larger .tif
file, nearly 20MB, which seems way too big considering the input sizes.
Here is my code below to create the 20MB output raster:
expression = "r1@1 * r2@1"
combinedExtent = self.getCombinedExtent(layerList)
calc = QgsRasterCalculator(expression, outputPath, 'GTiff', combinedExtent, mainRaster.crs(), mainRaster.width(), mainRaster.height(), layerReferences)
calcResult = calc.processCalculation()
intersectLayer = QgsRasterLayer(outputPath, "Combined Raster layer")
With outputPath
being where the output raster is saved, combinedExtent
being the overall extent of both rasters in the calculation, and mainRaster
being the overall background raster that both of the smaller rasters to be multiplied lie upon.
Below are the rasters used for multiplication, r1
and r2
, which are each roughly 14KB in size:
When multiplied with a similar raster, r2
, the following is created, displaying the area of intersect between the two rasters:
But this file is roughly 20MB in size, which seems way too big considering the small size of both input rasters.
Hopefully you can download r1
and r2
as .tifs
as attached and see the same issue with PyQGIS.