I am new to Qgis and also R, so I am struggling a bit... I have two raster layers of same resolution that perfectly align. One raster is DEM, and the other one is a binary forest map (forest = 1 , no forest = NA). All I have to do is to calculate the proportion of forest per elevation. Like, (how many pixels of forest fall in elevations between 0-50) divided by the (total number of pixels in the DEM that have the value between 0-50). How can I calculate this proportion (forest per elevation) in a automatic way?

  • You didn't ask a question? If you need help with something: Show what you already tried, show what you want to achieve, show a test case that illustrates your problem.
    – Senshi
    Commented May 29, 2017 at 11:57
  • I juts posted the question. Sorry for that. I have tried using R, but my results were not correct...
    – TFA
    Commented May 29, 2017 at 12:18
  • what do you mean by "in an automatic way"? do you want to process data multiple times and build a python tool? or rather by using available tools step-by-step?
    – dru87
    Commented May 29, 2017 at 14:18

1 Answer 1


I think SAGA Zonal raster statistics is the tool you are looking for.

This is a sample workflow I would suggest;

  1. Reclassify your DEM to zones (0~50m -> 1, 50~100m -> 2, ...) by Processing Toolbox | SAGA | Raster tools | Reclassify values (simple) which gives you a discrete raster
  2. Calculate zonal statistics between 2 rasters by Processing Toolbox | SAGA | Geostatistics | Zonal raster statistics. Assign your reclassified DEM to Zone Grids and your forest [0,1] raster to Categorical Grids. Then hit [Run].

QGIS(SAGA) will return a table Zonal Statistics which shows combinations of DEM zones, forest zones, and Count UCU which is the cell counts. After that, it will be easy to turn it into Area and/or calculate their proportion.

  • Please be careful SAGA is very fussy about the grid alignment. It may be advisable make a copy of reclassified DEM raster, burn forest onto it to ascertain that they are exactly same grid.
  • I am glad :) Let me know if you find troubles or difficulties in the workflow.
    – Kazuhito
    Commented Jun 1, 2017 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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