0% found this document useful (0 votes)
46 views65 pages

QGIS Tutorial Feb 2021

Uploaded by

Ezio Auditore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views65 pages

QGIS Tutorial Feb 2021

Uploaded by

Ezio Auditore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

A Tutorial on

Developed by

Dr. Md. Mostafa Ali Julker Naem


Professor Junior Scientific Officer
WRE, BUET, Dhaka, CEGIS, Dhaka

February, 2021
Exercise-1: Georeferencing

Page 1 of 65
1.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 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 Dhaka City (Early 2000s).

1.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. In
our case we will use UTM coordinate system (we will input the projection
parameters manually).

1.3 Installing necessary plugins:


Unlike ArcGIS, QGIS doesn’t pre-install all the necessary plugins/tools. So we
have the freedom to choose whatever we need to install for our purpose. In this
exercises we will need and install three plugins.

1. Georeferencer GDAL
2. Coordinate Capture
3. QuicMapServices

Page 2 of 65
The installation process is shown in the following figures-

Page 3 of 65
1.4 Defining UTM manually:
1. From settings option of main window select Custom CRS…

2. In the window name the desired name of the co-ordinate system. And paste the
parameters copied from the doc file provided named “UTM parameters”.

3. Click + button and click OK.

Page 4 of 65
1.5 Importing scanned map into the Georeferencer:

1. From the main menu choose Raster o Georeferencer o Georeferencer…

2. Click the Open Raster button


3. Browse to the Test_Dhaka.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.

Page 5 of 65
1.6 Transformation Parameters of map (To export):
First we have to set the transformation parameters of the map we are processing.

1. In the menu (of georeferencer) 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.

Page 6 of 65
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 we can choose the code of any relevant reference system.
For our case we will choose; 32645 (which we created manually for
UTM45 N ).

Browse to the folder where you want to save the georeferenced map. The tool
automatically rename the file (as ********_modified). So in our case the

Page 7 of 65
georeferenced file will be named Test_Dhaka_modified.tif. Keep the other
settings on default and check the box Load in QGIS when done. The dialogue
should look like the one below.

1.7 Adding ground control points (Georeferencing):


In order to link the file coordinates to real world coordinates, we need to
indicate Ground Control Points (GCPs) with known coordinates-

1. Zoom in on the coordinate 2645000 North and 840000 East.

2. Click the Add Point button to add a GCP.

Page 8 of 65
3. Enter the map coordinates in the pop-up window:

840000 2645000

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

Page 9 of 65
5. Repeating the same procedure we need to georeference at least 4 points.

6. If you made a mistake you can remove the GCP by using the Delete point

button .
7. At the bottom of the screen you can see the estimated mean error in the
map units (0.2530 meters in our case). The error is also indicated at the
GCPs using a red line. The large error is found, we can change to another
transformation type in the transformation settings (as shown in 1.5), the
error values will be recalculated.

Page 10 of 65
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:

Page 11 of 65
Exercise-2: Digitization in QGIS

Page 12 of 65
2.1 Digitizing Vector layer from Georeferenced Background:
From a georeferenced background ( Scanned map or satellite image), we can
easily digitize vector layers. Vectors can be points, (poly)lines or polygons. In
this exercise we will do all of them.

Points:

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
(USER:100000). 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 Places. We can also create fields for
numbers. For type we choose Whole number and Width 3. This means that
we can store integer values up to 999.

Page 13 of 65
3. Click the button Add to attributes list. The attribute is now added. Click
OK.
4. Browse to the folder where you want to store your data and name it
Places.shpand press OK.
5. The empty shapefile has now been added to your layers list….

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

Page 14 of 65
7. 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.
8. In the topographical map navigate to a place.Now click the Add Feature

button .
9. Now fillup the fields.

10. A point shape file is created like the following…

11.Repeat this step for a few other Places. 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.
12.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.

Page 15 of 65
13.You can check the attribute table of your new point vector layer by right
clicking on the layer name (Places) and selecting Open Attribute Table..

Line and Polygon:

Digitizing Line and polygon is very similar to digitizing point features. We just
have to select Line or Polygon option while adding new shapefile layer as
described in the 2nd step of the point digitizing.

Page 16 of 65
Just one thing is to be kept in mind, snapping option is a very useful option while
working with lines. We can find it in the setting option as shown below-

Page 17 of 65
2.2 Digitizing River Bank from Georeferenced Images:
In this exercise we will digitize georeferenced images downloaded from USGS
website. Downloaded images are provided in the folder named “Jamuna” inside
Ex-1.

The following steps will guide you through the process.

1. First, we have toAdd images. In the main menu Click the Open Raster
button
2. Select 2007.tif and 2017.tif and double click to open.

3. We will work with 2007 first. So


uncheck 2017 from layer panel.

4. Now we have to create a line shapefile using the same methods described
previously.

Page 18 of 65
5. Name the shapefile “2007Banks” (Say).

6. Now Zoom in the image and Digitize any bankline you wish.

Page 19 of 65
7. After doing the full bank the image looks like this….

8. Repeat the whole process for 20017 and name the shapefile
“2017Banks” (Say).
Page 20 of 65
9. After doing the full bank the image looks like this….

10. Hiding the images and keeping the lines only we can clearly see the
changes in only 10 years….

11. Using these shapefiles we can do any kind of analysis we want.

Page 21 of 65
Exercise-3: Vector Data Analysis

Page 22 of 65
3.1 Introduction:
In this exercise we will learn to process vector data. That will include:

1. Import .xls files into GIS.


2. Convert Excel table to GIS format.
3. Working with attribute table and use of field calculator.
4. Interpolate point features into raster.
5. Calculating length of line features.
6. Calculating area of polygon features.

3.2 Importing .xls files into GIS:


In this exercise we will work with Jamuna river bathymetry data

Following steps will guide you through the processes-

1. open layer> Add a layer> add delaminated txt

Page 23 of 65
2. Now browse the CSV file, choose X,Y field and coordinate and select OK.

Page 24 of 65
3. QGIS interface will look like this.

3.4 Converting Excel table to GIS format:


1. The next step is to convert All Cs data to a GIS vector format, i.e.
shapefile. Click right on All Cs data and choose Save as...

2. In the dialogue Browse to the folder to save the file as All Cs data.shp. Select
CRS as WGS 84 UTM 45 N (EPSG: 32645). Click Ok.
3. Now Remove the All Cs data from the display by clicking right and selecting
Remove. Be sure to remove the right one. If you hover your mouse over the
layer name it will show the file name. With Remove you only remove it from
the display, the file will still be on your hard disk.
4. To check whether our points projection is ok or not, we can use google
satellite image using Quick Map Services plugin (From Web option).

Page 25 of 65
3.6 Working with Table:
Now all the elevation are in m. Let’s assume we need to convert this to ft for some
reason. Following steps will guide us through this conversion-

1. Go to attribute table of Stations and start editing mode by clicking on


button.
2. Click to add a new column to the table. And fill in the dialogue
according to this screenshot: then press OK.
[Here with is the amount of numbers, precision is the amount of decimal]

Page 26 of 65
3. Now the attribute table shows an extra column with NULL values. In order
to calculate the right values click above the table to open the Field
Calculator dialogue.
Fill the dialogue like the screenshot below. To avoid typos the best practice
is to double click on the field name in the middle of the dialogue screen and
to click the * button. Then type 3.28. Click OK to proceed.

4. Make sure the table look like the window below. Click update all and click
ok .

Page 27 of 65
5. Click again on to toggle back to non-editing mode. Click Save to save
the changes when asked and close the attribute table. If you made a mistake
choose Discard to undo all changes since last save.

Page 28 of 65
3.7 Interpolating point features into raster:
Now we will learn to interpolate this values of salinity into a raster.

1. In the processing tool bar search (Interpolation) and choose IDW

2. In the dialogue specify the output file: Interpolated_salinity.tif by using the


browse window and specifying the .tif format.

Page 29 of 65
Check the Z-field
checkbox and
select. This is the field that we will interpolate. And choose the extent .

3. The interpolated bathymetry map is now loaded into the display.

Page 30 of 65
4. It is visualised in greyscale, so you have to set the visualisation options. Click
right on the map and select Properties.
5. Under the Style tab, play around with the different options and click OK to
return to the display. Visualising the result this interpolation method looks
better.

Page 31 of 65
3.8 Calculating length of line features:
So far we have worked with point data only. Let’s move on to line data. Now we
are going to learn how to calculate length of line shapefile. Let’s calculate the
distances between some of the stations.

1. First of all let’s uncheck the raster layer for better visibility. Now from
coordinate layer properties, change the label to Upazila name.
2. Now create a new shapefile layer (line) as shown in the previous example.
Let’s name it as Lines.
3. Right Click on Lines and choose Toggle Editing.

4. Now click on add feature button .


5. Left click on two successive points that we want to calculate distance then
left click. Fill up the popup window with id as we like. Note that we may
need to fill other fiends if we add additional fields while creation the layer.

Page 32 of 65
6. Repeat this procedure for all the distances that you are willing to calculate.
7. Click button to stop editing mode. Save the layer.
8. Now the window should look something like that…

9. If we go to the attribute table of the Lines layer it should look like this..

Page 33 of 65
10.We have to add a new field to calculate the lengths of the lines. For that

click on button of the table and then click on button to add a new
layer.
11.Fill up the box as shown below. [The lengths will be in meter unit, so it
might be a big number. Therefore we choose 10 as length.That means it
will be able to handle up to 999999999 m ]

12. Now for Lengths layer click button. In the geometry section find
$length and double click on it. Press ok.

Page 34 of 65
13. The table window should look like this…

14. Press update all and click on to stop editing mode.


15.After this the Lengths field shows the lengths of the sections in meter. We
can easily convert this length into km using field calculator as shown earlier.

3.9 Calculating Area of a feature:


We can easily calculate any area using similar procedure as length calculation.
The only difference is that instead of selecting $length, we have to select $area
in the 12th step of length calculation.

Also note that the area will be in sq. meter. So we have to use field calculator to
convert it to sq. km.

Page 35 of 65
Exercise-4: Raster Data Analysis

Page 36 of 65
4.1 Necessary Data:
The necessary data (Dummy) is provided in the Ex-3 folder. For this exercise we
will use the following maps:

➢ Dhaka.tif,
➢ AREA.shp

4.2 Add Raster Layer:

➢ Use the add raster button from the toolbar on the left to add the
following layers: Dhaka.tif,Then click Open.
➢ Drag the Dhaka.tif grid to the top in the display tab to view the map (Note
that it is easier if the Layers panel is on top, see figure below.

➢ Rasters normally only store values, and in the layer panel it always shows
incorrect values. So we have to correct the shown values first from
properties as shown below

Page 37 of 65
Page 38 of 65
➢ Now at first do some basic operation using dhaka
4.3 Analysis:
4.3.1 Analysis -1: Basic operation using Raster calculator:
For this condition, we basically have to perform following three tasks-

1. Use clip operation for extracting a smaller area.


2. Change the style of color ramp for better outlook.
3. Create a Boolean grid with DEM elevation >= 15m.
4. Convert Raster into vector.

Following steps will guide you through the process…

➢ Go to Raster→ Extraction →Clip by extent

➢ We can either use a shapefile (Mask Layer) or draw an extend to clip our
Raster layer (Dhaka). For our case we will use our Area file as shown
below…

Page 39 of 65
➢ Let’s Name the new file “clip Dhaka”. And also correct the legend values
as shown earlier. It will appear as shown below.

Page 40 of 65
➢ Now we can change the color properties as shown below…

➢ The DEM should look like this-

➢ Now let’s find out the area with elevation over 15m.

Page 41 of 65
➢ For this go to Raster→ Raster calculator

➢ Write the following expression in the window (Double click on clipped


mask to use “Clipped mask ” in the expression) and also give the output
layer a name …

Page 42 of 65
➢ Let the name to be “DemOver15m”. Click Save and OK.

➢ In the output 1 represent True (cells with elevation >=15m) and 0


represents False (cells with elevation <=15m).

➢ Lets name the output shapefile as “AreaOver15m”.

➢ This will take a while. Don’t panic, just relax.


➢ When the operation is complete , the output shapefile may look like this-

4.3.2 Analysis -2: Generation of Inundation map:


For Analysis-2 we will use ClipDEM. In this DEM our Min elevation value is -
13 and Max value is 30.

The basic theme of inundation map is that a cell with lower elevation than the
WL will be inundated. So let’s find an inundation map for WL 9m, 10m, 11m,
12m and 14m.

➢ From Processing Toolbox search for “Reclassify values (Simple)”

Page 43 of 65
➢ If you cant find Processing Toolbox just Go to Processing and click on
Toolbox

➢ Fill us the box as shown below and click on the box at lookup table
option.

Page 44 of 65
➢ Fill up the table as shown below (before that you must Add 3 more rows
using Add row button)-

➢ Click Ok and Run.


➢ Qgis will generate a Temporary file named GRIDOUT.sdat. Save this file
as “Inundation” in your folder.

Page 45 of 65
➢ Remove the temporary file. The Raster file should look like this-

➢ Go to properties of Inundation to change the colors and legends.

Page 46 of 65
➢ You can change label by double clicking any label. Also color can be
customized as your likings.
Page 47 of 65
Exercise-5: Map Generation

Page 48 of 65
5.1 Introduction:
In this exercise we will learn how to generate and design a standard map using
QGIS. Say for example, we are trying to generate the following map of Dhaka
District using Qgis.

For this purpose we have to perform following tasks-

1. Provide Title
2. Insert Legend
3. Insert two map frames
4. Generate Grids (With Coordinate)
5. Provide suitable borders
6. Insert Scale bar
7. Use Arrows
8. Insert image of North direction

In the following few steps we will learn how to perform all the above tasks and
thus learn the basics of map generation.

Page 49 of 65
5.2 Import Data:
The first step is to import the necessary vector or raster data layer using which
we want to generate the maps. For this exercise we will use the shapefile of
Bangladesh to generate the map of Dhaka District.
1. Add the shapefile layer named district.shp from the folder Ex-5.
2. Adjust the coordinates if necessary (we will work in BTM).
3. Extract Dhaka District from the district shapefile.
4. Use necessary adjustment of the symbology.

The window should look like this.


Now we will use this two layers to generate the desired map.
5.3 Use of Print Composer:
For generating and exporting maps we have to use Print Composer tool.
1. First we have to open New print composer from Project Tool bar.

Page 50 of 65
2. A new composer window will pop up. Give a name or keep it blank.

3. Press Ok. The Composer will open.

4. From the Composition section, the default settings of the map can be
changed.

Page 51 of 65
5. From the page section, we can change the background of the map page as
shown in the image below (After clicking Change Button, the box of the left
will pop up).

6. The composer now looks like this-

Our basic preparation for the map is now complete. We can now insert of generate
the components of the map.

Page 52 of 65
Step-1: The Title

1. Click on Add new label button:


2. Draw the text box at the top of the page.

3. Select the text layer (named QGIS) and go to item properties.


4. From main properties we can change the title. From Appearance we can
change the font, size and alignments etc.

5. If we click on the box under the Lock icon , the text will be fixed in the current
position. We also can change the frame or background color etc.

Page 53 of 65
Step-2: The Main Frame

From main window uncheck district layer and zoom the Dhaka layer. We want
Dhaka layer in our main frame.

1. Now go to composer and click on Add new map button to create new map
layer.

2. Now create the box wherever you like in the composer window. Remember
that whatever is in the main window will automatically show up in the frame.

Page 54 of 65
3. We can use (Move/select button) to move and adjust the position of the
frame.
4. Now we can adjust the contents of the frame using the (Move item
content) button.
5. If we are satisfied with the frame position, we can lock the frame from the
item section.

6. Now our frame (Map 0) and its content is fixed in place. We can now change
its properties (background, grids, coordinates, texts etc.) from item
properties.
7. We can change the background color and provide frame from the item
properties section.

Page 55 of 65
Step-3: Grids and Coordinates

1. Go to grid section of the item properties and click on button.

2. Fill up the box as shown below:

3. The map should look like this now-

Page 56 of 65
4. Now go to the coordinate section. Fill up the section as shown below-

5. Adjust the fonts from the font section as your desire.

Page 57 of 65
6. The map should look like this now-

7. Work with the main frame is over. We will now move on to the secondary
frame containing the map of Bangladesh.

Step-4: Secondary Frame

1. First of all go to the main window of Qgis and check the district layer and
zoom to layer (district).
2. Now go to composer and click on (Add new map) button to create new
map layer.
3. Draw the frame where suitable. And adjust the contents if necessary.

Page 58 of 65
4. In the Layer section check the boxes as shown above. We have to check the
boxes for the main frame also.
5. We can provide frame, grid, coordinates etc. for this frame also as shown
earlier for main frame.
6. Lock the frame in place if we are satisfied.

Step-5: Legend

1. Click on (Add new legend) button. And draw the box wherever you like.
2. Change the item properties as you wish. We can change the item names from
the Legend items section.

3. We can also change the fonts and symbol properties-

Page 59 of 65
4. We can also change the spacing of different components of the legend and
also provide frame and change background etc.

5. The nap should now look like this-

6. The next tusk is to provide Scale bar.

Page 60 of 65
Step-6: Scale bar

1. Click on (add new scale bar) Button.


2. Draw at the bottom of the map. Adjust the position. Then change the
properties as shown –

3. We can also change fonts and background as shown earlier. The map now
looks like this-

Page 61 of 65
Step-7: Insert North Arrow

1. Click on button. Draw an image box on left corner.


2. From search directories (item properties) choose suitable symbol.

3. Adjust the North arrow and lock it in place.

Step-8: Insert Arrow

Our final task is to insert an arrow from the frame-2 to frame-1.

1. Click on button. Draw the arrow as shown below-

2. Adjust or change the properties if necessary.


3. The final map now looks like this-

Page 62 of 65
5.4 Export Map:
We can export the map in different formats (PDF , image etc.)

1. Go to Composer → Export as image…

2. Select the desired folder location and click ok. A window will pop up.
Change the properties as you like.

Page 63 of 65
3. Click Save button.
4. The Image will be saved to your desired folder.
5. Using the same procedure we can export the map as PDF and SVC format
also.

Page 64 of 65

You might also like