Uploaded by Bush Man

Introduction to geospatial analysis in QGIS

advertisement
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
Tutorial: Introduction to geospatial analysis in QGIS
Site:
IHE DELFT OPEN COURSEWARE
Printed by:
Livingstone Asala
Course:
ToT1 – Spatial analysis for agricultural applications using open
source tools
Date:
Friday, 16 April 2021, 12:22 PM
Book:
Tutorial: Introduction to geospatial analysis in QGIS
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
1/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
Table of contents
1. Introduction
2. Theory
2.1. GIS Vector Data Model
2.2. Map projections in GIS
2.3. GIS Formats and Good Practice
3. Choosing the projection
4. Importing the Scanned Map into the Georeferencer GDAL Plugin
5. Setting the Transformation Parameters
6. Adding Ground Control Points (GCPs)
7. Reduce Errors and Perform the Transformation
8. Verify the Georeferenced Map
9. Digitizing Vector Layers from a Georeferenced Backdrop
9.1. Digitize Places
9.2. Digitize Rivers
9.3. Digitize Lakes
10. Styling the Places, Rivers, and Lakes
10.1. Style Places
10.2. Label Places
10.3. Style Rivers
10.4. Style Lakes
11. Conclusions
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
2/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
1. Introduction
In order to use hardcopy maps in a GIS, they need to be scanned and georeferenced. Georeferencing is also needed for raw remote sensing
images, such as aerial photographs and satellite images.
For the best result, choose a map sheet that is clean and does not have too many folds. Use a scanner that is large enough to scan the whole
map. The resolution of the scanner should be large enough (e.g. 1200 dpi) to have su cient detail in the resulting raster maps.
For georeferencing we need to link locations on the scanned image to coordinates. There are two ways:
Collect ground control points (GCPs) at locations that are clearly visible in the image, such as bridges and junctions.
If the hardcopy map contains a coordinate grid, you can use the printed grid as a reference. Make sure that you know the projection of this
grid, which is usually stated on the map.
Learning objectives
Work ow
Materials
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
3/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
2. Theory
First we'll present the theory needed for this exercise in some videos.
Watch rst this introduction to GIS video.
Watch each video in the next sections carefully. During the live session we'll do a quiz!
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
4/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
2.1. GIS Vector Data Model
Watch this video on the GIS Vector Data Model.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
5/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
2.2. Map projections in GIS
Watch this video on Map Projections in GIS:
This video show more in practice how to use projections in QGIS:
A useful site to check if you're stuck with projections is: https://ihatecoordinatesystems.com
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
6/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
2.3. GIS Formats and Good Practice
Watch this important video on GIS formats and good practice.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
7/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
3. Choosing the projection
Have a look at the scanned map and try to nd the projection that has been used for the grid on the map. You can use any image viewing
software for this.
Now look up the keywords at http://www.spatialreference.org.
Which EPSG code belongs to the projection of the topographical map?
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
8/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
4. Importing the Scanned Map into the Georeferencer GDAL Plugin
1. From the main menu choose Raster | Georeferencer
The Georeferencer is now opened in a new window.
2. Maximize this window
3. Click the Open Raster button
4. Browse to the TopographicMapVesdre.png le. A pop-up window might open where you have to specify the Coordinate Reference System (CRS) of this
input map. It does not yet have a CRS, so you can click Cancel.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
9/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
5. Setting the Transformation Parameters
First we have to set the transformation settings.
1. In the georeferencer menu choose Settings | Transformation Settings; here you can choose:
Di erent transformation types. A simple linear transformation can be used if the map is not much deformed. The other ones can be tried
when more deformation exists. More information about the transformation types can be found in the documentation. We will start with a
linear transformation.
Resampling method: if you need the pixel values in further calculations, it is best to choose the nearest neighbor option. This resampling
method will preserve as much as possible the original pixel values by choosing the nearest one. Visually, however, this method results in a
“blocky” map. If the purpose is only for visual use, for example as a backdrop for digitization of vector layers, then it is better to choose
another resampling method. Here we will use the cubic method, which uses the average of the 16 nearest pixels.
Target SRS: here choose the code that you have noted before; EPSG:31370. You can choose it by clicking
and typing 31370 in the lter
eld.
2. Browse to the folder where you want to save the georeferenced map using the browse button
. The tool automatically adds _modified to
the le name. So in our case the georeferenced le will be named TopographicMapVesdre_modified.tif. Keep the other settings on default and
check the box Load in QGIS when done.
The dialogue should look like the screenshot below.
3. Click OK to continue.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
10/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
6. Adding Ground Control Points (GCPs)
In order to link the le coordinates to real world coordinates, we need to indicate Ground Control Points (GCPs) with known coordinates. We can
derive these coordinates in di erent ways:
The easiest way is to use the coordinate grid on the scanned map if this is available and if it is in a known projection. We click on a node in
the grid and type the corresponding X and Y coordinates in the dialogue.
Using a reference map in the QGIS map canvas that has already been georeferenced. In this way we can obtain the right coordinates by
clicking on the reference map.
Using GCPs that were measured in the eld using a GPS.
Here we will use the coordinate grid that is printed on the map.
1. Zoom in on the node with coordinate 235000 m East and 150000 m North. Read the coordinates from the side of the map, determine what is x
and what is y.
2. Click the
button to add a GCP.
3. Enter the map coordinates in the pop-up window:
4. Press OK.
Now your screen should look like the screenshot below:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
11/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
The red dot is the location that you have referenced. In the table below the map, you can see the Source X and Source Y coordinates. These are the
unreferenced le coordinates. Their values depend on which pixel you clicked for placing the GCP, so it can di er from the screenshot. Dest. X and
Dest. Y show the real world coordinates that you have linked to this location. The other elds of the table have to do with estimated accuracy and
will be lled in after adding more points.
5. Let’s choose a second GCP in the upper right corner of the map and proceed in a similar way as with the rst GCP. Your screen should look like
the screenshot below:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
12/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
You can see that some error statistics have been calculated. With only two points this does not make much sense. The minimum amount of GCPs
for a linear transformation should be three. With more GCPs that are well distributed over the map, the transformation will be more accurate.
6. Add in a similar way a GCP in the lower left and the lower right corner of the map. If you made a mistake you can remove the GCP by using the
button.
Your screen should look like the screenshot below:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
13/39
4/16/2021
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
Tutorial: Introduction to geospatial analysis in QGIS
14/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
7. Reduce Errors and Perform the Transformation
At the bottom of the screen you can see the estimated mean error (0.438877 pixels in our case). The error is also visualized at the GCPs using a
red line. Obviously your values will not be exactly the same.
There are two ways to reduce the error:
Check the values in the table. You might have made a mistake (swapped X and Y or missed a 0 in the coordinate).
You can use the
button to place the GCPs really at the nodes where the grid lines cross. You need to zoom in to select the right pixel.
Note that the mean error is not automatically updated. You need to change the transformation type to something else and then back.
If this doesn’t reduce the error, we can change the transformation type. If we change to another transformation type in the transformation
settings, the error values will be recalculated.
In our case the error is less than 1 pixel, so we can accept it.
Note that a mean error < 1 pixel cannot always be achieved. The decision to accept a certain accuracy depends on the purpose of the map.
1. Now we can start georeferencing using the
button.
After some calculation time you'll probably get this popup to choose the transformation equation:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
15/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
Di erent equations can have di erent accuracies. Here both have an accuracy of 1 m.
2. Keep the rst option and click OK.
The georeferenced map appears in the QGIS Map Canvas.
3. You can close the Georeferencing window. It will ask if you want to save your GCPs. You can click
Discard if you don’t want to use them. If you save them, you can load them again in the georeferencer.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
16/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
8. Verify the Georeferenced Map
In order to verify the result you can check the coordinates at the grid nodes that you have used as GCPs.
1. Click right on a grid node in the map and the coordinates are displayed next to the cursor.
2. Read the coordinates from the side of the map and verify if they correspond with these coordinates. Repeat for the GCP locations.
Another way to verify the result is to use the web maps as a backdrop. The QuickMapServices plugin provides easy access to many web maps such
as Google satellite and OpenStreetMap.
Plugins are third-party additions to QGIS. They can be installed through the Plugins manager. You need an internet connection to connect to the
Plugins repository.
3. Choose from the main menu: Plugins | Manage and Install Plugins...
4. Search for QuickMapServices.
5. Click Install Plugin. Click Close after installing.
6. In oder to get access to more online resources choose Web | QuickMapServices plugin | Settings from the main menu. Next, choose the
More services tab and click Get contributed pack. Click OK in the popup and Save in the dialogue when the contributed pack is installed.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
17/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
7. Go to the main menu and choose Web | QuickMapServices plugin and select Google | Google Terrain and then OSM | OSM Standard.
Compare the georeferenced map with Google Terrain and OpenStreetMap.
To help with this comparison you will employ a Blending Mode. Blending modes determine how two layers interact visually. When a blending mode
is applied to a layer it will be blended with the layer below.
8. Open the Layer Styling panel by clicking the
button. Set the target layer to TopographicMapVesdre_modified.
9. In the panel, choose Blending mode Multiply.
Blending modes allow for more elegant rendering between GIS layers. They can be much more powerful than simply adjusting layer Opacity.
Blending modes allow for e ects where the full intensity of an underlying layer is still visible through the layer above. There are thirteen blending
modes available.
This is a good time to save your QGIS project (.qgz le).
10. From the main menu, choose Project | Save as... and save it as Exercise_1.qgz.
The project le contains references to all layers, styles, projections, extent and zoom level of the Map Canvas. Save your project regularly!
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
18/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
9. Digitizing Vector Layers from a Georeferenced Backdrop
Our georeferenced scanned map can now be used as a backdrop to digitize vector layers. Vectors can be points, (poly)lines or polygons. In this
exercise we are going to digitize:
Places as points
Rivers as polylines
Lakes as polygons
We will create these vector layers in a GeoPackage spatial database. In that way we have all layers together in one le, instead of using separate
shape les.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
19/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
9.1. Digitize Places
First we have to create an empty GeoPackage layer.
1. From the main menu select Layer | Create Layer | New GeoPackage Layer.
2. In the New GeoPackage Layer dialogue, rst select the Database lename by clicking the
button. Browse to the folder where you want to
store the GeoPackage and save it to Vesdre.gpkg. For Table name type Peaks. For Geometry type choose Point. Make sure EPSG:31370 is chosen as
the projection. Create a new eld with the Name Name, keep Type Text data and click
.
3. Click OK.
The empty layer has now been added to your layers list. If it's not on top, drag it to the top of the list. The order of layers is important. We're going
to digitize Places, so it needs to be on top in order to see the result. If it's below the topographic map, we can't see the points.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
20/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
In order to start digitizing, you have to toggle to editing mode.
4. Click on the Places layer so it is selected. Click on
in the main toolbar to toggle to editing mode. You can also right-click on the layer and
choose Toggle Editing from the context menu to place the layer into edit mode.
Now the buttons on the Digitizing Toolbar become active. A pencil icon also appears next the layer in the Layers Panel indicating the layer is in edit
mode.
5. On the topographical map navigate to Verviers.
6. When you have found Verviers, zoom in to the center and click the Add Point Feature button
. The cursor changes in a crosshair. Move the
mouse to the center of Verviers and click to place the point.
A dialogue with a form shows up. d is the feature id that is automatically generated. It’s a unique integer number for each feature. The other
attribute that we have to ll is Name.
7. In this example we type Verviers for Name. Click OK.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
21/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
Now the point is placed.
8. Repeat this step for a few other places.
If you made a mistake, you can use the Vertex Tool
screenshot below) and click
to move the feature or use one of the select options to select the point feature (see
to delete the selected point feature. These buttons
can be used to undo/redo editing actions. Use
to save the edits.
9. When done, click again on the
button to toggle editing. If you didn’t save edits yet, it will ask you to Save or Discard. With Discard you can
always undo your edits until the last time it was saved.
It is important that the layer is not in editing mode when you're done with editing. Always check if the layer has no pencil. Layers that are in
editing mode can't be used in processing and you risk loss of data if you didn't save it.
Editing mode toggled on:
Editing mode toggled o :
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
22/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10. You can check the attribute table of your new point vector layer by right-clicking on the layer name (Peaks) and selecting Open Attribute
Table.
Now you can see the attributes that you have added and their d and Name values.
If you don't see the table, you need to toggle from Form view to Table view with the buttons on the lower right of the window.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
23/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
9.2. Digitize Rivers
Your next task is to digitize line features (rivers). The procedure is similar to creating a point layer.
1. In the New GeoPackage Layer dialogue rst browse to the existing Database, Vesdre.gpkg.
2. Give a new Table name of Rivers and a Geometry type of Line. As a new attribute we add Name with the type Text data. Don't forget to click the
button. Check if the dialogue resembles the gure below and click OK.
A New GeoPackage Layer window will open informing you that the le already exists.
3. Choose Add New Layer to add the Rivers layer to the GeoPackage.
The Rivers layer is now added to the layers panel.
4. Toggle editing to start adding rivers. Click on the Add Line Feature
button to add a new river feature. Zoom and pan on the map to nd a
stream to digitize.
Always start digitizing from the upstream to downstream. The direction will be stored in the layer. Always place a vertex when a tributary joins a larger stream.
That's important when connecting the tributary later.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
24/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
5. Click on the starting point of the line (node) and click when necessary to make a vertex.
You can use the zoom and pan buttons to trace the stream. You can use the Spacebar to pan during digitizing. With Backspace you can delete the
last node while digitizing.
6. After you place the end node of the line, right click to complete the feature. Now you can enter the attribute data in the form. You can nd the
name also on the OSM Standard layer. Click OK after entering the name.
Now you are going to digitize a tributary. First you have to set the snapping options.
7. In the main menu choose View | Toolbars | Snapping Toolbar (alternatively right-click on a toolbar and
choose Snapping Toolbar). Click
to enable snapping. Choose to snap to vertices of the active layer with a tolerance of 15 meters.
8. Now digitize the tributary from upstream to where it joins the higher order river. You will see that the line will snap to the node that you placed
before on the main river. After digitizing save the edits an toggle o editing mode.
If you want all tributaries to be one single feature, you need to dissolve the features.
9. When you have given all tributaries the same name, you can dissolve them by choosing Vector | Geoprocessing Tools | Dissolve from the
menu.
10. Use the
button to choose Name as the Dissolve eld and save the result in a GeoPackage layer with the name Rivers_dissolved. Click Run.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
25/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10. Check the attribute table of the result before and after dissolving:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
26/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
9.3. Digitize Lakes
Finally we are going to create a polygon vector layer for some lakes. Try to nd out how to do this for yourself. It is very similar to the procedure
for lines. The only di erence is that the rst node should be the same as the last node in order to close the polygon. Use the name of the lake as a
text attribute.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
27/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10. Styling the Places, Rivers, and Lakes
In this nal section you will style your places, rivers and lakes.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
28/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10.1. Style Places
You will begin with the styling the Places layer.
1. Open the Layer Styling panel by clicking the
button. Set the target layer to Places.
By default they are styled using a Simple marker.
2. Choose topo pop city from All symbols. Change the Color to red and the Size to 3 mm.
You can immediately see the result on the map.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
29/39
4/16/2021
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
Tutorial: Introduction to geospatial analysis in QGIS
30/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10.2. Label Places
Next you will label the places.
1. Switch to the Labels tab
of the Layer Styling Panel. Switch from No Labels to Single labels. Set the Label with option to the Name eld.
2. To make the labels easier to read change the font Style to Bold. Switch to the Label bu er tab
more separation between the labels and the feature icon switch to the Label placement tab
3. Finally click the Automated placement settings
and check the Draw text bu er option. To give
and set the Distance to 2 mm.
button to open the Automated Placement Engine window. Uncheck the box for Allow truncated
labels on edges of map option. This will prevent labels from being cut o .
4. Click OK to dismiss and your labels should look like:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
31/39
4/16/2021
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
Tutorial: Introduction to geospatial analysis in QGIS
32/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10.3. Style Rivers
Next you will style the rivers.
1. Set the target layer in the Layer Styling Panel to Rivers and switch from the Labeling tab back to the Styling tab.
2. Select Simple line. Click the Color bar to open the Select line color panel.
3. Change the Color to an RGB value of 31|120|180.
4. Click the Go back
button to return to the main symbology panel.
5. Increase the Stroke width to 0.86 millimeters.
6. To label the rivers switch to the Labels tab
.
7. Repeat the initial steps of labeling Place to label Rivers with just the Name eld.
8. Switch to the Label placement
tab and choose under Mode for Curved.
To make them more readable against the topo map you will apply a bu er.
9. Switch to the Label bu er tab
and check Draw text bu er option.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
33/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
You will set the color to the green background of the topo map.
11. Click the drop down arrow for the Color setting and choose Pick color.
12. With the eye dropper cursor click on a place to select that green topo map background color.
13. Finally return to the Text
and set the label Color to an RGB value of 31|38|180, the Font to Calibri, the Size to 11 and the Style to italic.
Your rivers should look like:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
34/39
4/16/2021
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
Tutorial: Introduction to geospatial analysis in QGIS
35/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
10.4. Style Lakes
Next you will style the lakes. You will use a shapeburst ll which will allow you to color the lakes from light blue to dark blue.
1. Set the target layer in the Layer Styling Panel to Lakes and switch from the Labeling tab back to the Styling tab.
2. Select the Simple ll styling component. Change the Symbol layer type to Shapeburst ll. Keep the default Gradient colors setting of Two color. Set the
rst color to an RGB value of 185|239|255. Set the second color to an RGB value of 31|133|180.
3. Set the Shading style to Set distance with a value of 6. Increase the Blur strength to 12.
Finally you will add a simple line to represent the coastline of each lake.
4. Click the Add symbol layer
button. Change the new Simple ll renderer to a Symbol layer type of Outline: simple line with Color of 31|133|180.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
36/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
5. Label the lakes with the the Name. Set the label Color and RGB value of 225|255|255 (white), the Font to Calibri, the Size to 10 and the Style to bold
italic.
6. Switch to the Label placement
tab and change the Mode to Horizontal. Then switch to the label Formatting
tab and enter a space as the
Wrap on character. Set the Alignment to Center.
7. Then switch to the label Formatting
tab and enter a space as the Wrap on character. Set the Alignment to Center.
Your lakes should look like:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
37/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
8. Save your project. You'll need it for the next lesson.
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
38/39
4/16/2021
Tutorial: Introduction to geospatial analysis in QGIS
11. Conclusions
In this lesson you have learned to:
nd the projection and EPSG code of a map
install plugins
georeference a scanned map using GCPs from a grid
use the coordinate capture tool
use online layers from the QuickMapServices plugin
digitize points, lines, and polygons and add attributes
use the snapping toolbar
dissolve features
store data in a GeoPackage
style and label vectors
You can watch this webinar for the full procedure:
https://ocw.un-ihe.org/mod/book/tool/print/index.php?id=9985
39/39
Download