I have some trouble with QGIS

I have two layers of information:

  • The first one a vector that contains 500 objects, with attributes such as number of population, and...
  • A raster that has three classes: degrade (-1), stable (0) and improvement (1), plus -9999 which corresponds to non-values

What I would like to obtain is in the attribute table of my vector layer, the percentage (area) of the three classes of my raster

something like this, in the row one : - the id, the population, the area of class 1, the area of class 2, the area of class 3. and so on for my other 500 lines.

I tried thing with Zonal statistics but I couldn't obtain what I wish.

  • Your question is a bit unclear. Do you want to know, how much of each feature belongs to each class? Or do you want to know, which portion of a class each features makes up? – Erik Dec 6 '18 at 15:24
  • more like each : which portion of a class each features makes up – laulau Dec 6 '18 at 15:30
  • A couple of weeks ago at the QGIS user group meeting in Cape Town someone asked something similar and he said he was using plugins.qgis.org/plugins/LecoS to compute the statistics but it has one limitation which is it does only one polygon at a time. But this can be easily solved by creating a script which loops through the features. The plugin is already available as a processing algorithm – kartoza-geek Dec 6 '18 at 16:27

The task you have has to be broken into smaller tasks as I doubt there is a single tool to do this. First I would export each raster class into a separate layer so it contains only pixels of that class and everything else is nodata. Second I would calculate the zonal statistics and make sure they produce column 'count'. Do this for each raster. Third create new column in the attribute table of the polygon layer and calculate the product of the count and area of your rasters pixel (x-resolution * y-resolution) for each class. Fourth calculate area of your polygon. Last fraction of the each class in the polygon should be easy enough to calculate.


| improve this answer | |

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.