In QGIS 2.18.12 (qt4) on Linux, I repeatedly observe strange legend behaviour when new layers are loaded or generated using the Raster Calculator.

The legend will show colours for two classes (values). In the display window, the colours are apparently reversed.

See the following image: QGIS legend colour mapping

At 1, we see that in the legend, nan is black and 0 is white.

At 2, I am clicking on the black field in the mgrid layer.

At 3, the value is 0. If I click outside the black field, the value is nan, which is the opposite of the expected behaviour.

If I reverse the gradient in Properties | Style | Band rendering, then the legend is "corrected" (nan is transparent, 0 is black) but in the display window, there are no discernable fields at all:

Legend correct, no discernable fields in image

Updating the min/max statistics (with load min/max values) in the band rendering settings fills both fields with 0 and results in a legend that looks like this:

No gradient in legend

The image does not change (it is as it is in the first image above).

What causes this, and how do I fix it?

  • 1
    Could be a bug. Have you tried right-clicking your layer and going to Properties > Style. Assuming your Render type is Singleband gray, try changing the Colour gradient to Whilte to black instead of the default Black to white. – Joseph Aug 29 '17 at 10:14
  • Does it help if you update the min/max statistics for the raster no the Style Properties tab? – mixedbredie Aug 29 '17 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.