-
Notifications
You must be signed in to change notification settings - Fork 9
/
03-data.Rmd
116 lines (73 loc) · 6.09 KB
/
03-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
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
# (PART) Transport data in QGIS {-}
# Downloading and loading data {#data}
## Downloading data
A vital skill for doing using GIS skills to solve real-world problems is finding, downloading and importing data.
Often, the first stage in the data downloading/loading process is to find the data online.
You will need several data sets to add to your QGIS project. First you will need to download the data.
Click on the link below or type in the following URL into your internet browser:
https://github.com/ITSLeeds/QGIS-intro/releases/
On that page you will see several links. For the exercises in part 1 you will need this one: [**qgisdata.zip**](https://github.com/ITSLeeds/QGIS-intro/releases/download/0.1.1/qgisdata.zip).
Download and unzip the files into an appropriate place on your computer, in the folder where your QGIS project lives.
```{r, eval=FALSE, echo=FALSE}
# download data with R (see readme of piggyback pkg for into)
piggyback::pb_download("qgisdata.zip")
```
```{block2, type='rmdnote'}
If you're using Chrome on Windows, this is how to save it the file after you clicked on it and after it appears at the bottom of your browser. Right click on the folders and click "show in folder". Use cut and paste and select a location for the folder on your computer. (e.g You can use your M drive if working on a university computer).
```
Once downloaded, right click on the zipped folder that has been downloaded to your computer and select "extract all".
## Importing spatial data
To load a spatial data file, click on the Data Source Manager button in the top left corner of QGIS (see Figure \@ref(fig:data-source-manager)).
```{r data-source-manager, out.width="10%", fig.cap="The Data Source Manager icon", echo=FALSE}
knitr::include_graphics("figures/open-data-source-manager.jpg")
```
We will first load a polygon layer.
1. Open the Data Source Manager and select “Vector”.
1. Next press the button with 3 dots, which is below and right of where it says **source**.
1. Next navigate to the file by finding the folder "qgisdata".
1. Inside this is another folder "Access_DeprivationLeeds"
1. Add the data: "Access_DeprivationLeeds.shp"
1. Click “Add” then “Close”. Note the data manager does not close automatically after adding a file to your project, this is to allow you to add multiple files at once.
```{r data-source-manager-shp, out.width="100%", fig.cap="The Data Source Manager - Vector", echo=FALSE, fig.show='hold'}
knitr::include_graphics("figures/AddVectorLayer.jpg")
```
```{block2, type='rmdwarning'}
If the map appears to be 'squashed', distorted and compressed in the vertical (North-South) dimension, this is probably because the coordinate reference system needs to be set, to 27700. See Chapter \@ref(working-with-qgis) for details on how to set-up a project and set the CRS.
```
The result should look something like the map displayed in Figure \@ref(fig:imported) (but the colour might be different).
```{r imported, fig.cap="The map after the file 'Access_DeprivationLeeds.shp' has been imported.", echo=FALSE}
knitr::include_graphics("figures/AccessDepLayerOnScreen.jpg")
```
Next add the cycle_routes layer (note this is a line layer).
Follow the steps above, but note that you may need to 'navigate up the file tree' (which means go up a folder level to 'IntroQGISdata2019') then you will be able to click on the folder 'cycle_routes'.
## Importing a CSV or text file
### CSV with spatial data
We have already loaded polygon and line data. Now we will add point data
Sometimes you have data that contains spatial information but is not in a spatial data format. A common example is to have a CSV file with latitude and longitude columns. CSV is a common format for storing data and can be opened by lots of different software, including Microsoft Excel.
We will plot the location of vehicles collisions in Leeds. Use the 'stats19.csv' example file.
1. Open the Data Source Manager and select “Delimited Text” then specify the “File Name” and location, or use the … to navigate to the file.
1. Under the “Geometry definition” select “Point coordinates” and set the “X field” to “longitude” and the “Y field” to “latitude”. Set the “Geometry CRS” to “EPSG: 4326 – WGS 84”. Note here we are explicitly telling QGIS the CRS of the data.
1. Click “Add” then “Close”.
```{r data-source-manager-csv, out.width="100%", fig.cap="The Data Source Manager - Delimited Text", echo=FALSE}
knitr::include_graphics("figures/import_csv.jpg")
```
After importing the 'stats19' data, using menus shown in Figure \@ref(fig:data-source-manager-csv), you should see points on the map, representing where crashes in Leeds took place in 2017.
If you do not see dots on the map, re-read this section and have another go.
If you do, like in Figure \@ref(fig:summary-screenshot-data-loaded), congratuations, you can now load data into QGIS!
```{r summary-screenshot-data-loaded, fig.cap="Summary of the data loaded in this Chapter, note the name of the datasets in the Layers menu.", echo=FALSE}
knitr::include_graphics("figures/summary-screenshot-data-loaded.png")
```
## Loading basemaps
You can add a "basemap" as follows:
1. Click on the 'XYZ Tiles' option in the Browser Panel. Options should include Google and OpenStreetMap.
1. Clicking on one of these will add a new layer, which can be seen in the Layers menu.
1. The basemap now obscures the other layers you have added. Go to the layers panel and drag the basemap to the bottom of the list of layers. The Basemap will now appear below the other layers.
**Now save your work**. Save your work regularly.
## Summary
Before moving on to the next chapter make sure you have.
1. Downloaded the example data
1. Imported the files to QGIS
3. Added a basemap
Bonus Exercises
1. Read about the disadvantages of shapefile and some of the alteratives http://switchfromshapefile.org/
2. In the course data folder, there is a copy of the "Access_DeprivationLeeds" file in Geopackage format. Have a go at loading this layer into QGIS. the polygons may be a different colour to the shapefile, but it should cover the same area.