Quantcast
Channel: Active questions tagged raster-calculator - Geographic Information Systems Stack Exchange
Viewing all articles
Browse latest Browse all 190

PyQGIS - Raster multiplication creates too large a file

$
0
0

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:

r1, one of the rasters used for calculationr2, the other raster used for calculations

When multiplied with a similar raster, r2, the following is created, displaying the area of intersect between the two rasters:Raster output from multiplying two rastersBut 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.


Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>