How can I change the pixel value from 0 to 10 on QGIS?
Allow me to rephrase the question "change the pixel value from 0 to 10" as follows;
- if the pixel value equals 0, then change it to 10.
- if the pixel value is not 0, then keep the original pixel value.
(1) The first one is expressed as ("YourRaster@1" = 0) * 10
.
- (A) when the pixel value is
0
, condition("YourRaster@1" = 0)
returnsTrue
which is1
. Then1 * 10
becomes10
. - (B) when the pixel value is not 0, condition
("YourRaster@1" = 0)
returnsFalse
which is0
. Then0 * 10
becomes0
.
(2) The second one is expressed as ("YourRaster@1" != 0) * ("YourRaster@1")
.
- (C) when the pixel value is
0
, condition("YourRaster@1" != 0)
returnsFalse
. Then0 * ("YourRaster@1")
becomes0
. - (D) when the pixel value is not
0
, condition("YourRaster@1" != 0)
returnsTrue
. Then1 * ("YourRaster@1")
becomes("YourRaster@1")
(i.e. your original pixel value).
(3) Finally, by putting these two together, ("YourRaster@1" = 0) * 10 + ("YourRaster@1" != 0) * ("YourRaster@1")
will work this way:
- When the pixel value is
0
, (A) + (C) becomes10 + 0
, which is10
. - When the pixel value is not
0
, (B) + (D) becomes0 + "YourRaster@1"
, which is the pixel value of your original raster.
("YourRaster@1" = 0) * 10 + ("YourRaster@1" != 0) * ("YourRaster@1")
– Kazuhito Feb 22 at 11:02