I am new to python and QGIS (have some experience with arcpy). I am trying to multiply two .tif files together using gdal_calc.py but I can't get it to work. It just returns the error invalid syntax. Here is the code. I am doing this in the QGIS Python command line.

gdal_calc.py -A people.tif -B places.tif --outfile=c:/test.tif --calc="A*B" --NoDataValue=0

I then tried this after reading an answer to another question, which ran and printed a number. However, it has not output a .tif file:

import os

gdal_calc =  'python C:/wheregdal_calc/islocated -Apeople.tif B-places.tif --outfile=c:/test.tif --calc="A*B"'
  • B-places.tif should be -B places – Ian Turton Aug 15 '18 at 15:16
  • thankyou for your response, changed this and still get the same result, a number prints but no output file is created – Issy Aug 15 '18 at 16:01
  • 1
    make sure you use a space before the filenames e.g. -A people.tif -B places.tif in the python version, same as the command line – Steven Kay Aug 15 '18 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.