3

I have a raster showing a map with a lot of fine-scale structure (water depths and rivers) in QGIS, and I'd like to make the structure visible when the plot is low resolution.

Up close, I have beautiful plots showing connected flow paths:

Zoomed-in river map

However, when I zoom out, the water appears pixelated and the flow paths and connections are completely lost:

Zoomed-out river map

Is there a way I can change the image rendering to make the water appear connected at any resolution?

1
2

It would be helpful if you include a sample dataset with your question next time.

That said, I've acquired a river map from the World Resources Institute's Aqueduct Floods Hazard Maps; specifically, this one.

When we first load this data into QGIS we see pretty much nothing: No rivers visible in QGIS

So our first step is to change the colour of water to blue. We do this by right-clicking on the layer in question and clicking Properties, or simply by double-clicking on the layer's colour scale. We then select the "Blues" colour ramp.

QGIS with blues but no contrast

Next, note the range of the data: it's from 0 to 32. According to the documentation this represents "inundation depth in meters for coastal and riverine floods".

But, when it comes to rivers, our default assumption should always be that the datasets associated with them will have strong nonlinearities. To understand why consider that a river network is formed by, roughly speaking, by rivers of approximately equal size joining together to form a single river that's twice as large. If you repeat this process a few times you end up with an exponential size distribution. Strahler numbers quantify this. The result is something like this:

Mean water discharge in cubic kilometers per year

These exponentials don't just hold for volume: they also apply to other dimensions of rivers:

Channel dimension by drainage area

The implication is that using a linear color scheme with rivers will almost always be a bad choice. And so it is here. Looking at the histogram of your data shows a clear exponential curve:

Exponential curve in river data

The best way to deal with this would be to use a logarithmic transform on the data; however, QGIS does not currently offer this as an option for rasters and no one seems to have backed up the source code for the one plug-in that provided this option.

No matter, we can deal with it by asking QGIS to choose a more appropriate data range by throwing out outliers. To do so we:

  1. Select "Min/Max Value Settings" in the layer's Symbology menu.
  2. Select Cumulative count cut with 2% and 98% as the bounds (adjustable), choose the whole raster as the statistics extent, and use "Estimate" for accuracy (otherwise the operation will be very slow):

Throwing out outliers

This shows us a range of 0 - 0.4419744.

Now, we reclassify our data by hitting the "Classify" button below the color-value menu:

Reclassify

Note that we do not select "Clip out of range values". This would make the big numbers all disappear. What we want, instead, is for them to saturate on our colour scale.

This leaves us with the a choppy, pixelated image not unlike the first image you show as being "beautiful plots showing connected flow paths". If you look at the smaller rivers on the left-hand side (closer to the United Provinces and moving towards the Punjab) there's actually significant disconnection.

Pixelated rivers

The reason is that the smaller rivers are often only a single pixel wide and, by default, QGIS uses "Nearest Neighbour" resampling because it is fast. Nearest neighbour is going to (essentially) assign the value of the pixel in the zoomed out map based on a single pixel value from the zoomed in map and, odds are, it's going to miss the rivers we're interested in.

To fix this, we want to instead use something like "Bilinear" or "Cubic" resampling, like so:

Using cubic resampling

I achieved my best-looking results by using Cubic resampling with 6.0 oversampling and no early resampling.

The effect of nearest neighbour, bilinear, and cubic sampling is better seen here:

Nearest neighbour, bilinear, and cubic sampling

And the effect of oversampling can be seen in the right two images here:

Oversampling demo

This answer goes into much more detail about these settings.

The final map is something that looks good at most resolutions:

enter image description here

enter image description here

enter image description here

enter image description here

Except the inner most zooms. At this point cubic or bilinear interpolation is actually going to blur the image because we can visually resolve the individual pixels underlying the data at this point:

enter image description here

The solution is to switch back to nearest neighbour interpolation at this point:

enter image description here

1
  • 1
    Great! A real tutorial and extremly helpful. – Babel Apr 6 at 6:22

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.