How sum two raster with different shapes?


Anderson Roberto da Silva
 

Hi, I'm developing a system and I need sum two raster with different shapes.
I've a DEM raster with a resolution of 30 meters and another raster with a resolution of 10 meters, both clipped in the same area by a polygon.

When I trying sum the rasters I get the error: ValueError: operands could not be broadcast together with shapes.

I know that rasterio read raster as numpy array, but If I use the Raster Calculator from QGIS software, I can sum the rasters without problem.

I would like sum the rasters without use command line, e.g. rio calc or gdal_calc.py, but I not found a example to implement this.

Thank's for any help.


Amine Aboufirass <amine.aboufirass@...>
 

You can't sum rasters with different shapes. Resample your rasters to a common resolution and align them so that they can be read as arrays with the same shape, then add the two arrays together and write to a new raster.


On Tue, 18 Aug 2020, 19:03 , <byander@...> wrote:

Hi, I'm developing a system and I need sum two raster with different shapes.
I've a DEM raster with a resolution of 30 meters and another raster with a resolution of 10 meters, both clipped in the same area by a polygon.

When I trying sum the rasters I get the error: ValueError: operands could not be broadcast together with shapes.

I know that rasterio read raster as numpy array, but If I use the Raster Calculator from QGIS software, I can sum the rasters without problem.

I would like sum the rasters without use command line, e.g. rio calc or gdal_calc.py, but I not found a example to implement this.

Thank's for any help.


Anderson Roberto da Silva
 

Thank's Amine. I create a function to resample the raster keeping the extents and resolution to calc with other rasters.