2

I have a raster with different values (negative and positive). I want to color the raster based on a rule: All positive values have a certain color and all negative another. I don't want to use 'singleband pseudocolor' becuase it creates several values in the legend. I just need two values to show up in the legend (red for negative, blue for positive).

1

Unfortunately there is no rule-based option for raster files.

But you can do it the following:

enter image description here

Choose Singelband pseudocolor, set Min to -1 and Max to 1, create three classes and set the values. -1 will color all negative values, 0 all 0 values and 1 all positive values.

  • MrXsquared - can you explain the 'Value' column in the image above? I've worked with rasters and colour ramps several times and always find this column confusing. Above you have 499|500|501 - but what does this actually mean to QGIS? (I understand above what you say it will do in this case). What would happen, for example, if there was also a 450 category. Does that match anything above or below 450? Or does it match anything half way between 450 and 499? Or some other behaviour? After several years this remains one of the few aspects of QGIS that really beats me. – Rostranimin Feb 10 at 14:33
  • @Rostranimin In the case of my answer it works via the Min / Max Value Settings. When I set 499 as Min, everything below will be treated like it is 499 and everything above 501 will be treated like it is exactly 501. In your case it will still be a color ramp, but with only two classes: The color of 470 will be closer to the one of 450 than 499, but it will not exactly be that color. Don't know how to explain this in short. Best would be to try it out :) – MrXsquared Feb 10 at 17:37
  • Thanks. Had missed that you'd put in a min/max. I've used discrete(?) interpolation before. Played around with it a lot. Never worked out how to tell where the boundary would be between levels. No matter. Thanks for trying. – Rostranimin Feb 10 at 22:46

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.