What you want to do is the re-classify the raster before polygonizing. You can GRASS tool
r.recode for that (available in QGIS).
For a solution with raster calculator, see below.
You need a simple text-file defining the classes. Just copy the text below in a file and save it as
.txt file (you can use a text editor for that, as e.g. the simple Editor tool in Windows).
Menu Processing / Toolbox / r.recode, set the raster as input and the saved txt-file as
File containing recode rules.
You get a new raster as output, containing just five values (categories): 1 to 5. Than polygonize this raster to get your polygons.
Paste this text in an otherwise empty txt file. The first two numbers, devidid by
: define the range of values you want to group together to a new category, the last value is the numbering of the category:
Screenshot: A simple raster with random-values form 0.009 to 0.997 (see histogram on the right side). Recoded and vectorized. In the resulting vector layer,
category 5 =
very high is highlighted with red outlines and labeled accordingly: as you can see (especially in the cases marked with arrows), the red outlined polygons contain pixels with different values (shades of gray), but in a certain range (0.8 to 1):
Edit: to add another solution that correpsonds more to your initial idea:
Using raster calculator
Menu Raster / Raster calculator, paste this expression and run it:
("raster@1" * 1000 <= 200 ) *1 +
("raster@1" * 1000 <= 400 ) *1 +
("raster@1" * 1000 <= 600 ) *1 +
("raster@1" * 1000 <= 800 ) *1 +
("raster@1" * 1000 <= 1000 )*1
Explanation: There is no direct conditional implemented, but you can imitate it. For that evaluate if the pixel-value in case is smaller/equal than 0.2:
"raster@1" <= 0.2. This returns 1 for true, 0 for false. Multiply this by 1 and add further conditions in steps of 0.2: each time it is fulfilled, it adds 1. For pixel value 0.9, you thus have: 0+0+0+0+1= 1. Like this, you get an output-raster with 5 categories, inverse to the r.recode solution, category of smallest values getting highest category-code and the other way round.
However, raster calculator seems not to work properly with decimal numbers. Because of that, first multiply the values by 1000. Finally, polygonize as above.