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?
I think SAGA
Zonal raster statistics is the tool you are looking for.
This is a sample workflow I would suggest;
- 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
- Calculate zonal statistics between 2 rasters by
Processing Toolbox | SAGA | Geostatistics | Zonal raster statistics. Assign your reclassified DEM to
Zone Gridsand 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.