I am attempting to set the value of a pixel based on its current value. I am using the Raster Calculator in Quantum GIS dev 1.7 trunk.

For example, if the value is 0, I want to set it to 255.

Based on an example that I found, something like this should work, but it doesn't.

myRaster@1=0 255 

The RasterCalc plugin appears to use a function syntax, but that doesn't appear to be valid either

eq( myRaster@1, 0, 255)

Any suggestions? Thanks.


As far as I know, this kind of query is not possible with the built-in raster calculator but only with "RasterCalc" plugin by gis-lab.

RasterCalc syntax is:

eq( [relief]@1, 50, 200 )

Compare: http://gis-lab.info/qa/rastercalc-eng.html

  • That syntax doesn't work with the built-in Raster Calculator in v1.7. – DavidF Mar 4 '11 at 5:01
  • No, only with RasterCalc plugin. Two different things. Quite confusing, I think. – underdark Mar 4 '11 at 7:11

Technically I think you can do it. Say you wanted to assign 0 the value 255, 1 the value 142, 2 the value 719, and all other values to 0. I believe this would work:

((myRaster@1=0)*255 + (myRaster@1=1)*142 + (myRaster@1=2)*719)*(myRaster@1<3)

I used a similar approach to pull two values out of one raster, assign the composite raster 0 for both of those values, then do a specific calculation using two rasters for all other values in the first raster. I'm using QGIS 1.8.0.

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.