1

I'm trying to perform a laborious task to get the class values of a raste overlaid on a multi-part shapefile.

I have a raster with values rated from 0 to 8 for a Main Basin. I also have a shapefile with 3 sub-basins of this main basin.

I would like to calculate the value of the raster classes according to the overlay sub-basin.

For example: shapefile sub-basins: A; B and C. Raster class: 0 to 8

For class 0 what is the area value for sub-basin A?

enter image description here

enter image description here

enter image description here

In QGIS I know there is r.report, however it only does this for a mono-part shapefile (one polygon).

Would there be any tool in qgis that would do this for multiple polygons?

1
  • 1
    Try zonal histogram
    – BERA
    Jun 4 at 17:02
1

You can use Zonal histogram then transpose the output using for example excel or python pandas:

Zonal histogram output, the output raster categories become columns: enter image description here

Export to csv and transpose:

import pandas as pd
csvfile = r'/home/bera/Desktop/tempgis/output_zonal_hist.csv' #Change to the exported output from Zonal histogram
subbasin_id_field = 'subbasin' #Name of your subbasin id field

df = pd.read_csv(csvfile)
df2 = df.set_index(subbasin_id_field).transpose()
df2.index.name='rasterval'
df2.to_csv(r'/home/bera/Desktop/tempgis/output_zonal_hist_transposed.csv')

enter image description here

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.