-
Notifications
You must be signed in to change notification settings - Fork 9
/
08-Vector-processing.Rmd
129 lines (74 loc) · 4.99 KB
/
08-Vector-processing.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Processing vector data
We saw in Chapter \@ref(style-and-select-features) how to style and select features of interest from layers loaded into QGIS.
In this section, we will learn how to process data.
That means creating new data from existing data.
```{block2, type="rmdnote"}
You must have loaded data and have done the exercises in the previous chapters, particularly loading the data in Chapter \@ref(data), before proceeding.
```
## Reprojecting Data
Two of the three geographic datasets loaded in Chapter \@ref(data) have different coordinate systems. This can make it challenging to make connections between the datasets. So we will reproject the stats19 data to the British National Grid.
In the vector, menu select Data management Tools, Reproject Layer.
```{r reproject-menu, out.width="100%", fig.cap="Reproject Menu", echo=FALSE}
knitr::include_graphics("figures/reproject.png")
```
Then select the British National Grid as the target CRS. If it is not listed in the drop-down menu, then use the button to the right to open the Coordinate Reference System menu. You can use the search box to search for a CRS by name or its EPSG code.
```{r crs-menu, out.width="100%", fig.cap="Reproject Menu Coordinate Reference System", echo=FALSE}
knitr::include_graphics("figures/crs.png")
```
## Joining Data
Joining data allows you to link two separate datasets together by something they have in common. There are two types of join. Attribute joins (often just called joins) link two datasets by a common attribute such as an ID number. Spatial joins link datasets by a shared location.
In this next section, we will use a series of joins to find the area of Leeds with the highest rate of road collisions.
### Attribute Joins
We will join the population data onto the LSOA boundaries.
Find "leeds_lsoa" in the Layers panel and right-click to bring up the context menu.
Click on Properties
Select Joins from the options on the left.
Click the green + button to open the Add Vector Join window.
Select the following options:
Join layer: population
Join field: area
Target field: lsoa11cd
Click OK,
Click OK again
```{r joins, out.width="100%", fig.cap="The Add Vector Join window", echo=FALSE}
knitr::include_graphics("figures/joins.jpg")
```
Use the "Identify features" tool to see that each LSOA now has a population value.
### Spatial Joins
We will assign an LSOA ID number to each road collision by doing a spatial join.
In the Vector Menu, select Data Management Tools, Select Attributes by location, as shown in \@ref(fig:joins-menu).
```{r joins-menu, out.width="100%", fig.cap="Join Attributes by Location", echo=FALSE}
knitr::include_graphics("figures/spatial_joins.jpg")
```
For the Input Layer select "stats19" and for the output later select "leeds_lsoa". For join type select "Create separate feature of each located feature". Then click "Run in Background", as shown in \@ref(fig:joins-window).
```{r joins-window, out.width="100%", fig.cap="Join Attributes by Location Window", echo=FALSE}
knitr::include_graphics("figures/spatial_joins_window.jpg")
```
Once the process has completed a new layer will have been added to the map called "joined Layer" you can use the "Identify Features" tool to see that each point in the stas19 data now has the new field lsoa11cd containing the LSOA id number for each point in the stats19 data. Manually check a few random points using the "Identify Features" tool to ensure the process has worked correctly.
```{r joins-result, out.width="100%", fig.cap="Join Results", echo=FALSE}
knitr::include_graphics("figures/spatial_join_result.jpg")
```
## Points in Polygons
The final step for this chapter will be to count the number of road crash casualties in each LSOA.
In the Vector Menu, select Analysis Tools, Count Points in Polygons.
```{r points-polygons, out.width="100%", fig.cap="Points in Polygons Tool", echo=FALSE}
knitr::include_graphics("figures/points_ins_polygon.jpg")
```
For the Polygons choose your LSOA areas and the points the stats19 data. USe the number of casualties as a weighting field, and give the "count field name" an appropriate name.
A new layer will be created with the number of casualties for each LSOA. Use symbology to visualise the most dangerous areas of Leeds.
```{r final-plot, out.width="100%", fig.cap="Number of road crash casualties in Leeds", echo=FALSE}
knitr::include_graphics("figures/final_plot.jpg")
```
<!-- ## Attribute calculations -->
<!-- New attributes can be added to datasets with the Calculator... -->
<!-- ## Buffers -->
<!-- ## Spatial subsetting -->
## Summary
Before moving onto the next chapter, make sure you have.
1. Reprojected the stats19 data to the British National Grid
1. Done an attribute join of the population data to the LSOA areas
1. Done a spatial join of the LSOA areas to the stats19 points
1. Counted the number of casualties in each LSOA
Bonus Exercises
1. Can you use symbology to show the population of each LSOA?
1. Can you use symbology to indicate the number of casualties in each LSOA?