Displaying rasters in QGIS

Back to home page

In ecology and wildlife studies, a lot of our spatial data takes the form of rasters rather than vector files. When you first add a raster in QGIS, you usually get a plain grey rectangle, or maybe just a grey outline on a white background, as most raster file formats have no styling information. To make sense of a raster, you need to change the style.

Here I'll give some hints for "quick-and-dirty" styling to display the contents of a raster. For a more detailed tutorial, see here.

How you style your raster depends on the type of data it shows:

You can download the example data here. Extract all the files to a folder on your hard drive. The files are rasters for land use (categorical) and distance from road (continuous), together with a .shp file with the roads.

Styling categorical data

Start up QGIS, go to Layer > Add Raster Layer (or use the toolbar button), and select the LandUse.asc file. It is an Arc/Info ASCII Grid file, which has no CRS information, so the Coordinate Reference System Selector box pops up: choose "WGS 84 / Pseudo Mercator", EPSG 3857.

A grey blob appears:


If you use the Identify Features tool (View menu) and click on different parts of the gray blob, you'll see the values range from 1 to 5. The white area has "null (no data)".

Open the Layer Properties box by double-clicking on LandUse in the Layers List, and go to the Style tab; the top part of the window is shown below. Our LandUse layer has only one band, so "Render as" = Single band gray and "Gray band" = Band 1.

The default for "Color map" is Grayscale. Change that to Colormap.

Now go to the Colormap tab:

Leave "Color interpolation" as Discrete, and look at the "Generate new color map" panel. Our map should have one entry for each level; if you're not sure how many levels there are, just set "Number of entries" to 2 or 3 and click Classify.

We now know that the lowest value is 1 and the highest 5. Change the number of entries to 5 and click Classify again:

Click OK and let's see the result:

That is better than the gray blob! And it might be all you need. In any case, save the project (File > Save Project) and give it a suitable name. The colours you have chosen will be stored in the project .qgs file; if QGIS closes unexpectedly, you do not have to do your work all over again.

If you want a prettier picture, you can edit the colours and legend labels. Go to Properties and the Colormap tab again. Double-click on a coloured box to change the colour and on a label to edit the label. You should of course know what the different levels mean to be able to put in proper labels.

This is my edited Colormap entry:

And the map looks like this:

Save the project again. If you want to use this style for other rasters with the same layers in future, you can use the Save Style button at the bottom of the Properties window.

Styling continuous data

Deactivate the LandUse layer, go to Layer > Add Raster Layer and select the DistanceFromRoad.tif file. It is a  GeoTIFF file which does have CRS information. This time we get a gray rectangle:

The Identify Features tool (View menu) shows that the values are large (5 digits or more), the distance of the pixel from a road in metres.

For a really quick-and-dirty view, go to the Properties box, Style tab, and set "Color map" to Pseudocolor. I also loaded the roads shape file and put that above DistanceFromRoad, to get this:

Pseudocolor gives you no control over the colour range, except for inverting the colours: check the box next to "Invert map color" at the top of the Style tab. The Freak Out option is similar to Pseudocolor, but with more striking colours. Neither is good for colour-blinds.

The Colormap option works as for categorical variables. On the Colormap tab, you'll probably want to set "Color interpolation" to Linear. With "Number of entries" =10 I got the following map:

Changing the default colours is not easy, though a simple range - say dark to light - can be achieved by using "Number of entries" = 2 and setting the first and last to the colours you want. With brown for the first and white for the last, I got this:

And here's the Colormap tab for that:

For more choice of colours and colour ranges, look at the plugins from bc-consult.

Updated 17 Dec 2012 by Mike Meredith