Basic Raster Styling and Analysis (QGIS3)

A lot of scientific observations and research produces raster datasets. Rasters are grids of pixels that have a specific value assigned to them. By doing mathematical operations on these values, one can do some interesting analysis. QGIS has some basic analysis capabilities built-in via Raster Calculator. In this tutorial, we will explore the options available for styling rasters and functionality provided by the raster calculator.

Privire de ansamblu asupra activității

We will use population grid data to create a thematic map of the global population change between year 2000 and 2010.

Alte competențe pe care le veți dobândi

  • How to copy/paste styles between layers

Obținerea datelor

We will use the Gridded Population of the World (GPW) v4 dataset from Columbia University. Specifically, we need the Population Count for the entire globe at 2.5 Degree Minute resolution in GeoTiFF format and for the year 2000 and 2010. You will need a free Earth Data account to download the data.

../../_images/data125.png

Pentru comoditate, puteți descărca o copie a seturilor de date direct de la adresele de mai jos:

gpw-v4-population-count-rev11_2000_2pt5_min_tif.zip

gpw-v4-population-count-rev11_2010_2pt5_min_tif.zip

Sursa de date [GPW4]

Procedure

  1. Open QGIS and locate the downloaded files in the Browser panel. Expand the gpw-v4-population-count-rev11_2000_2pt5_min_tif.zip file and drag the gpw-v4-population-count-rev11_2000_2pt5_min.tif file to the canvas.

../../_images/1150.png
  1. A new layer gpw-v4-population-count-rev11_2000_2pt5_min will be added to the Layers panel. Similarly, locate the gpw-v4-population-count-rev11_2010_2pt5_min_tif.zip file and drag the gpw-v4-population-count-rev11_2010_2pt5_min.tif file to the canvas.

../../_images/2127.png
  1. Let’s explore these layers. Click the Identify button on the Attributes Toolbar. Once the tool is selected, click on any point on the canvas.

../../_images/365.png
  1. The value associated with that pixel will be displayed in a new Identify Results panel. In the Identify Results panel, change the Mode to Top down. This will display pixel values of all rasters instead of just the topmost layer. Compare the values from both the layers. As the resolution of the rasters is approximately 5km x 5km, the pixel values represent the total population in the area (25 sq. km) represented by the pixel.

../../_images/436.png
  1. Close the Identify Results panel. Let’s create a better visualization of the layers. Click the Open the layer Styling panel button in the Layers panel.

../../_images/532.png
  1. In the Layer Styling panel, click the Render type dropdown and select Singleband pseudocolor renderer.

../../_images/631.png
  1. This renderer will style the layer using a color ramp. The default color ramp is white-red where the minimum value will be assigned the white color and the maximum value in the layer will be assigned the red color. The intermediate values will be assigned a shade of red linear interpolation. Expand the Min / Max Value Settings and choose Cumulative count cut option. You will see that the map visualization is much better now. The standard data range is set from 2% to 98% of the data values, meaning that the outliers will not be used to set the minimum and maximum values, resulting in a much more representative visualization.

../../_images/731.png
  1. Close the Layer Styling panel. We can apply the similar styling to the other layer as well. But there is an easier way to transfer the styles from one layer to the other. Right-click the gpw-v4-population-count-rev11_2010_2pt5_min layer and select Styles ‣ Copy Style.

../../_images/830.png
  1. Now right-click the un-styled gpw-v4-population-count-rev11_2000_2pt5_min layer and select Styles ‣ Paste Style.

../../_images/931.png
  1. The same styling parameters will be applied to the other layer. This feature is particularly useful when you want to compare different layers using the same categorization. As you toggle the visibility of the top layer, you can see the changes in population visually.

../../_images/101.gif
  1. Our task is to create a thematic map of the changes in population. Let’s compute the difference between the 2 layers and create another raster where each pixel represents the change in the population. Go to Processing ‣ Toolbox.

../../_images/1151.png
  1. Look for Raster Calculator under Raster Analysis and double-click to open the tool.

../../_images/1240.png
  1. Select both the layers using button as Input Layers. The raster calculator can apply mathematical operations on the raster pixels. In this case we want to enter a simple formula to subtract the 2010 population from 2000. Enter the following expression using ε button. In the expression, The bands are named after the raster name followed by @ and band number. Since each of our rasters have only 1 band, you will see the names with @1 appended to the layer name. Keep all the other options as default and save the output layer with the name population_change_2010_2000.tif and click Run.

"gpw_v4_d_count_rev11_2010_2pt5_min@1"
- "gpw_v4_population_count_rev11_2000_2pt5_min@1"
../../_images/1338.png
  1. Once completed a new layer population_change_2010_2000 will be added to the Layers panel. Let’s change the styling so that the negative and positive population changes are better visualized. Click the Open the layer Styling panel button in the Layers panel.

../../_images/1435.png
  1. One option is to use the similar styling technique as earlier and choose a diverging color ramp. Click the Color ramp drop-down and select Spectral ramp. Click the drop-down again and choose Invert Color Ramp to assign blues to low values and reds to high values.

../../_images/1531.png
  1. This is a good visualization, but not easy to interpret. Let’s create a better map with 4 discrete categories, Decline, Neutral, Growth and High Growth. Scroll down to the tables with classes. Hold the Shift key and select all the rows. Click the Remove selected row(s) button.

../../_images/1629.png
  1. Change the Interpolation mode to Discrete. We will now create a color map manually. Click the Add values manually button. Enter -100 as the Value and Decline as the Label. Assign blue color to this category. The way color map works is that all values lower than the value entered will be given the color of that entry. You will notice the canvas will show only those areas with negative population change.

../../_images/1730.png
  1. Complete the color-map with suitable values. I chose 100, 1000 and 100000 as the upper-bounds for the Neutral, Growth and High Growth categories respectively. Assign colors to each of created categories, for example beige, orange and red.

../../_images/1826.png
  1. Once you are satisfied with the visualization, close the Layer Styling panel. You now have a global thematic map of population change.

../../_images/1921.png

If you want to give feedback or share your experience with this tutorial, please comment below. (requires GitHub account)