Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Exercice 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Exercises Open Source Software for

Preprocessing GIS Data for Hydrological


Models

Dr. Hans van der Kwast


Senior Lecturer in Ecohydrological Modelling
Water Science and Engineering Department

E-mail: h.vanderkwast@un-ihe.org

In cooperation with:

September 2017, version 2.18.11


OpenCourseWare
ocw.un-ihe.org
Contents
1 Preface ............................................................................................................................................. 4
2 Introduction ..................................................................................................................................... 5
3 Getting familiar with QGIS............................................................................................................... 6
4 Digitizing from a scanned map ........................................................................................................ 9
5 Importing tabular data into a GIS .................................................................................................. 20
6 Importing data from a GPS and conversion to vector layers ........................................................ 34
7 Spatial planning using map algebra............................................................................................... 46
8 Inaccessible wells .......................................................................................................................... 64
9 Catchment delineation .................................................................................................................. 66
10 Using Open Access data ................................................................................................................ 95
11 Create 2D and 2.5D maps ............................................................................................................ 106
12 Styling and map design................................................................................................................ 111
References ........................................................................................................................................... 123
Links ..................................................................................................................................................... 123
Screencasts .......................................................................................................................................... 123
1 Preface
A Geographic Information System (GIS) can be a useful tool for preparing the input of models and
tools. Furthermore, in this era of Open Data ample open access data is available that can easily be
retrieved from the internet and integrated in open source desktop GIS software, such as QGIS.

These exercises will guide you through different steps that are needed to preprocess data to be used
in models and tools. In the first exercise you will learn how to register a scanned topographic map
and use it as a backdrop for digitizing vector data. In the second exercise you will learn how to import
data from spreadsheets into a GIS and to use it to join tables, manipulate the attribute table and
interpolating the data to a continuous raster layer. In the third exercise you will download open
access data from OpenStreetMap and use it for further analysis and conversion. The geodatabase will
also be introduced in this exercise. In the fourth exercise you will use map algebra for spatial
planning. Finally, you will learn how to delineate catchments and streams form digital elevation
models and to present them in maps or in an interactive webpage.

The exercises have been developed for different MSc programmes at IHE Delft and tailor made
trainings in Uganda, financed by the Vitens Evides International (VEI) fund. I would like to thank Jan
Hoogendoorn and Jonne Kleijer, GIS experts from VEI, for their contribution to these exercises. The
Adjumani dataset was developed by VEI and the National Water and Sewerage Corporation (NWSC)
in Uganda. I’m thankful for their permission to use the dataset for educational purposes.

In the near future we will further update the exercises and distribute it as Open CourseWare so the
whole community can use the course materials.

4
2 Introduction

2.1 Learning objectives


After following this step-by-step tutorial you will be able to:

x Use QGIS in its main functionalities, also in conjunction with plugins


x Digitize features from a scanned map or satellite image
x Import tabular data in a GIS
x Do simple vector analysis
x Interpolate point data
x Convert vector and raster data
x Reproject vector and raster data
x Use map algebra
x Use online data
x Perform catchment and stream delineation

2.2 Software requirements


During the next exercises we will make use of the following software:

x QGIS ver 2.14 (Essen) or higher,


x Google Earth,
x Firefox Mozilla
x MS Excel or OpenOffice Calc

You need an internet connection to download plugins or to use the open access data.

2.3 Preparation
Please note that QGIS is already installed on the laptops of UNESCO-IHE participants. Please do not
change the version and skip this section. The exercises have been tested for QGIS 2.14.x.

1) Download QGIS from http://www.qgis.org/en/site/forusers/download.html


2) Install QGIS
3) Install the exercise data from http://ocw.unesco-ihe.org

2.4 Convention
Throughout this guide we have used three different fonts according to what kind of operation we
wanted to point at:

 Calibri, is used for the main text


 Times New Roman, Italic, is used to identify software commands
 Courier New is used for text input, that is text that you have
to write in the software, or for file names

5
3 Getting familiar with QGIS

3.1 Start QGIS 2.18


You can start QGIS 2.14 Desktop by looking for it in the Start menu or using the search function.
Make sure you open the QGIS Desktop with Grass in order to have all functionality we need.

3.2 The screen


Like many commercial GIS also QGIS has a "traditional" GIS layout.

It is made of the Standard System Menu or Main Menu (we will refer to Main Menu in the following
pages) which is always on the top of the software's window, of standard toolbars like the Zoom
Tools, or others that can be activated clicking in the Main Menu View and then Toolbars.

On the left hand side there is the Table of Content (Layers list) area, where all the layers displayed
are shown. To the left of this space there is a vertical toolbar, the Manage Layers toolbar.

In the centre of the window stay the Map Area, where all maps will be displayed.

More information about the QGIS Graphical User Interface can be found here:
http://docs.qgis.org/2.18/en/docs/user_manual/introduction/qgis_gui.html

6
3. Standard
2. Zoom & Other Tools
System Menu

1. Table of Contents
(Layers)

6. Open Different
Types of GIS Data

5. Data Sources 4. Map Area


Browser (blank right now)

7. On-The-Fly (OTF)
Projection

7
Exercise 1: Digitizing from a scanned
map

8
4 Digitizing from a scanned map

4.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 enough detail in the resulting raster maps.

For georeferencing we need to link locations on the scanned image to coordinates. There are two
ways:

1. Collect ground control points (GCPs) at locations that are clearly visible in the image, such as
bridges and junctions.
2. 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 usually is stated on the map.

In this exercise we will use a scanned map of Mount Marcy (USGS, 1979)
(Mount_Marcy_New_York_USGS_topo_map_1979.JPG), which we will georeference with
the coordinate grid printed on the map. You can find the data (Data Exercise 1) on the
OpenCourseWare website (http://ocw.unesco-ihe.org/course/view.php?id=11). Save the map on
your hard drive (e.g.
D:\QGIS_Exercises\Exercise_1\Mount_Marcy_New_York_USGS_topo_map_1979
.JPG

4.2 Choosing the projection


Have a look at the scanned map and try to find the projection that has been used. You can use any
image viewing software for this. Which projection was used? Look for the EPSG code in
http://www.spatialreference.org and write it down.

4.3 Enable the Georeferencer GDAL plugin


The Georeferencer GDAL plugin is a core plugin, which means that it is already installed. In order to
use it, you need to activate it. This works as follows:

1. In the main menu go to Plugins Æ Manage and install plugins…


2. Search for Georeferencer GDAL and check the box
3. Click Close to close the dialogue

9
4.4 Importing the scanned map into the Georeference GDAL plugin
1. From the main menu choose Raster Æ Georeferencer Æ Georeferencer…

2. Click the Open Raster button


3. Browse to the Mount_Marcy_New_York_USGS_topo_map_1979.JPG file
4. A window will 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.

4.5 Setting the transformation parameters


First we have to set the transformation settings (see also screenshot on next page).

1. In the menu choose Settings Æ Transformation Settings…


2. Here you can choose:
a. Different 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. We will start with a linear transformation.
b. Resampling method: if you need the pixel values in further calculations, it is best to
choose the nearest neighbour 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 4 nearest pixels.
c. Target CRS: here choose the code that you have noted before; EPSG:26718
Browse to the folder where you want to save the georeferenced map. The tool automatically
adds _modified to the file name. So in our case the georeferenced file will be named
D:\QGIS_Exercises\Exercise_1\Mount_Marcy_New_York_USGS_topo_map
_1979_modified.tif

10
Keep the other settings on default and check the box Load in QGIS when done. The dialogue
should look like the one below.

4.6 Adding Ground Control Points (GCPs)


In order to link the file coordinates to real world coordinates, we need to indicate Ground Control
Points (GCPs) with known coordinates. We can derive these coordinates in different ways:

x 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.
x 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.
x Using GCPs that were measured in the field using a GPS.
Here we will use the coordinate grid that is printed on the map.

1. Zoom in on the node with coordinate 581000 East and 4885000 North.
2. Click the Add Point button to add a GCP.

11
3. Enter the map coordinates in the pop-up window:

If you have a reference map in the QGIS map canvas, you can use the From map canvas
button to capture the coordinate and perform an image to image georeferencing. Here we
will only type the coordinates form the map grid.

4. Press OK. Now your screen should look like this:

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 file coordinates. Their
values depend on which pixel you clicked for placing the GCP, so it can differ from the
screenshot above. Dest. X and Dest. Y show the real world coordinates that you have linked
to this location. The other fields of the table have to do with estimated accuracy and will be
filled 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 first GCP. Your screen should look like this:

12
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
4.

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 Delete point button . Your screen
should look like this:

At the bottom of the screen you can see the estimated mean error (40.4217 pixels in our
case). The error is also visualized at the GCPs using a red line.

13
There are two ways to reduce the error:

a. Use the button (move GCP point) to place the GCPs really at the nodes where
the grid lines cross. You need to zoom in to select the right pixel.
b. We can also change the transformation type. If we change to another transformation
type in the transformation settings, the error values will be recalculated.
We’ll apply option b.
7. In the menu go again to Settings Æ Transformation Settings… and now let’s select a 1st order
polynomial (Polyniomial 1) instead of the linear transformation. Keep the rest as it was. Click
OK to return to the GCP table. Now you can see that the mean error has been reduced to a
fraction of a pixel, which is acceptable. If you don’t see a mean error < 1, than you have to
check the GCP locations and correct them.

8. Now we can start georeferencing using the button. After some calculation time the
georeferenced map appears in the QGIS map canvas. You can close the Georeferencing
plugin. 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 Georeferencing plugin.

9. In order to verify the result you can use the Coordinate Capture plugin. If it is not activated
yet you can do it by choosing from the menu: Plugins Æ Manage and Install Plugins… . Then
search for the Coordinate Capture plugin and check the box to activate and click Close:

10. A panel has appeared under the layers list. Here you click on Start capture. Click on a grid
node in the map and the coordinates are displayed in the panel:

Read the coordinates from the side of the map and verify if they are correct.

11. Another way to verify the result is to use the QuickMapServices plugin web maps as a
backdrop. If not yet installed, install the QuickMapServices plugin: in the main menu choose
Plugins Æ Manage and Install Plugins… and search for the QuickMapServices plugin and
install.

14
After installing, choose from the main menu Web Æ QuickMapServices plugin and try some
of the options.

4.7 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:

x Mountain tops as points


x Rivers as (poly)lines
x Lakes as polygons
The following steps guide you through the process.

1. First we have to create an empty shapefile. In the main menu select Layer Æ Create Layer
Æ New Shapefile Layer…

2. In the New Vector Layer dialogue we specify that we are creating a Point layer. For the CRS
we select the one of the topographical background map (EPSG:26718). You can use the
arrow to choose the right projection from the dropdown list. Next, we have to create a new
attribute. In the attribute list you can see that by default there is an attribute called id. We
will create one with the name Elevation. For type we choose Whole number and Width 4.
This means that we can store integer values up to 9999, which is sufficient for any mountain
on Earth.

3. Click the button Add to attributes list. The attribute is now added. The dialogue should look
like this:

15
4. Click OK.
5. Browse to the folder where you want to store your data (e.g.
D:\QGIS_Exercises\Exercise_1) and name it peaks.shp and press OK.

6. The empty shapefile has now been added to your layers list.

7. In order to start digitizing, you have to toggle to edit mode. Click on the peaks layer so it is
selected.

8. Click on to toggle to editing mode. Now the other editing buttons become active and a
pencil before the layer name shows that we are editing the layer.

9. In the topographical map navigate to a spot height of a mountain. They are indicated with x
and an elevation value. If you have found one, zoom in and click the Add Feature button .

10. Move the mouse to the mountain top. The cursor changes in a crosshair. Click on the
mountain top.

11. A dialogue with a form shows up. Here you can fill in the attribute values: id = 1 and
Elevation = 738

12. Repeat this step for a few other peaks. If you made a mistake, you can use to select the

point feature and to delete the selected point feature. This button can be used to
move a point feature. Use to save the edits.

13. 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.

14. 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

16
Now you can see the attributes that you have added and their id and elevation values.

15. Our next task is to digitize line features. The procedure is similar to creating a point layer. In
the New Vector Layer dialogue now you choose Line. As a new attribute we add River
Name with the type Text. Keep the width at 80. Check if the dialogue resembles the one
below and click OK. Call the new vector layer streams.shp.

16. In the layers list select the streams layer and toggle editing.

17. Click on to add a new line feature. Zoom and pan on the map to find a stream to digitize.

18. 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 also change the symbology
to visualize clearer the line that you are digitizing. After you placed the end node of the line,
click right. You can use the spacebar to pan during digitizing.

19. In the dialogue, fill in id = 1 and the name of the river.

17
20. Repeat these steps for a few streams and save your edits. Check the attribute table. If you
want to add tributaries that connect to streams, play around with the snapping settings (in
the main menu go to Settings Æ Snapping options…).

21. Finally we are going to create a polygon vector layer for some lakes. Try to find out yourself
how to do this. It is very similar to the procedure for lines. The only difference is that the first
node should be the same as the last node in order to close the polygon.

4.8 Image to image registration


Try to use the Georeferencer plugin to register the scanned map (JPG file) to a satellite image
from the QuickMapServices Plugin. In this way you can perform an image to image registration.
Please make sure you use the right projection. Does the image to image registration give better
results?

This whole exercise can be viewed in a screencast


at: https://youtu.be/4IWyVeGhzog

18

You might also like