QGIS Planet

Shapeburst fill styles in QGIS 2.4

With QGIS 2.4 getting closer (only a few weeks away now) I’d like to take some time to explore an exciting new feature which will be available in the upcoming release… shapeburst fills!

As a bit of background, QGIS 2.2 introduced a gradient fill style for polygons, which included linear, radial and conical gradients. While this was a nice feature, it was missing the much-requested ability to create so-called “buffered” gradient fills. If you’re not familiar with buffered gradients, a great example is the subtle shading of water bodies in the latest incarnation of Google maps. ArcGIS users will also be familiar with the type of effects possible using buffered gradients.

Gradient fills on water bodies in Google maps

Gradient fills on water bodies in Google maps

Implementing buffered gradients in QGIS originally started as a bit of a challenge to myself. I wanted to see if it was possible to create these fill effects without a major impact on the rendering speed of a layer. Turns out you can… well, you can get pretty close anyway. (QGIS 2.4’s new multi-threaded responsive rendering helps a lot here too).

So, without further delay, let’s dive into how shapeburst fills work in QGIS 2.4! (I’ve named this fill effect ‘shapeburst fills’, since that’s what GIMP calls it and it sounds much cooler than ‘buffered gradients’!)

Basic shapeburst fills

For those of you who aren’t familiar with this fill effect, a shapeburst fill is created by shading each pixel in the interior of a polygon by its distance to the closest edge. Here’s how a lake feature polygon looks in QGIS 2.4 with a shapeburst from a dark blue to a lighter blue colour:

A simple shapeburst fill from a dark blue to a lighter blue

A simple shapeburst fill from a dark blue to a lighter blue

You can see in the image above that both polygons are shaded with the dark blue colour at their outer boundaries through to the lighter blue at their centres. The screenshot below shows the symbol settings used to create this particular fill:

A simple shapeburst fill from a dark blue to a lighter blue

Creating a simple shapeburst fill from a dark blue to a lighter blue

Here we’ve used the ‘Two color‘ option, and chosen our shades of blue manually. You can also use the ‘Color ramp’ option, which allows shading using a complex gradient containing multi stops and alpha channels. In the image below I’ve created a red to yellow to transparent colour ramp for the shapeburst:

Colour ramp shapeburst with alpha channels

Colour ramp shapeburst with alpha channels

Controlling shading distance

In the above examples the shapeburst fill has been drawn using the whole interior of the polygon. If desired, you can change this behaviour and instead only shade to a set distance from the polygon edge. Let’s take the blue shapeburst from the first example above and set it to shade to a distance of 5 mm from the edge:

Shapeburst fills can shade to a set distance only

Shapeburst fills can also shade to a set distance from the polygon’s exterior

This distance can either be set in millimetres, so that it stays constant regardless of the map’s scale, or in map units, so that it scales along with the map. Here’s what our lake looks like shaded to a 5 millimetre distance:

Shading to 5mm from the lake's edge

Shading to 5mm from the lake’s edge

Let’s zoom in on a portion of this shape and see the result. Note how the shaded distance remains the same even though we’ve increased the scale:

Zooming in maintains a constant shaded distance

Zooming in maintains a constant shaded distance

Smoothing shapeburst fills

A pure buffered gradient fill can sometimes show an odd optical effect which gives it an undesirable ‘spiny’ look for certain polygons. This is most strongly visible when using two highly contrasting colours for the fill. Note the white lines which appear to branch toward the polygon’s exterior in the image below:

Spiny artefacts on a pure buffered gradient fill

Spiny artefacts on a pure buffered gradient fill

To overcome this effect, QGIS 2.4 offers the option to blur the results of a shapeburst fill:

Blur option for shapeburst fills

Blur option for shapeburst fills

Cranking up the blur helps smooth out these spines and results in a nicer fill:

Adding a blur to the shapeburst fill

Adding a blur to the shapeburst fill

Ignoring interior rings

Another option you can control for shapeburst fills is whether interior polygon rings should be ignored. This option is useful for shading water bodies to give the illusion of depth. In this case you may not want islands in the polygon to affect their surrounding water ‘depth’. So, checking the ‘Ignore rings in polygons while shading‘ option results in this fill:

Ignoring interior rings while shading

Ignoring interior rings while shading

Compare this image with the first image posted above, and note how the shading differs around the small island on the polygon’s left.

Some extra bonuses…

There’s two final killer features with shapeburst fills I’d like to highlight. First, every parameter for the fill can be controlled via data defined expressions. This means every feature in your layer could have a different start and end colour, distance to shade, or blur strength, and these could be controlled directly from the attributes of the features themselves! Here’s a quick and dirty example using a random colour expression to create a basic ‘tint band‘ effect:

Using a data defined expression for random colours

Using a data defined expression for random colours

Last but not least, shapeburst fills also work nicely with QGIS 2.4’s new “inverted polygon” renderer. The inverted polygon renderer flips a normal fill’s behaviour so that it shades the area outside a polygon. If we combine this with a shapeburst fill from transparent to opaque white, we can achieve this kind of masking effect:

Creating a smooth exterior mask using the "inverted polygons" renderer

Creating a smooth exterior mask using the “inverted polygons” renderer

This technique plays nicely with atlas prints, so you can now smoothly fade out the areas outside of your coverage layer’s features for every page in your atlas print!

All this and more, coming your way in a few short weeks when QGIS 2.4 is officially released…

Colour shortcuts in QGIS 2.4

Quick poll… what’s the most frustrating thing about GIS? Fighting with colour plotters? Trying to remember GDAL command line syntax? MapInfo’s new ribbon interface* [1]? All of the above?

Wrong!

It’s getting a colour from here:

colour1

…all the way over to here:

colour2

Since the dawn of GIS humanity has struggled with this simple task* [2]. We’ve come up with multiple techniques for solving this problem, ranging from the RSI inducing “select and copy red value, alt-tab, paste, alt-tab, select and copy green value, alt-tab, paste, etc….” method, through to chanting “70, 145, 160… 70, 145, 160… 70, 145, 150… 70, 145, 150” to ourselves as we frantically try and rearrange dialogs to find the destination colour picker, all the while avoiding strange looks from co-workers.

Fortunately, QGIS 2.4 is coming to the rescue! Now, you can right click on any of QGIS’ colour picker buttons for a handy copy/paste colour shortcut menu. Pasting colours works from a whole range of formats, including hex codes, color names, and css-style “rgb” and “rgba” strings.

Fixed!

Problem solved!

Even better, you can just drag colours from one colour button to another:

Fixed again...

… and solved again…

Or, drag a colour from GIMP and drop it onto a QGIS colour button:

x

… and yet again!

Or even drag a colour from a QGIS button directly onto a shape in Inkscape! All this win is coming your way in QGIS 2.4, due June 2014.

[1] Pre-empting the inevitable flood of complaints when this new interface is rolled out
[2] I assume

And now… colour preview modes in QGIS’ map canvas

As a quick follow-up to my last post on colour preview modes for the print composer in QGIS 2.4, this feature has also been added to the main map canvas window! Now it’s even easier to adjust your symbol colours and immediately see how they’d appear under a range of different circumstances:

Colour previews modes for the map canvas

Colour previews modes for the map canvas

 

Colour blindness and grayscale previews in QGIS 2.4

Since QGIS 2.4 is nearing feature freeze it seems like a good time to start exploring some of the great new features in this release. So, let’s get started with my most recent addition to QGIS’ print composer… preview modes!

As every first year cartography text book will tell you, it’s important to know your target media and audience when creating a usable map. Some important considerations are whether or not your map will be photocopied or printed in black and white, and whether you need to consider colour blind map readers in your audience. In the past, designing maps with these considerations has been a time consuming, tedious process. You’d have to export your map, open it in another graphics editing program, apply some colour transform, work out what issues there are, flip back to QGIS, make your changes and repeat. If you’re working with a tight deadline it can be difficult to justify the time this all takes.

QGIS 2.4 will help to make this whole process a lot simpler. In the print composer there’s now an option to enable a number of different live “preview modes“. These include grayscale, monochrome, and two colour blindness simulations (Protanope and Deuteranope).

Composer preview modes in QGIS 2.4

Composer preview modes in QGIS 2.4

These preview modes are live, so you can continue to edit and tweak the colours in your composition while a preview mode is active! For a quick demonstration, let’s start with this creatively coloured thematic map:

bad_colored_map

While it might not be the most aesthetically pleasing map, at least the thematic colours can be easily matched to their corresponding values in the legend. Let’s see what would happen if we photocopied this map. This is as easy as activating the “Simulate photocopy (grayscale)” preview mode:

greyscalepreview

Hmm… not so usable now. The five thematic colours have been reduced to just three discernible colours. Oh well, at least we haven’t had to export our map to find this out, and it’s nice and easy to adjust the colours and composition to work for photocopies without having to leave QGIS to test the results!

Let’s see how this map would look to someone with colour blindness, by activating the “Simulate colour blindness (Protanope)” mode:

color_blindness

In this case, our map isn’t too bad. The different classes are still discernible and the map can be interpreted by someone with protanopia.

So there we have it – now it’s easy to determine how our map outputs will look under different circumstances and adjust them to suit! Composer preview modes will be a part of the upcoming 2.4 release of QGIS, which is due out at the end of June 2014.

Update:

This feature has also been added to the main map canvas.

Back to Top

Sustaining Members