1

I need to calculate the quartile value (e.g. 75%) of the pixels of a raster layer within a polygon file. I try to do that using QGIS, and found that the zonal statistics might be able to do that. But I only find the below options with the zonal statistics: Count; Sum; Mean; Median; StDev; Min; Max; Range; Minority; Majority; Variety.

Any solution to calculate the quartile value in QGIS?

1

You can use GRASS processing algorithms from withing QGIS. v.rast.stats should do what you require.

You could also probably use QGIS' native Zonal histogram but then you'd have to process the output yourself to find the quartiles from the unique value counts.

If you have only one polygon, or want it done over all of the raster which is covered by the union of the polygon features, you could clip the raster by the vector layer and then use GRASS r.stats, or QGIS native Raster layer histogram.

| improve this answer | |
  • Thanks. v.rast.stats seems work. I am running that now. – Jian Zhang Jan 28 at 15:41
  • Good to hear. Be careful about NODATA pixels, if that's relevant. GRASS and native QGIS don't always seamlessly communicate on what are NODATA values and this could throw off quantiles if present in your data set. – Houska Jan 28 at 16:08
  • Now I have another question. I use "v.rast.stats" to calculate the "third_quartile" for a multipolygon file. I realize that it generates a lot of rows for each species (could be the same length with the occupied raster cells for each species). That makes the results really long, and the size is huge. Is there any way to only generate one row for each species? – Jian Zhang Jan 30 at 5:49
  • @JianZhang, sorry this is exceeding my ability to visualize. However, you could try converting the multipolygons to polygons. And/or dissolving them? GRASS does polygons differently than QGIS ("topologically", as a tiling of the mapping region with no gaps, overlaps etc), so I'd be a bit leery of throwing multipolygons into the mix. And maybe run Fix geometry on the vector layer? Just ideas... – Houska Jan 30 at 12:30

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.