# How to sum or even perform more complex mathematical operations (multiply, add a constant, …) two GDAL grids?

I have two grids with same cell size, same starting position (top left) and same grid size. I want to sum the grids and create a sum grid as an result:

e.g. grid A + grid B = grid C

How can I achieve that with GDAL?

What happens, if my grids are not identical (1) in grid size (2) in starting position and (3) in cell size.

Thank you very much for the answer.

-

## 1 Answer

I am answering my own question:

You can use gdal_calc.py Python library to achieve this.

http://svn.osgeo.org/gdal/trunk/gdal/swig/python/scripts/gdal_calc.py

Here all the files have to be the same dimension. I still do not know how to accomplish this if grid's are not in the same size.

-
Raster 'mapematics' is essentially just maths using arrays. So, you need to make your rasters (and therefore the arrays) the same size, either by expanding the extent of one or both (depending on the overlap) or cropping to the limits of the overlap. You can do that either by manipulating the rasters or their array equivalents. You must consider carefully how you will handle NoData. The easy way to do this sort of operation is use QGIS which will handle the mismatch of the grids for you. – MappaGnosis Mar 6 '13 at 8:50