TransWikia.com

Rendering only a specific fraction of raster values

Geographic Information Systems Asked by ptw716 on March 31, 2021

I have a raster where each pixel has a continuous value 0-1. I would like to indicate which 25% (for example) of the area corresponding to the raster contains the highest values i.e. indicate where the top 25% of values are located. Is it possible to do this somehow simply in Layer Properties using QGIS?

2 Answers

For a layer property method you can try the following:

In the symbology of your raster set render type to Singleband pseudocolor. Use mode Quantile. Change the number of classes to 4. Now make the lower 3 classes transparent by going into the colour settings and turning the opacity to 0%.

Answered by MarcM on March 31, 2021

If you're willing to try using GRASS-GIS, this operation is simple. GRASS has a module r.quantile for calculating any quantiles of a raster map. The default number of quantiles is four, so you get the first 25%, the first 50% (median value), and the 75% quantile. The output of this module is a list of the quantile values. This list can then be "fed" into an r.reclass statement to get the new reclassed raster with value 1,2,3,4 representing each of the four quantiles. If you want only the top 25%, you then run r.mapcalc on the reclassed raster to get only those pixels.

Here's how it goes from the GRASS command line, assuming I have a raster called srtm30:

# Use the -r option to r.quantile get output in the reclass format
micha@tp480:$ r.quantile -r srtm30
Computing histogram
 100%
Computing bins
Binning data
 100%
Sorting bins
Computing quantiles
-4094.000000:-2779.000000:1
-2779.000000:-1266.000000:2
-1266.000000:-48.000000:3
-48.000000:56.000000:4
 
# Now put those values into a reclass rules text file
echo "-4094 thru -2779 = 1 25%
-2779 thru -1266 = 2 50%
-1266 thru -48 = 3 75%
-48 thru 56 = 4 100%" > srtm_rcl.txt

# And run r.reclass with that rules file
micha@tp480:$ r.reclass srtm30 output=srtm_reclass rules=srtm_rcl.txt
micha@tp480:$ r.mapcalc "srtm_25pcent = if(srtm_reclass==1, srtm30, null())" 

The above r.mapcalc expression will set all pixels in the bottom 25 percentile to their original raster values, and all other pixels will be NULL. You can tune this to your needs, of course.

HTH

Answered by Micha on March 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP