2

I have a series of raster files (150 or so) that I need to multiply by a baseline raster. Unfortunately, the series of rasters have a different cell size (30m×30m i.e. .00027777778 degrees × .00027777778 degrees) than the baseline file (.1 degree × .1 degree).

I ran a test using qgis' raster calculator (which is under the menu path: raster->raster calculator...) and it worked fine as far as I can tell. That is, QGIS was able to reconcile the differing cell sizes and complete the action as expected. However, when I went to batch the process, I discovered its not possible — at least not from the GUI.

When I tried the SAGA, GRASS, and GDAL_CALC algorithms it appears the differing cell sizes are presenting issues. As a note, the basline file currently has a worldwide extent whereas the other files are smaller subsets.

Is there a way to call QGIS' raster calculator as a batch process or from a scripting language?

Example gdal_calculate input:

python gdal_calculate.py --outfile= C:/Users/asd/Documents/MangWork/TestImage/gdalcalcout.tif \
                         --calc "(han*adj)" \
                         --han=C:/Users/asd/Documents/MangWork/TestImage/cl_MEX_30N_110W.tif \
                         --adj=C:/Users/asd/Documents/MangWork/TestImage/Correction_Raster_Comp.tif \
                         --cellsize=MINOF
2

Why don't you change the cell size of the baseline file? If the resolutions are the same, you will be able to correctly use GRASS (and if it is the same region) or GDAL_CALC. In fact, it is what QGIS probably does before execute the multiplication.

Otherwise, you should consider using the Python Console with the QqgRasterCalculator Class: http://qgis.org/api/classQgsRasterCalculator.html.

  • Thanks for the response. I haven't converted the baseline file for a few reasons. 1) I was hoping that it would be easy(ish) to have the QGIS/GDAL mechanics do the heavy lifting for me. 2) If I resampled the whole thing, it would get really big really quick. 3) My random testing with QGIS tools have yet to provide me with a good way to get my baseline file to match the resolution (e.g. snap to raster) of my analysis rasters. I'd gladly take any suggestions. Also, I've tried using the console but I've not got it to work. Any thoughts? Thanks again. – dothatrumba Oct 28 '14 at 5:28
1

This is also my problem in subtracting two raster images with different dimensions. I also tried gdal_calc, tried QGIS raster calculator but as what you've said it isn't possible with batch processing. It happened that I also searched everywhere and asked everywhere, but they'll just say that subtracting images with two different dimensions isn't possible. Not until I found out gdal_calculate.py. I was able to subtract two raster images with different dimensions using this gdal utility. And one of its optional parameters is the --cellsize which I think what you need?

  • Thanks for forwarding this along! I don't suppose you have any advice on successfully loading and running the utility? I installed it (or at least I think I did) and despite some fiddling with the Path variable, directory changing etc, I can't get cmd to play nice. I basically get a whole bunch of cannot find errors. – dothatrumba Oct 28 '14 at 4:36
  • How did you install the gdal_calculate.py? – user Oct 28 '14 at 5:55
  • What are the bunch of errors you're getting? – user Oct 28 '14 at 7:14
  • If I run it straight from the command line, I get a "gdal_calculate is not recognized error." Adding the path to the env variables didn't appear to work. When I run cmd from the filepath of the script as a blank, something appears to happen but it provides no commentary. When I try to run it from the folder path it doesn't give an error so much as give no response. There is every chance I've mucked something up in the setup and therefore any advice about set up would be much appreciated. I've updated my question to include the code I was trying to feed into gdal_calculate. – dothatrumba Oct 28 '14 at 20:54
  • Tried that and an unfortunately it did not work. I tried copying the associated compiled python files (and environments and conversions) and ran into the same error (not recognized etc.). When I copied the files into my programfiles/GDAL folder (where the OS points to vis a vis PATH) I got an error about needing the environments and conversions dependancies. When I copied all of the files into the GDAL folder and typed gdal_calculate.py the cmd window paused for a second as if it was running something and then gave new line. Trying with an OSGEO4W install was also unsuccessful. Any thoughts? – dothatrumba Oct 30 '14 at 3:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.