2

I am trying to change negative values (raster layer) into "0" but I cannot find a way to do that.

Does anyone know how to accomplish it in QGIS 3.2?

I found an answer somewhere on the Internet to use the Python console entering '0 if !field! < 0 else !field!' but I have no experience using Python.

3

I recommend Raster calculator.

If your raster layername is RasterA, then try (RasterA@1 >= 0) * RasterA@1

  • If the cell value is 0 or greater than 0, (RasterA@1 >= 0) returns 1 (i.e. True)
  • If the cell value is less than 0, (RasterA@1 >= 0) returns 0 (i.e. False).

In short, (RasterA@1 >= 0) acts as a Boolean mask.

  • Thanks, but I would like the values >0 to remain the original values and the values <=0 changed into 0. I used rastercalculator to create a raster where cells represent deviation from optimum pH. For negatives & 0 the pH is okay. – ClaKie Nov 1 '18 at 16:53
  • That's what this calculation does. The equation returns the original cell value when the original cell value is greater than or equal to zero. When the original cell value is less than zero, it returns 0. So all values less than zero are converted to zero, while all other values remain unchanged.. – csk Nov 1 '18 at 17:23
  • Thanks @csk ! Please excuse my lack of explanation, ClaKie. – Kazuhito Nov 1 '18 at 19:02

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.