-
Notifications
You must be signed in to change notification settings - Fork 9
/
09-raster-data.Rmd
78 lines (45 loc) · 4.54 KB
/
09-raster-data.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Raster Data
So far, we have only used Vector data with QGIS; this chapter will introduce raster data.
## What is the difference between raster and vector data.
Vector data is made up of points, lines, and polygons with attributes. This data structure makes it well suited to many GIS purposes. For example, we have already seen that the boundaries of an LSOA can be recorded as a polygon and that each polygon can have attributes like the area name, population etc.
Raster data is very different. It is essentially an image where each pixel has a value. Rasters are always rectangular and have a fixed resolution (so they become pixilated as you zoom in). A common use of raster data is satellite and aerial photography. These images are made from three overlapping rasters (often called a raster stack or raster brick). The three rasters represent the Red, Blue, Green colour bands which together make up a full-colour image. Raster can have more than three bands; for example, they may be used to represent changes over time or colours beyond human perception such as infra-red or ultraviolet.
## Download Sample Data
Download the sample raster data from here:
https://github.com/ITSLeeds/QGIS-intro/releases/download/0.01/leeds_cir_compress.tif
## Adding raster data to the map
Adding raster data to QGIS is done using the same data manager as vector data, except you must use the raster tab. You will notice that the raster contains an aerial photograph of Leeds, except the colours, appear to be wrong.
```{r raster-import, fig.cap="The sample raster data added to the map", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/raster-import.png")
```
The colour difference is due to this raster being a colour infrared image. Rather than the usual Red, Green, Blue bands this image has Near Infrared (NI), Red, Green.
## Normalized difference vegetation index
You may have noticed that the trees and grass in the raster appear bright red, but most other features appear grey. We shall use the raster to calculate the Normalized difference vegetation index (NDVI) a measure of how much vegetation is within each raster cell.
Within the "Raster" menu select "Raster Calculator" the formula for calculating the NVDI is:
$$\frac{NI - Red}{NI + Red}$$
Enter the formula into the raster calculator notice the use of @ to designate the different bands of the raster layer. Remember to specify where you want the results to be saved.
```{r raster-calc, fig.cap="The raster calcualtor with the NDVI formula", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/raster-calcualtor.png")
```
Once the raster calculator is complete, you should have a new raster layer. It will be in greyscale with values between -1 (least vegetated) and 1 most vegetated. You can adjust the symbology to make the vegetated areas clearer. In the figure, three colours are defined 0 (white), 0.2 (light green), 1 (dark green). These colours approximately make trees dark green, grass light green, and all non-vegetation white.
```{r ndvi, fig.cap="The NDVI raster with a psudo-colour scheme applied", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/ndvi.png")
```
## Linking Raster and vector data
Finally, we will link the NDVI raster back to the LSOA boundaries so that we can have an average vegetation score for each LSOA.
In the processing menu select "toolbox", this opens the processing toolbox panel on the right side. Use the search bar to find the "zonal statistics" tool.
```{r zone-stats1, fig.cap="The Zonal Statistics tool in the processing toolbox", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/zonal-statistics.JPG")
```
Complete the form to get statistics from the NDVI raster for each LSOA. When specifying the statistics to calculate select the mean.
```{r zone-stats2, fig.cap="The Zonal Statistics tool", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/zonal-statistics2.png")
```
Zonal statistics may take several minutes to run. Once completed, the mean NDVI value will be appended to the attribute table of the LSOA polygons.
Adjust the symbology of your LSOA layer to reflect the NDVI scores.
```{r lsoa-ndvi, fig.cap="LSOA areas with average NDVI scores", out.width="100%", echo=FALSE}
knitr::include_graphics("figures/lsoa-ndvi.png")
```
## Summary
This chapter has introduced raster data, the raster calculator, and zonal statistics.
**Bonus Exercises**
Consider how you could use the NDVI values to measure access to green spaces. How might you exclude small areas of green space such as gardens, but include large areas such as parks?