0% found this document useful (0 votes)
93 views143 pages

GIS Book

This book serves as a practical guide for learning GIS concepts, focusing on hands-on exercises and using data from Nepal, making it particularly suitable for students in that region. Each chapter introduces new terminology and tools while minimizing theoretical content to enhance learning engagement. The guide covers various aspects of GIS, including data types, coordinate systems, database management, and GNSS applications.

Uploaded by

RABIN KHADKA
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)
93 views143 pages

GIS Book

This book serves as a practical guide for learning GIS concepts, focusing on hands-on exercises and using data from Nepal, making it particularly suitable for students in that region. Each chapter introduces new terminology and tools while minimizing theoretical content to enhance learning engagement. The guide covers various aspects of GIS, including data types, coordinate systems, database management, and GNSS applications.

Uploaded by

RABIN KHADKA
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/ 143

Learn GIS and Remote

Sensing through Practice


A Practical Guidebook for Learning GIS

Akhilesh Kumar Karna, PhD


This book is intended for the learner of GIS concepts. Every chapter starts with short
introduction to the new terminology and tools wih more focus on the practical exercise
tutorial. It uses data for Nepal and more suited for students of Nepal.

First release, January 2019


This book is dedicated to

My parents

My wife Rita

and

Daughters: Kriti & Yuki


Contents

1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1 This Book 11
1.2 Installation of QGIS 11
1.3 QGIS Interface 11
1.3.1 Layers Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.4 Understanding QGIS interface through exercise 12
1.4.1 Example: Visualizing GIS data in QGIS . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.5 Elements of QGIS interface 16
1.5.1 Layers panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.5.2 Browser panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5.3 Menus/Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5.4 Status Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.6 Using menus and tools of QGIS. 20

2 GIS Data Types and Symbology . . . . . . . . . . . . . . . . . . . . . . . 25


2.1 GIS Data Types 25
2.1.1 Vector Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.1.2 Raster Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2 Symbology 26
2.2.1 Vector data attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2.2 Applying Symbols to Vector Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.2.3 Applying Symbols to Raster Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.3 Map production and cartography 51
2.3.1 Layout Manager interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

3 Coordinate Reference System . . . . . . . . . . . . . . . . . . . . . . . . . . 61


3.1 What is coordinate 61
3.2 Projection and projected coordinate system 64
3.2.1 Transverse Mercator Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.2.2 Azimuthal Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.2.3 Conic projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.2.4 Summing up the projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.3 Shape of earth 66
3.4 Projection Transformation 67
3.4.1 Assign Projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.4.2 Projection transformation of vector data . . . . . . . . . . . . . . . . . . . . . . . . 70
3.4.3 What is EPSG? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.4.4 Projection transformation of raster data . . . . . . . . . . . . . . . . . . . . . . . . 72
3.5 Why do we need so many different CRS? 74

4 Database Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.1 What is information system 75
4.2 Basic tutorial for Database management 76
4.3 Using Selection Statements in Database Management 80
4.4 Creating and editing table in a database 84
4.5 Information System vs Geographic Information System 86
4.5.1 Converting non-spatial database to spatial database . . . . . . . . . . . . . 86
4.6 Summary of database management system 89
4.6.1 Definition of database and DBMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.6.2 DBMS applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

5 Working with Vector Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93


5.1 Types of vector data (Geometry) 93
5.2 Vector GIS Data Formats 94
5.2.1 File based vector data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.2.2 Relational database management system (RDBMS) . . . . . . . . . . . . . . 95
5.2.3 Internet based vector data provider . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7

5.3 Characteristics of vector data 96


5.4 Sources of vector data 99
5.4.1 Governmental and non-governmental organization source of GIS data 99
5.4.2 Derivation of data from remote sensing images . . . . . . . . . . . . . . . . . 100
5.4.3 Engineering survey and GNSS based survey . . . . . . . . . . . . . . . . . . . . 100
5.5 Deriving GIS data from text documents and images 100
5.5.1 Creating GIS data from text documents . . . . . . . . . . . . . . . . . . . . . . . 100
5.5.2 Creating data from images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.6 Analysis of Spatial Data 110

6 An Introduction to GNSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113


6.1 What is GNSS? 113
6.2 Components of GNSS 114
6.2.1 Space segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6.2.2 Control segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
6.2.3 User segment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.3 How GNSS works? 115
6.3.1 GNSS signals and their transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.3.2 Calculation of receiver’s location (Trilateration) . . . . . . . . . . . . . . . . . 116
6.4 Errors in computation of location 117
6.4.1 Atmospheric effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
6.4.2 Multipath error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
6.4.3 Ephemeris and clock errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
6.5 Practical use of GNSS 119
6.6 Mapping and navigation related apps 119
6.6.1 Google Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
6.6.2 OSMTracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
6.6.3 OsmAnd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
6.6.4 GPSTest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
6.6.5 SW Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
6.7 Working with GNSS apps 125
6.7.1 OSMTracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
6.7.2 SW Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Preface

This book is intended for novice user of GIS.


While teaching GIS, and while I was learning myself, I had observed that going
through a lot of theories makes learning cumbersome. When you get something with
a few lines of codes or with a few clicks of mouse you are excited to learn some more.
But most of the books on GIS starts with a lot of theories. I have tried to limit theoritical
part in the initial chapters. With a very few efforts you can produce good looking maps.
Once you know how GIS works, through your own experience, you will get to know the
theory behind it in the subsequent chapters.
This book is focused on the users in Nepal, although it can be modified to suit other
places.
You need to know about places if you want to learn GIS, because, after all, GIS is all
about locations. When you find the places in the book familiar to you, you feel as if you
are in your own territory. But most of the books and tutorials you find in the market or
on the internet uses data of unfamiliar places.
GIS needs a lot of data. Most of the data needs to be downloaded from internet. It is
necessary to have high speed internet connection if you need to learn through this book.
First two chapters are freely available. You can send feedback to my email address
akhileshkk_at_hotmail.com. Your valuable suggestions will be taken into account to
improve in the next editions of book.
1. Introduction

1.1 This Book


This book will introduce the concepts of GIS(Geographic Information System) through
practical applications using QGIS.
Structure and instructions used in this book will become clear as we go through it.

1.2 Installation of QGIS


This book uses QGIS installed for Windows 10. You may encounter some minor
differences than explained in this book if your OS is different. QGIS can be installed in
various ways. In this book I will recommend to install QGIS standalone version from the
website: http://qgis.org. This book uses QGIS version 3.2. You can use newer version.
In that case there may be some differences in the interface explained in this book.
[Net18]
[Wes+15]
[Tes19]
[Tes19]
Download the software from the above website. You will need to check whether
your OS is 64-bit or 32-bit. In case of any confusion you can download and install 32-bit
version.

1.3 QGIS Interface


QGIS interface consists mainly of followings:
• Menu bar with menus
12 Chapter 1. Introduction

• Panels which can be moved, removed, docked and undocked


• Tool bars with tools
• Map display area where a map is displayed
• Status bar which has various information

Figure 1.1: QGIS interface

1.3.1 Layers Panel


Fig.1.2 shows Layers panel, you can find maximize and close buttons as well as related
tools within a panel.
In the figure, Layers panel is docked together with Browser panel as you can see in
the figure. These two panels can be switched by selecting the tabs at the bottom. When
you select Browser panel, the interface will change as shown in figure 1.3.
You can see the name of panel at the top of each panel. This is also the handle of the
panel. You click and hold your mouse cursor on the handle and move the panel as you
wish. Here, you can practice moving the Layers panel. You can also remove the panel by
clicking the close button at the right top of the panel. Once removed, panel can be shown
again by clicking on the Menu View ⇒ Panels. You will see sub menu with the list of
available panels as shown in Figure 1.4
1.4 Understanding QGIS interface through exercise 13

Figure 1.2: Layers panel

1.4 Understanding QGIS interface through exercise


Before starting the exercises, let us create a folder for keeping our data. Make a
new folder named GIS_exercise in any convenient location. For our exercises in
this chapter, we will create folder Exercise01 for keeping data. We need GIS data
to show in QGIS. We will learn what is GIS data in next chapters. Before that,
let us practice an exercise which will show map of world in QGIS. Many GIS data
are available for download from websites. For this exercise, we will download data
of world boundary from website http://www.naturalearthdata.com/downloads/
50m-cultural-vectors/50m-admin-0-countries-2/. Click on the button Down-
load Countries. Save and extract your zip file in GIS_exercise\Exercise01. You can use
7-zip or any unzip program to unzip the data.

1.4.1 Example: Visualizing GIS data in QGIS


Exercise 1.1 QGIS Exercise: Data visualization
• Start QGIS Desktop from windows start menu.
• Add GIS data.
You can add GIS data in different ways as follows. For this exercise practice all
the three methods.
1. Click Menu Layer ⇒ Add Layer ⇒ Add Vector Layer
14 Chapter 1. Introduction

Figure 1.3: Browser Panel

Figure 1.4: Show Hide Panel


1.4 Understanding QGIS interface through exercise 15

In the popup window click browse and point to the folder where you extracted
the data. See the Figure 1.1.

Note : If All Files is selected in the filter, change it to ESRI shapefile so that you
can see fewer files in the list.
Select the file ne_50m_admin_0_countries.shp and click Open (in the file se-
lection window), again click open in add vector layer window. You will see the map
of the world added to the display area.
2. Click on the Add Vector Layer tools under Manage Layers tool bar as shown
in the Figure 1.1.
You will get the same popup window as in the above step(Figure 1.1. Follow
the steps as shown in above method.

3. Activate browser panel.


Expand folder(click + sign on the left) to show the location of data as shown in
16 Chapter 1. Introduction

the Figure below.

Drag and drop the file to map display


Note: You may be tempted to Undo (by clicking Ctrl+Z or by selecting Undo
from Edit menu) to remove some of the layers added by above action, but it will not
work.
In this example we have displayed a map of world countries.
Let me explain how to remove the layers you have added in the next section. Don’t
close the QGIS window. You may save the project as ex01.qgs inside GIS_exercise
folder.


1.5 Elements of QGIS interface


In this section, I would like to explain about some of the tools, menus and panels
necessary for basic maneuver of QGIS.

1.5.1 Layers panel


Layers panel and Browser panel are two important panels for basic working with QGIS.
First of all, let us try to understand Layers panel Figure 1.5.

Figure 1.5: Layers panel

If you have completed the above exercise, your Layers Panel will look like Figure
1.5. Inside the Layers panel, you will see all the layers you have added to the map.
There are 8 tools as shown in the same figure. Each layer in the list of layers have three
1.5 Elements of QGIS interface 17

components: 1) check box for showing/hiding the layer, 2)Symbol of the layer and 3)
name of the layer. Some properties of the layer shown in the list of layers is enumerated
below, try to learn by practicing.
• When a layer is clicked, it becomes selected and the background changes to blue.
• If you click on the check box on the left, it will toggle between hide and show.
When the check box is checked, the layer is visible on the map. Try to show and
hide each layer.
• When you right click a layer, you will get a context menu. We will illustrate some
of the context menu items in this chapter through exercise. Some of the items will
be introduced in the upcoming chapters.
• Double clicking a layer will show its properties.
• Now let us look at some of the tools marked 1 to 8 in Figure 1.5. Details of each
tool shall be explained through exercises.
1. Open the layer styling dock: This tool can be used to change the style of the
layer.
2. Add group: This tool will add a group. This tool helps managing layers in
group.
3. Manage layer visibility: This tool will show or hide multiple layers in the
Layers Panel. You can try clicking on the tool and the subsequent menu
items.
4. Filter legend by map content: This tool will be explained later.
5. Filter legend by expression: This tool will be explained later.
6. Expand all: This tool will expand the layers inside a group.
7. Collapse all: When you select a group in the layers panel and click Collapse
all tool, the layers within the group will be hidden. It is opposite of Expand
all tool.
8. Remove layer or group: Select a layer in the layers panel and click on this
tool and see what happens.

1.5.2 Browser panel


Now we will see the contents of Browser panel.
QGIS can display GIS data from different sources. Browser panel is handy tool for
selecting and displaying GIS data from different sources. QGIS 2.18 is able to handle
GIS-data from following sources as shown in Figure 1.6. - GIS data from your hard drive
- GIS data from various Spatial Databases - GIS data from various spatial data servers
You will find Project Home, Home, Favourites, and drive names within the Browser
panel which will assist you in selecting GIS data from your hard drive. In QGIS, you can
save a map file after adding various layers. This file is called project file. Project Home
will show the data inside the folder where your project file resides. Similarly, Home is
18 Chapter 1. Introduction

the location of user’s home folder such as C:/Users/Akhilesh in Windows.


QGIS supports DB2, MSSQL, Oracle, PostGIS and Spatialite database.
QGIS supports Mapserver, Feature server and Tile Server such as ArcGisMap-Server,
WMS, WFS etc. Some of the capabilities will be demonstrated in coming chapters.

1.5.3 Menus/Tools
Many of the QGIS capabilities can be accessed through menus and tools of QGIS. Some
of the tools and menus will be explained in the next example.
As shown in Figure 1.7 and marked from 1 to 5, let us look at the functions of some
of the toolbars.
1. Project toolbar: You can create a new project, open an existing project, save an
opened project with the tools in this toolbar. You can also create or open a canvas
for printing. The same function can be accomplished by using sub menus of Menu
⇒ File.
2. Map Navigation toolbar: You can zoom and pan the map with these tools. You can
also zoom to a selected feature (What is feature? ⇒ see the next chapter). Many
of the capabilities of this toolbar can also be accomplished by using sub menus of
Menu ⇒ View.
3. Attribute toolbar: The tools contained in this toolbar can be used to identify the
features of different layers of map(identify tool). You can also select a feature of
the map (Selection tool). Using Attribute tool, you can show attributes of a layer.
You can also measure length, area or angle using Measure tool.
4. Label toolbar: It is used to label the features of the map.
5. Digitizing toolbar: It is used to edit the features of a layer.

1.5.4 Status Bar


Status Bar is located at the bottom of the user interface. You can find coordinates,
scale, coordinate reference system and few other items in the status bar as shown in
@(refStatusBar).
1. Coordinate: This shows the coordinates of the cursor as you move your mouse.
2. Scale: Scale shows the scale of the map. You can also directly enter the scale to
change the zoom level of map.
3. Coordinate Reference System (CRS): You can see a globe mark with EPSG
followed by some number. It shows the coordinate reference system in terms of
EPSG code. Coordinate Reference System is explained in detail in section 3.

1.6 Using menus and tools of QGIS.


In the previous section we introduced to different menus and tools of QGIS. Now, let us
try to practice some of them. It is necessary to practice time and again to become fluent
and to understand which tools or menus are needed in which condition.
1.6 Using menus and tools of QGIS. 19

Figure 1.6: Browser panel


20 Chapter 1. Introduction

Figure 1.7: QGIS Tools

Figure 1.8: Status Bar

Exercise 1.2 Practice with menus and tools


In the following exercise, we wil use various tools and menus. You can continue
from the last example, if you have not closed the QGIS session.
• Remove layers from map canvas: If you have more than one layers in the layer
panel, you can remove layer(s) by any of the following methods.
a. Right click on a layer to be removed in the Layers Panel and choose
Remove in the context menu. (You can also select multiple layers using
Shift Key)
b. Select a layer(or multiple layers) in the Layers panel and click on Remove
layer or group tool in the Layers Panel.
• Using navigation tools: Now you have only one layer in the map. Let us use
some map navigation tools and attribute tools.
a. Click Zoom In tool (with + sign) on the map navigation toolbar. Draw a
rectangle on the map as shown in ??. The map of the selected area will
be displayed.
1.6 Using menus and tools of QGIS. 21

b. Click Zoom Out tool (with - sign) and draw a rectangle on the map and
see what happens.
c. Click Zoom Last tool and observe what happens. You will see that the
area displayed just before using Zoom Out tool will be displayed. You
can click on this tool as many times you like. When there is no history
remaining for the last displayed area, the tool will be grayed out (disabled).
Now you can click Zoom Next tool and see that display area will change
in the forward direction. These tools are similar to the back and forward
arrow in the web browser.
• Using Identify tool: Click Identify Features tool on the Attribute toolbar.
Click any country on the world map.
You will see Identify Results panel displayed somewhere(probably on the right
side) in the user interface. You will see the attributes of the feature displayed in
tabular form as shown in following figure.
22 Chapter 1. Introduction

• Using selection tool:


1. Now click Select Features tool. Move (hover) the cursor on each tool
and you will see the name of that tool as tooltip info. You can select single
country by clicking it or you can select multiple countries by drawing a
rectangle.
2. Now click Zoom to Selected feature in the Map Navigation toolbar.
The map display will zoom to the selected feature(s).
3. Now click Open Attribute Table in the Attribute Toolbar. You will
see a table as shown in the following figure.
1.6 Using menus and tools of QGIS. 23

R What is attribute table?


Attribute table is related to GIS data. We will explain in detail later about
the types of GIS data. However, let me explain in short about the GIS data
we have displayed. It is clear from the map that the GIS data represents the
geometric boundary of all countries in the world. But the GIS data does not
only contain the geometry but also the properties of each geometry in terms
of numbers and texts. These are called attributes or fields. Each geometric
feature represent a country. The attribute table shows each attribute as column
for each features represented by rows of the table. More rows and columns
can be seen by moving the horizontal and vertical scrollbars.

Now let us try the followings and observe what happens.


a. Try to guess the meaning of each attribute.
b. Click on any column header (attribute name), for example SOVEREIGNT. The
table is sorted in the order of country name.
c. Click on any row header. The background of the row becomes blue and the
corresponding feature is shown in yellow color in the map. This means the
feature is selected. If you can not see the feature, you can click on Zoom To
Selection tool.
• Using Label toolbar:
We will use Layer Labeling Options tool and Layer Diagram Options tool.
Follow the steps below.
a. Click Layer Labeling Options tool. You will see a dialog box as shown
in following figure.

b. Change No Label to Show labels for this layer


c. In the Label with Selection box, select SOVEREIGNT. Click Apply
button at bottom right corner and close the dialog box.
You can find many other options to beautify the labels on the features.
24 Chapter 1. Introduction

d. Now let us try to use Layer Diagram Options tool. You can see it beside
Layer Labeling Options tool.
Above figure shows the steps to show Label as diagram.
• Step-1: Click the tool Layer Diagram Options. On the left pane of the dialog
box, change No diagram Rightarrow Pie Chart.
• Step-2: Select Attributes from the list on the left pane. Select Attribute
“POPE ST ” and click on the plus(+) sign.
• Step-3: Select Size from the list on the left pane. Select Scaled Size radio on
the right pane. In the Attribute selection box, select POP_EST. Click Find
button to fill the Maximum Value field. In the Size input box, write 6. Check
the Increase size of small diagrams and set the value to 0.2.
• Step-4: Click OK at the bottom of the dialog box.


2. GIS Data Types and Symbology

In the last chapter we learned how to add GIS data in the map display area and also
acquainted to some of the menus and tools of QGIS. In this chapter we will talk a little
bit more about the types of GIS data.
GIS data represents the real earth in terms of geometry. There are several types of
GIS data, but we will focus mainly on two types of data, namely, Vector and Raster data.
Let us try to understand what is represented by these two types of data respectively.

2.1 GIS Data Types


2.1.1 Vector Data
Features on earth can be represented by points, lines or polygons. These geometries are
termed as vector GIS data. As we show in the last chapter, the boundaries of countries
can be represented as polygon. Following are some of the examples of features that can
be represented by each type of geometry.
• Point: Trees, electric poles, electric towers, centroid of polygons, buildings, airport,
epicenter of earthquake, meteorological and hydrological stations
• Line or Polyline: River, electric transmission line, roads
• Polygon: Lake, pond, river, buildings, administrative boundary, landuse polygons
Some of the features such as river, buildings etc can be represented by different types
of geometry depending upon the purpose of analysis and visualization.

2.1.2 Raster Data


Raster data, such as images, are gridded data which consists of rows and columns of
data. Cell is the unit of representation of raster data. Following figure demonstrates the
26 Chapter 2. GIS Data Types and Symbology

raster data.

Figure 2.1: Elevation data (one of the most used GIS data)

Figure 2.1 is an elevation data represented in black to white color. Black color
represents lower elevation while white color shows higher elevation. Every cell in the
raster data has some value which represents the elevation at corresponding point. Raster
data can have more than one value for each cell. These are called raster bands. Elevation
data shown above has single band.
Figure 2.2 is an image taken by satellite called Sentinel. For every cell there are three
values. This raster image has three bands. If we represent each band as red, green and
blue color, we get a true color image same as what we see with our eyes. By the way,
photographs we take with our digital camera also are three band raster data. We need to
assign colors to each band so that we can see the image.

2.2 Symbology
In the last chapter we displayed the map of countries of the world. All the polygon
features were displayed with the same color (fill), and boundaries (boarder) of the
countries were displayed in black color. We can change the fill color and boarder color
of the polygons based on various attributes of the layer. Representing the GIS data with
different colors and symbols is part of Symbology. In the following examples we will try
to assign different symbols to vector and raster data.
2.2 Symbology 27

Figure 2.2: Image as Raster data

Download GIS data for Nepal administrative boundary and few other data from
following URLs. Create a folder named Exercise02 in your workspace.
• http://ngiip.gov.np/data-center/topographical-data (Data with file
name 1000k.zip will be downloaded to your default path when you click on the
link named 1000K. Move the file to Exercise02 folder.
• http://ngiip.gov.np/data-center/admin-boundary (Click on the link Ad-
min Palika to download the file. Move the file to Exercise02 folder.
Note: The urls listed above were accessed on 23rd January, 2018.

2.2.1 Vector data attributes


Before understanding how we can change the symbols of vector data, we need to know
more about the attributes. Following example will show you the types of attribute data.
• Add vector layer ne_50m_admin_0_countries.shp to the map as explained in last
chapter.
• Select the layer in the Layers Panel and click on the properties to open Properties
dialog box.
• Select Fields in the left pane of the dialogbox, you will see a table of fields as
28 Chapter 2. GIS Data Types and Symbology

shown in Figure 2.3. Observe the table and click OK to close the dialog.
• Now click Open attibute table tool. It will show you the list of values of each
feature corresponding to each field.

Figure 2.3: Attribute type, length and precision

From the above observation we can understand that there are three types of attributes
1) String, 2) Integer and 3) Real(in general). However, in the due course you can find
few more types of attributes.
From the Layer Properties dialog box, we know that - Attribute scalerank is an Inte-
ger and it can hold 4-digit number (Length is 4). - Attribute featureda and SOVEREIGNT
are Strings. Attribute featureda can be upto 30 characters long and SOVEREIGNT can
be 32 characters long. - Attribute LABELRANK is Real and its length can be 5 including
decimal and 2 digits after the decimal. You can check the data in the attribute table.

2.2.2 Applying Symbols to Vector Data


Following exercise will acquaint you with various ways you can apply symbols to the
vector GIS data. What kinds of symbol can we use? 1. Refer to Figure below in the next
example. We can see that based on attributes we can use - Single symbol: Each of the
features will have same symbol irrespective of attribute. - Categorized: We can create
categories of features based on an attribute of the layer and apply a specific symbol to
each category. - Graduated: We can create graduated symbol based on integer or real
field(attribute). - Rule Based: We can create rules based on attributes, and for each
rule we can define the symbol. The features will be symbolized based on which rule
they conform to. 2. Types of symbol: For each type of vector data (Point, Polyline and
Polygon) there are different types of symbol. The simplest ones are 1)Simple marker (for
point), 2)Simple line for polyline and 3)Simple fill for polygon. However, as shown in
Figure in the next chapter, we can find many other types of symbol apart from the default
ones. Once you click Simple marker or Simple line or Simple fill in the symbol, you
2.2 Symbology 29

can find drop down list of symbols beside Symbol layer type for you to chose. Following
example and exploring the layer properties dialog will make you conversant with layer
styling and symbols.

Exercise 2.1 Applying symbol to vector GIS data


Open QGIS Desktop from start menu and follow the steps below.
Step-I. Add layers to the map canvas.
a. Find the location of your GIS data Admin-Palika.zip, you have just down-
loaded, from the Browser Panel and drag-and-drop to the map display area
(as shown in Figure below).

b. Similary, find 1000k.zip. It consists of more than one GIS data. Therefore
it has plus(+) sign on the left. Expand 1000k.zip and add following GIS
data (ending with .shp) as layers.
• hydro_ln.shp: Shapefile of rivers as lines
• hydro_ar.shp: Shapefile of water bodies as polygons
• elev_ln.shp: Shapefile of contour lines at interval of 1000m
• trans_pt.shp: Location of airports as points
• trans_ln.shp: Shapefile of roads as polylines
• settl_pt.shp: Name of settlement areas as points
c. Arrange the layers by dragging each layer so that the polygon layers are at
the bottom and points layers are at the top as shown in Figure below.
Save the project as ex02a.qgs. You can save the project during the next
steps and pause your exercise and reopen the project again to restart from
the last step.
30 Chapter 2. GIS Data Types and Symbology

Step-II. Symbolize layers


a. Apply symbols to administrative boundary layer.
In the Layers Panel right click on Admin-palika layer and click Properties.
See Figure below.

Alternatively, the dialog can be opened by double clicking the layer from
Layers Panel.
b. From the left pane of dialog box, select style. On the right pane change
single symbol to categorized (See figure).
2.2 Symbology 31

c. You can see a dropdown list beside Column. Select GN_TYPE from the list.
d. Below the list of symbols (which is empty at present), click on Classify. You
will see a list of unique values which is extracted from attribute GN_TYPE
of the admin-palika layer listed as symbols.
e. If you click on Apply button at the bottom right of dialog, you can observe
the change in colors of the layer. In the list of symbols, you will see the
following attributes:
• Gaunpalika
• Nagarpalika
• Mahanagarpalika
• Upamahanagarpalika
• Wildlife Reserve
• Watershed and Wildlife Reserve
• National Park
• Hunting Reserve
• Development Area
f. We need to plan the colors for each type based on our purpose. For the
present exercise, let us follow the steps below.
• Double click on the symbol beside Development Area. From the dialog
box, click on the color selection dropdown list and change the color to
white (See Figure).
32 Chapter 2. GIS Data Types and Symbology

Alternatively we can select color from the color wheel and triangle
shown in the figure above.
• In similar way, select symbols for other GN_TYPES. For Wildlife
Reserve, Watershed and Wildlife Reserve, National Park and Hunting
Reserve select dark green color, for Gaunpalika dark-grayish-green
and different shades of red for Nagarpalika, Upmahanagarpalika and
Mahanagarpalika (Figure is shown below).
• Click Apply button at the lower right corner of the properties dialog
box. Now the map looks more recognizable and purposeful.

Step-III. Apply symbol to Water body polygons (hydro_ar layer)


a. Open property dialog for the layer.
b. Click Simple Fill. You will see color settings for fill color and outline color.
2.2 Symbology 33

In the fill color select blue and for outline color check Transparent Color
(see Figure).

Step-IV. Apply symbol to rivers (hydro_ln layer)


a. Open property dialog for river layer.
b. Change the color to blue and width to 0.1.
c. Click OK.
Step-V. Apply symbol to roads (trans_ln layer)
a. Open property dialog for roads layer.
b. Click plus sign(+) below the list of symbols (see Figure). Now you have
two Simple Line symbols in the list.
c. Select the lower one and change the color to dark gray. Change the width to
0.8.
d. Similarly, select the upper Simple line and change the color to yellow and
width to 0.4.
e. Click Apply button.

You can see that the roads are all over Nepal and the map does not look good.
We need a categorized road shapefile so that we can show Strategic road
network (SRN) more highlighted than other roads. Or, we can symbolize
each category of roads differently.
f. Select roads (trans_ln layer) in Layers Panel then click Open Attribute
Table tool. We can see that there are two attributes for this layer, i.e,
34 Chapter 2. GIS Data Types and Symbology

FCODE and NAME. If we scroll down the attribute table, we can see that
there are many features which do not have NAME.
g. Now we can change the symbol in such a way that the roads without any
name will be shown only at low scale. Let us try to do this as explained
below.
• Open Properties dialog for trans_ln layer.
• Click Style in the left pane. In the right pane change Single Symbol
to Rule-based.
• Delete any symbol in the list of symbols by selecting it and clicking
minus(-) sign below the list. Click plus(+) sign. A dialog box (Edit
rule) will appear as shown in Figure below.
• Enter the name of Label as you like. Click the button with . . . sign
beside Filter. Expression string builder dialog box will appear. You
can find several functions in the list. Expand Fields and Values and
double click NAME attribute. Add to the expression so that the expres-
sion is:
"NAME" IS NOT NULL

R What does this expression mean?


It means we are going to apply a symbol for those roads which
has some text in the NAME attribute.

• Change the symbol to double line by adding one more line in the
symbol in Edit rule dialog box as explained before.
• Now let us add symbol for the roads which does not have any name. In
the Property dialog, add rule by clicking on Plus(+) sign. Label it as
Other roads.
• As explained above, set the rule expression as (Note the difference
from above expression):
"NAME" IS NULL
• Set a single line symbol for this rule. To allow these roads to appear
only at low scale, check scale range and in the minimum scale input
box write 1:200,000.
2.2 Symbology 35

• Click OK button in each dialog box to complete symbol application.


Step-VI. Change the symbol of contour elev_ln layer
As contour is not necessary to be shown at all zooms, we will make it visible
at low scale. Also we will make it thin so that it does not mess with the
background.
a. Open Property dialog for the layer.
b. Select General on the left pane. In the right pane, check Scale dependent
visibility and in the minimum scale input box enter 1:500,000.
c. Select Style on the left pane. Change the color of line to gray. Set the width
to 0.15.
d. Now we have thin colored contour lines which is visible when the scale is
bigger than 1:500,000.
Step-VII. Change symbol of settlement point settl_pt layer
a. Open Property dialog. Marker is the default symbol for point layers.
b. Move the vertical scroll bar on the right side. At the bottom, you can find
few shapes for marker symbol. Let us select star shaped symbol, or as you
like.
c. Change the fill and border color as you like.
d. As explained for contour line layer, change the scale based visibility to
1:500,000.
Step-VIII. Change symbol of Airport trans_pt layer
a. Open Property dialog.
36 Chapter 2. GIS Data Types and Symbology

b. Select Single marker.


c. In the Symbol layer type select SVG marker.
d. Scroll down to find the SVG Groups in the dialog box.
e. Scroll the SVG groups item to find transport.
f. From the list of images in SVG Image, select any airplane marker.
g. Make the size of the marker bigger and click on Apply button. Adjust the
size so that the airport markers are visible in the map.
You can explore many options in the styling and labeling dialog box. There are
so many possibilities and impossible to explain each options here. With much
practice, it is possible to produce good looking presentable map.
After applying layer symbol, scale based visibility and labels to each layer
following maps are produced. Figure 2.4 shows the map at full zoom and
Figure 2.5 shows the map zoomed to certain area.


Figure 2.4: Map zoomed to full extent


2.2 Symbology 37

Figure 2.5: Map zoomed to selected area

2.2.3 Applying Symbols to Raster Data


From the previous section, we know that the raster data contains integer or decimal
values for each cell in a rectangular grid of columns and rows. Each cell may have single
data or multiple data. Raster data can represent different features on the earth. We can
demonstrate and learn about raster data from the subsequent example. Before that, we
need to acquire some raster data. Raster data are generally memory consuming. We
need to download data for our exercise from some websites. If you have slow internet
connection, it may take several hours to download some of the data.
Now let us download some of the data as below:
1. Global land use data from http://due.esrin.esa.int/files/Globcover2009_
V2.3_Global_.zip (Accessed on 24th January, 2018)
2. Satellite image data from Sentinnel-2 which is available at https://earthexplorer.
usgs.gov/.
3. Elevation data from https://earthexplorer.usgs.gov/.

How to download data


The first one in the above list can be downloaded directly by clicking on the link or by
copying and pasting the link to internet browser. For the second and third ones, which
are the same, we need to login to the website. Before login, we need to register to the
website. The process of registering and login is self-explanatory. Go for it, and create
your account. After opening the URL, you will understand that USGS (U.S. Geological
Survey) hosts several different kinds of data. Each data type has link to the explanation
38 Chapter 2. GIS Data Types and Symbology

Figure 2.6: Earthexplorer data download tools

about the data. Opening the website and clicking the links to explanation for each types
of data, in itself, will be a great learning experience.
Now let us try to understand the methods of downloading each of the second and
third data.

Method for downloading Sentinel-2 data


Method for downloading Sentinel-2 data
• Open the URL and login to the website. In case your browser points to another
address after login, return to earthexplorer website again.
• The interface consists of data selection area on the left and location selection
interface with map on the right. Zoom and pan the map to desired location. I
selected Janakpur area. Click somewhere on the map for which location you want
your data. A pin will be added to the map.
On the left frame of the interface, you can find 4 tabs at the top, namely, 1)Search
Criteria, 2)Data sets, 3) Additional Criteria and 4)Results. When you select point on the
map, the coordinates of the point is added in the search criteria. Additionally, you can
input start and end dates in the date range to specify the duration for which you want to
search the data.
• Now click Data sets tab. You can find different types of data listed alphabetically.
For each type of data set, you can find sub-types by expanding it. Now expand
Sentinel near the bottom of the list. There is only one sub-set of this data set named
Sentinel-2. Check it.
• Click Results tab. After a few seconds to a couple of minutes, depending on your
network speed, you will get satellite images listed on the left frame. You will get a
list of satellite image of the clicked point taken at different time.
• For each item in the list you will see a small image on the left, file description at
top right and a few tools at the right bottom as shown in Figure 2.6. By hovering
over each tool you can know the meaning of each tool.
• The list is a multi-page list. You can go to next pages by scrolling down clicking
on the Next link. You can click Show Browse Overlay tool to see how the image
looks. After looking at few images, decide on downloading one. Click Download
Options tool and download JPEG2000 format image.
2.2 Symbology 39

Method for downloading Elevation data


Follow all the steps for Sentinel data except that in the Data Sets tab, select Digital
Elevation ⇒ ASTER GLOBAL DEM. Follow the other steps, you will get a single image
in the result. Download it.
Apply symbol to land use data
The global land use data downloaded for this exercise, covers large portion of the earth.
The data extends from 180◦ east to 180◦ west and 65◦ south to 90◦ north. We will clip
the data to the extent of the boundary of Nepal and then apply the symbol.

Exercise 2.2 Apply symbol to land use data


As explained, there are two parts in this exercise. a) Clip raster data, b) Apply
symbol.
Step-I. Clip data to the extent of Nepal.
a. Start QGIS. From the Browse Panel find the location of downloaded data
(zip file starting with GlobeCover) expand it and add GLOBCOVER_L4_
200901_200912_V2.3.tif to the map.
b. In the Browse Panel go to the 1000K.zip file used in the last exercise. Add
admin_ar.shp file to the map. You will get warning ‘CRS not defined’. We
will talk about CRS in the next chapter.
c. Click menu Raster ⇒ Extraction ⇒ clipper.
d. After the clipper dialog display, follow the steps below (refer Figure).

1. As shown in the Figure, click select.


2. Go to Exercise02 folder in the save raster dialog. Input the name of the
output file, e.g., nepcover.tif and click Save.
3. Select Mask Layer radio button. It will take some time before the
admin_ar layer is shown in the Mask layer field.
40 Chapter 2. GIS Data Types and Symbology

4. Check the Crop to the extent of the target dataset


5. Click OK. After the clipping finishes, click Close in the Clipper dialog.
Save the QGIS project file as ex02b.qgs.
Step-II. Apply symbol to the raster data.
Before applying symbol, remove global land cover data and admin_ar layer
(See Chapter-1 to remove layers from map). Let us have a look at the raster
layer first. In the layers panel, you can see that the land cover of Nepal is
represented by black and white color. This is the default symbol for single
band raster data. As shown in Figure, black color represents the value of 11
and white color represents the value of 220 other gray shades represent values
between 11 and 220.

a. Open file browser and go to the location where you downloaded Globcover2009_
V2.3_Global_.zip.
b. If you look inside the zip file, you will find an Excel file named GlobalCover2009legend.
xls. Let us have a look at the file.
c. Open the excel file with Microsoft Excel or LibreOffice Calc. For each
value in the first column, you will see what it represents in the second
column. In third to fifth column, it shows the red, green and blue color
values suitable for the symbol. We will apply these colors to the raster data
and see how our land cover data looks.
Now follow the steps below.
1. Open Property dialog for the layer.
2. From Render type dropdown list, select Singleband pseudo color,
refer Figure. Singleband pseudo color is used to represent single-band
raster data in different colors. If you check the dropdown list for Colors
in the Property dialog, you can see a list of graduated colors. For
example, if you select a color ranging from red to blue, the lowest
value will be represented by red, highest by blue and others in between.
You can check this by selecting one from the Color dropdown list and
clicking Apply botton at the bottom.
3. Change Interploation to exact. What does it mean? If you select linear,
all the values in the list will have some color. In case of exact, only those
2.2 Symbology 41

values listed will have colors, others will not have any color.
4. Change the Mode to Equal interval, so that we can select number of
classes.
5. Input 23 in the number of Classes. You can see that there are 23 classes
listed in the Excel file, therefore we shall follow it. You will see that the
list in the middle of the right pane is populated by values, colors and
labels.
6. Now let us change the list of values and the associated colors. When
you double click a value in the list, you can edit by typing a new value.
Similarly, if you double click a color in the list it is possible to change
the color. It is also possible to change the label for each values.
d. First value in the list is 11 and it is okay. Double click the color associated
with this value. A dialog with caption Change color will be displayed. In
the right pane, you can see input boxes for red, green and blue colors. Input
170, 240 and 240 for each of these three colors (Refer the Excel file for the
colors).
e. Now change the second value to 14 and colors for red, green and blue to
255,255 and 100 respectively.
f. Change all the values and associated colors accordingly and click Apply or
OK button.

A beautifully colored map of Nepal as shown in Figure will be displayed in


the map canvas (map display area). Save the file.
42 Chapter 2. GIS Data Types and Symbology

Apply symbol to satellite data


The satellite data downloaded for this example is a multiband data. To understand what
each of the band means, you need to explore the dataset tab of earthexplorer website
and click on the link to the detailed information for the data as shown in Table 2.1.

Table 2.1: Information about Sentinel Band

Band.Number Central.Wavelength..nm. Spatial.Resolution..m.


1 443 60
2 490 10
3 560 10
4 665 10
5 705 20
6 740 20
7 783 20
8 842 10
9 945 60
10 1375 60
11 1610 20
12 2190 20

Before starting the practice let me explain what we are going to do in this exer-
cise. We will use Sentinel-2 satellite data downloaded already. The image data will
be located at D:\GIS_exercise\Exercise02\Sentinel-2\L1C_T45RUK_A011799_
20170925T045444(1).zip\S2A_MSIL1C_20170925T044701_N0205_R076_T45RUK_
20170925T045444.SAFE\GRANULE\L1C_T45RUK_A011799_20170925T045444\IMG_
DATA. To find the data you will need to explore the path using File Explorer. The name
of the zip file and and folders will be different but similar. You can check the file naming
system in the earthexplorer website. Inside IMG_DATA folder you will find files with
extension ‘jp2’.
2.2 Symbology 43

In the Table 2.1 central wavelength of each band represents color or spectrum of
wave band. Band number 2, 3 and 4 falls in the visible band which our eyes can see as
blue, green and red respectively. Spatial resolution of each band represents the length
and width of each cell of the raster data of that particular band. We can see that each
band has different resolution. We will use visible bands of data for the present exercise.
For the purpose of this exercise we will combine three visible bands into one single raster
data. We can merge the three bands using QGIS using either of the following methods.
1. Using menu Raster ⇒ Miscellaneous ⇒ Merge
2. Using Processing toolbox
Processing toolbox consists of hundreds of special tools provided by different
software such as SAGA, GRASS etc. We will talk about it in different chapter.
We will use Processing toolbox for the current example. The toolbox is generally
visible on the right side of QGIS interface. If it is not visible, you can click menu
Processing ⇒ Toolbox.

Exercise 2.3 Display satellite data and apply symbol.


We need to add the satellite data to the map and then apply symbol. We will do
this in following order.
1. Merge the three bands (Red, Green and blue).
2. Display and explore in QGIS.
3. Apply symbology
Step-I. Merge the raster bands
a. Open QGIS. In the Browser Panel find the location of downloaded data
and expand it.
b. Bands of satellite data will be listed as files ending with .jp2. The file names
being long, you will need to scroll the panel horizontally to see the full
name of data. Select files ending with B02.jp2, B03.jp2, B04.jp2 and drag
to the map display area.
c. You may add admin_ar shapefile to the map to know which area of Nepal,
the data belongs to.
d. Each of the images we added to the map represents one of the 3 different
bands of satellite data. However, currently, each layer represents single
band raster data and as expected, each of them is displayed in gray color.
We need to merge these three raster data into single one with 3-bands. It can
be done as explained in the next steps, Figure ??. Number in the brackets
corresponds to the number in the figure.
44 Chapter 2. GIS Data Types and Symbology

1. In the Processing toolbox search for merge. Few tools matching the
word will be listed in the toolbox.
2. Double click Merge under GDAL.
3. Merge dialog box will be displayed. Check ‘Place each input file into
a separate band’.
4. In the Output raster type select Int16.
5. Selected Merged output file by clicking on the button and select the
folder to save the file. Name the outfile, for example, as sentinel_rgb.tif.
6. Click button for the Input layers and select all the images in the
Multiple selection dialog and click OK.
7. Click Run in the Merge dialog box.
e. In the resulting image, data acquired from the file ending with ‘B02.jp2’,
‘B03.jp2’ and ‘B04.jp2’ will be assigned to band-1, band-2 and band-3
respectively.
Step-II. Displaying and exploring multiband data in QGIS
If everything you did as explained above, the tool will run for a few seconds to
few minutes depending on the computer specification and the resulting image
2.2 Symbology 45

will be displayed in QGIS as new layer. However, the image still does not look
what we observe with our eyes. The colors are not satisfactory.
a. Let us have a look at the properties of the rgb layer. The default colors for
the image display is not correct.
b. Display Properties dialog by double clicking or by right clicking.
c. Select Style in the left pane. You can see on the right pane that the colors
selected for red, green and blue colors are band-1, band-2 and band-3
respectively. However, according to the information in the Sentinel, band-
3 represents red color and band-1 represents blue color.
Step-III. Apply proper symbol to the satellite data
a. We need to swap bands for red and blue color on the right pane. For this,
change the text in the dropdown list beside red channel to band-3 and text
beside blue channel to band-1.
b. Click Apply button. Now the color looks more natural.
Still, the image is not very satisfactory. It is because, the color stretches
to whole range of each band’s minimum and maximum value. To correct
this, we need to correct the stretch. Select Histogram on the left pane.
The histogram shows a graph of the number of pixels versus the range of
values, refer Figure ??. From the figure, we can see that:

• Maximum value for each band is around 12000. However, most of


the pixels have values below 4000.
• Minimum value for red band is around 500.
• Minimum value for green band is around 700.
• Minimum value for blue band is around 1000.
46 Chapter 2. GIS Data Types and Symbology

c. Based on these observations, let us change the minimum and maximum


values for each band in the Style tab of the Properties dialog.
d. Click Style on the left pane and change the values of each band as 1) 500
to 4000 for red, 2) 700 to 4000 for green and 3) 1000 to 4000 for blue.
e. Click OK button. Now it looks more or less natural color.
The final product should look like following figure, with or without cloud depend-
ing on the data you downloaded from earthexplorer.


Figure 2.7: Sentinel data in Natural color

Display elevation data and apply symbol


We will do it in two steps:
1. Download elevation data
2. Display elevation data and apply symbology
Refer to the section 2.2.3 for explanation about downloading data. Let us download
elevation data for mountainous area. Follow the steps below:
1. Open earthexplorer website and login with your credentials.
2. Click Add Coordinates in the Search criteria tab and enter the coordinates (27.5◦
latitude and 86.5◦ longitude) as in 2.8.
3. Select Data Sets tab. Find and check ASTER GLOBAL DEM under Digital
2.2 Symbology 47

Figure 2.8: Enter Coordinates for elevation data

Elevation in the list of data sets.


4. Select Results tab.
5. Download only data in the list of results.
6. Move the downloaded zip file to your working folder.

Exercise 2.4 Symbolizing elevation data


Purpose of this exercise is to display realistic view of elevation data showing
mountains, rivers and topographic features. We do this in following order.
• Add elevation data to the map layer.
• Apply symbology to elevation data.
• Create hillshade raster (hillshade is derived from elevation data, and depicts
the look as if viewed from above at certain vertical angle.)
• Apply transparency to the hillshade so that both the elevation and hillshade
layers are partially visible.
Each of the above steps is explained below in detail.
Step-I. Add elevation data
a. Open QGIS and open Browser Panel
b. Find the location of the downloaded zip file

c. Expand the zip file and select the file ending with dem.tif (see figure).
d. Drag and drop to the display area.
e. Save the project as ex02c.qgs.
48 Chapter 2. GIS Data Types and Symbology

Step-II. Apply symbol to elevation data


The single band elevation raster data will be displayed as black and white
image. Black color represents low elevation and white color represents higher
elevation. From this display itself we can easily imagine the nature of the
terrain. Let us change the color of the display as explained in the following
steps.
a. Open properties window for the raster layer
b. Select Style in the left pane.
c. Select Single Band pseudocolor in the render type.
d. In the color select new color ramp (see figure)

e. In the next pop-up select the default gradient.


f. For the next dialog, follow the steps below (numbers mentioned in the steps
refer to the numbers in the figure

• Change the color of (1) to blue


• Change the color of (2) to white
• Double click around (3)
2.2 Symbology 49

• Click and select (4) and change Relative position to 33.3 and color to
green.
• Double click around (5)
• Click and select (6) and change Relative position to 66.7 and color to
red.
In this way, we are going to assign white color to highest point, blue color
to lowest point and red and green colors to intermediate heights. We could
have chosen other colors. But this is just a demonstration of one more ways
of symbol application.
g. Click OK on each dialog and have a look at our new map displayed in the
display area.
Step-III. Create hillshade from elevation data and display with transparency
We can analyze elevation data in various ways. We will have special chapter
for this. In the meantime, let us see how this terrain looks from above. Follow
the steps below:
a. From the Menu select Raster ⇒ Analysis ⇒ DEM(Terrain Models)
b. Select output file (for example as hs.tif in your working directory under
Exercise02) in the next dialog, keep other things as default. Click OK.
Hillshade will be created and displayed.
c. Open the property dialog for the newly created hillshade layer.
d. Select Transparency in the left pane and set transparency to around 50%.
You will get a beautiful display as in figure 2.9.
50 Chapter 2. GIS Data Types and Symbology

Figure 2.9: Final map of elevation display


2.3 Map production and cartography 51

2.3 Map production and cartography


Until now we tried to display the vector and raster data in the map canvas. In this
section, we will create a printable map. You might have seen various printed maps by
government departments, scientific literatures, tourist guides etc. Map making, also
known as cartography, is art as well as science. Britannica defines cartography as
“Cartography, the art and science of graphically representing a geographical area, usually
on a flat surface such as a map or chart. It may involve the superimposition of political,
cultural, or other nongeographical divisions onto the representation of a geographical
area."
QGIS provides separate interface for map production which can be accessed through
its Layout Manager menu. It allows you to add map elements to the map, and print or
export it in a presentable form. The map elements supported by QGIS are:
• Multiple maps
• North arrow
• Text box (for title, labels etc)
• Map grid and coordinates
• Legends
• Scale bar
• Attributes
QGIS provides three different ways to produce maps. They are listed below. Meaning
and steps to produce them are described in the following exercises.
• A simple map with map elements
• An atlas (multi-page map book) based on a feature class represented in the map.
• A report which can utilize multiple feature classes.

2.3.1 Layout Manager interface


Layout Manager window provides a full interface to produce a printable map. In can be
accessed by using menu Project ⇒ Layout Manager. Figure 2.10 shows the interface of
Layout Manager window.
1. Layout canvas where all the maps and layout elements are added for getting
printed (1).
2. Toolbox containing layout elements (2).
3. All the map elements added to the layout canvas are listed here (3).
4. When a map element is selected, its properties are listed here (4).
5. Some tools including image export are available here (5).
Layout elements in the toolbox are listed in the Figure 2.11 below.

Creating a simple printable map


52 Chapter 2. GIS Data Types and Symbology

Figure 2.10: User interface of layout manager window

Figure 2.11: Map element toolbox

Exercise 2.5 Map production in QGIS


Following steps will show you how to create a printable map in QGIS.
Step-I. Add map to the layout manager canvas.
1. First of all, add vector and raster layers as you like and apply symbology as
2.3 Map production and cartography 53

explained previously.
2. From menu select Project ⇒ Layout Manager. In the Layout Manager
dialog box click button Create. Give some name to the new layout, such as
map practice. Following figure shows the QGIS layout manager interface.
3. First of all, check the mapping interface has all the desired layers are added
and proper symbology applied. Now, in the layout window add new map.
To do this click on Add new map tool and draw a rectangle where you
want your map to appear. Once you draw the rectangle, your map will look
like as shown below.

Step-II. Add legend to the layout


1. Now let us add legend using Add legend tool and clicking on the canvas.
All the layers in the Layers panel will be shown in the legend. We need to
remove the unnecessary elements of legend as explained in the following
steps.
• While legend is selected, remove check Auto update in the item prop-
erties on the right pane.

• We can remove an item by selecting it in the list of legends and clicking


− sign below the list.
• We can also change the name of the item such as trans_ln to Roads etc
by selecting the item and clicking pencil sign beside − sign. Finally
54 Chapter 2. GIS Data Types and Symbology

we have the list of legend as shown in the figure below. Right figure
shows the legend as displayed in the layout.

• You can check other options inside Item properties and try changing
them.
Step-III. Add title to the layout
1. From the toolbox click Add text tool to add text to the layout.
2. Default text is Lorem Ipsum. To edit the text, you need to check Item
Properties tab on the right pane as shown below. Whatever you write in
the textbox will appear in the title text. You can edit the text: font, color,
vertical and horizontal alignment etc. Alternatively, you can add an HTML.
For example, write the following HTML sentence in the text box and check
Render as HTML checkbox.
<p style="font-size:20px;color:red;"> A Simple Map of Nepal
</p>
2.3 Map production and cartography 55

Step-IV. Add north arrow


1. Click Add image tool from the toolbox and draw a rectangle on the layout.
2. A rectangular area is available for the image, however, it will be empty.
Click on the arrow beside Search directories. It will show a directory with
a list of available svg images.
3. Select an image of north arrow that you like.
Step-V. Add scale bar
1. Click Add scale bar tool and add scale bar to the layout.
2. The default scale bar needs to be edited to your liking. In the following
figure changes are made as:

• Style ⇒ Double Box


• Segements ⇒ left 1 and right 2
56 Chapter 2. GIS Data Types and Symbology

• Width ⇒ 50 units
Step-VI. Add grid and coordinates to map
1. Select the map by clicking it. In the Item properties expand Grid.
2. Add a grid by clicking ‘+’ sign.

3. Click Modify grid

4. Edit the items as shown in the figure above. Interval → X = 1.0; Y = 1.0 ;
Frame style to Zebra or as you like.
5. Scroll down the dialog to Draw coordinates and check it. Edit the items as
shown in the following figure or as you like. In the following figure, the
modified items are:
• Format → Decimal with suffix
• Right → Disabled
• Top → Disabled
2.3 Map production and cartography 57

Finally we will produce a map as shown in the Figure 2.12. 

Figure 2.12: Printable map produced with map-elements

Producing an atlas

Let us use the same map as before to produce an atlas. The atlas will be based on the
province boundary of Nepal as feature class. Follow the steps in Exercise 2.6.
58 Chapter 2. GIS Data Types and Symbology

Exercise 2.6 Producing map atlas in QGIS


We will again add a new layout to the project by using menu Project ⇒ Layout
Manager. One single GIS project can have any number of layouts. Create a new
layout named atlasPractice.
Step-I. Add main map
1. In the layout panel, add a map and all the elements as discussed in Exercise
2.5.
2. You need to lock layers and styles so that in the next part you don’t lose
the current symbolization and list of layers. Lock layers is available under
item Layers in the Item properties

Step-II. Add overview map


1. In main map, hide all the layers (uncheck the checkboxes) except nepal_state
layer.
2. In the layout window add a map in a small area at the bottom-right corner
as shown in the following figure. We will use this map as overview. You
will understand the meaning of overview as you follow this exercise.

3. You will see a map item added in the list of items on the right pane.
4. Lock layers for this map too as explained before.
Step-III. Create overview
1. While the new map is selected, add an overview from Item Properties on
the right pane. For this check Overviews and add an overview by clicking
‘+’ sign.
2.3 Map production and cartography 59

2. While overview 1 is selected, select main map (It is Map 2 in this example)
in Map Frame.
Step-IV. Create atlas
1. Change the text of title to make it variable.
<p style="font-size:20px;color:red;"> Map of Province No.
[% state_code %] </p>
2. Select the main map. From menu click Atlas ⇒ Atlas Settings. In the right
pane, a new tab Atlas will appear. As shown in the figure set the items as
follows:

• Coverage layer ⇒ nepal_state. (Multiple maps will be produced, each


zoomed to one of the states)
• Page name ⇒ format(’province_%1’,state_code). It will not affect the
60 Chapter 2. GIS Data Types and Symbology

output. Page name displayed in the atlas will be like province_1 etc.
• Check Sort by and set the expression as state_code. The images will
be produced from province number 1 to 7.
3. Now select tab Item Properties in the right pane. Scroll down to Con-
trolled by atlas and check the checkbox.

4. In the tool bar find the tool name Preview atlas and click it. Now you will
see the main map is zoomed to Province 1.
5. Everything is OK, however, size of scale bar is not appropriate. You can
edit its properties.
6. The atlas can be output as raster imagge (png, jpeg etc), vector image (svg)
or pdf. Click menu Atlas ⇒ Export atlas as images. Select a folder to
output images. Multiple images from province 1 to 7 will be created.

We will create report in Chapter 6, An Introduction to GNSS.


3. Coordinate Reference System

After reading and practicing the first two chapters that you can do everything in GIS or
QGIS. But, many things are still to know. We might want to know how QGIS knows
where to place a point or a line or a polygon or a raster image. It requires the location
of these features. Locations are expressed in terms of coordinates. Now is the time to
upgrade yourself and learn a few things about coordinate reference system. We might
be able to display maps without the knowledge of coordinates, but for analysis and
understanding of GIS data we need to know how the locations are conceived in GIS.

3.1 What is coordinate


Most of us might have the concept of coordinate which we studied in school. However,
they only deal with points in plane. Let us recollect what we learned earlier. Points in
the plane can be simply plotted with their coordinates as shown in figure 3.1
As the earth is not plane but curved, we need to learn a bit about the shape of earth
and its geometry. Shape of the earth can be fairly assumed to be a sphere. Let us think
about a line (axis) passing through the north pole and south pole. We can draw a circle
surrounding the earth passing exactly at the centre of this axis. This is called equator. We
can draw circles parallel to the equator such that they subtend a given angle at the equator.
Figure 3.2 shows the earth, the axis, equator and the circles parallel to the equator. The
angles formed at the equator is shown in degrees. This angle is called latitude.
Now, we understand one part of the coordinates. We can draw lines from north pole
to south pole. Such lines will be a half circle. These are called meridians. The meridian
passing through Greenwich, London of United Kingdom is considered as the reference
meridian and is also known as prime meridian. Locations East of the meridian are taken
as positive and towards west are taken as negative, see figure 3.3.
62 Chapter 3. Coordinate Reference System

Figure 3.1: Concept of coordinate

Figure 3.2: Concept of Latitude


3.1 What is coordinate 63

Figure 3.3: Concept of Longitude


64 Chapter 3. Coordinate Reference System

The frame (above) shows a movable and zoomable 3D image of sphere with latitude
and longitude. Somewhere on the sphere you can see a map of Nepal. It is made with R
programming language. By draging with mouse or moving the mouse wheel the image
can be rotated and zoomed. You can see that Nepal is situated between around 26 to 30◦
latitude and 80 to 90◦ longitude. Any point on the earth can be, now, expressed in terms
of latitude and longitude. As we can see, the latitude varies from −90◦ to 90◦ . The
negative value represents locations south from the equator and positive means north
of equator. Similarly, longitude varies from −180◦ to 180◦ . Negative value represents
locations west from the prime meridian and positive means east of prime meridian.
A point on earth can be reprsented for example as (85.5732, -27.3456) or (85.5732E,
27.3456S). ‘E’, ‘W’, ‘N’, ‘S’ is, obviously, short form for the four directions. Try the
following exercise.
1. Open https://www.google.com/maps.
2. In the search box type ‘27.7, 85.312’ (without quotes) and click enter.
You will find the map centered at the point (85.312E, 27.7N). Google maps uses
latitude first.
We have shown the latitudes and longitudes on sphere in the above images. You might
think that your knowledge of coordinates is complete with this information. However, in
GIS we don’t work with 3-dimensional display. You might recall the map of the world
we created in the first exercise 1.4.1. When you display the map in cartesian coordinates,
the map stretches from -180 to 180 degress in x-direction and -90 to 90 degrees in
y-direction. However, if you check the sphere above, you can see that -180 degrees (180
degrees west) and 180 degrees (180 degrees east) represents the same line. Simiarly,
we can see that the circles parallel to the equatorial one get smaller as we go towards
north or south. However, on the flat display, it is not the same. The distance between
places get highly exaggerated as we go farther from equator. These and few more things,
make it essential to devise better ways to represent the locations more accurately on the
plane map. In simple words, we can say that ‘it is impossible to reprsent any part of earth
accurately on a two dimensional plane’. Only a three dimensional globe can represent
the locations close to the actual. Many approaches has been devised and in practice to
minimize the loss of accuracy. We will try to understance some of them in the following
sections.

3.2 Projection and projected coordinate system

In the first exercise 1.4.1, we used latitude and longitude as x-coordinate and y-coordintae
respectively. This is called *geographical coordinate system** (GCS).
We can not put whole the globe on a plane paper. However, we can represent a small
portion of globe with higher accuracy. The methods of representing curved surface of
globe on a plane surface is called projection. Let us think how we can do this.
3.2 Projection and projected coordinate system 65

3.2.1 Transverse Mercator Projection


We can put a sphere inside a cylidnder of the same (almost) diameter. One of the big
circles of the sphere will touch the inside of cylinder. You can imagine this with the help
of following frame. This, again, can rotated zoomed etc.
Transverse Mercator Projection
As we can see, a thin strip of the cylinder almost touches the surface of globe. We
can project this small strip of the globe on the cylinder. And, cylinder can be unfolded to
make a plane surface. Thus we can achieve our aim of representing a part of globe on
plane paper.
In the above frame, the cylinder is placed horizontally (if we consider north-south as
vertical) so that a meridian coincides with the cylinder. If we place the cylinder vertically,
in the same sense, the resulting projection is called Mercator Projection. Hence, when
tilted 90◦ it is called ‘Transverse Mercator Projection’.
Universal Transverse Mercator (UTM) Projection
We can see in the same frame, that the globe is divided into 6◦ angles and the cylinder
touches the meridian passing through 3◦ . In this way, we can project 0◦ to 6◦ on the
cylinder. This is a universally accepted division of globe into 60 strips at 6◦ intervals
starting from −180◦ (180◦ W ) to 180◦ (180◦ E). This projection system is called ‘Uni-
versal Transverse Mercator Projection’. It is denoted as a number with ‘N’ or ‘S’ where
the number reprsents the strip count from 180◦ W . For example, the strip passing from
longitude 180◦ W to 174◦ W will be denoted as ‘1N’ if it is in northern hemisphere.
If you calculate using the same method, you can find that Nepal which stretches from
around 80◦ E to 90o E must use two different projections for two halves of the country.
Projection ‘44N’ will be used for the area lying west of 84◦ E (78◦ E to 84◦ E) and ‘45N’
will be used for the area lying east of 84◦ E (84◦ E to 90◦ E).

3.2.2 Azimuthal Projection


Another way of projecting the globe is using a plane. This is called Azimuthal Projection.
In the following frame, the concept of Azimuthal Projection is made clear.
Azimuthal Projection
In the above figure, we can observe two things: 1) Azimuthal projection can show
half of the globe at most, 2) The distance between latitude circles become smaller as go
to the equator.
Second point can be corrected by expanding the circles such that the distance between
consecutive latitudes are equal. As such, there are several ways we can use azimuthal
projection. However, we will not go into detail as it will get more complex.

3.2.3 Conic projection


As the name suggests, we may put the globe inside a cone, so that a portion of cone
almost coincides with the globe. Check the following frame. Similar to a cylinder, a
cone can also be flattened. This is the concept of Conic projection.
Conic Projection
66 Chapter 3. Coordinate Reference System

3.2.4 Summing up the projection


We explained three types of chiefly used projections briefly, in fact, very briefly. You may
go into depth by looking for ‘Cartography Projection’ or something similar on an internet
search engine. One of the result I have found is http://www.progonos.com/furuti/
MapProj/Normal/CartHow/cartHow.html. Here, you can find a lot of informative
materials about these projections.
So, what are the three projections? They are:
1. Cylindrical projection : Transverse mercator projection is one kind of cylindri-
cal projection. UTM (Universal Transverse Mercator) projection is again the
Transverse mercator projection for the zones of different part of the globe.
2. Azimuthal projection
3. Conic projection
Selecting a proper projection system depends on the accuracy provided by it. Which
is in turn governed by the location of the place on the globe. Every countries in the
world have standardised the use of the projection system. In Nepal, we use two UTM
projections 1) UTM 44N and 2) UTM 45N. We don’t use conic or azimuthal projection.

3.3 Shape of earth


Generally, we would find the explanation about the shape of earth before the projection
system in most of the books. However, I ended up opposite. Anyway, let us briefly touch
this subject.
So, what is the shape of earth? We see a lot of mountains, undulations etc on the
earth. Do they count in the shape of earth? Actually, we are supposed to draw a surface
of same elevation over whole the earth and it should pass through the surface of sea. It
may be easy for some. To make such surface you will have to cut the Everest and fill the
Dead Sea up to the zero-level. Now you might have some idea.
When we draw a surface passing at zero elevation, we will get somewhat ellipsoidal
surface. It is not spherical. The shape can be created by making an ellipse and revolving
around y-axis. Still, the shape is not exactly an ellipsoid. However, for most practical
purposes we take it to be an ellipsoid. Some of the properties of this ellipsoid are
mentioned below:
• Diameter passing from North pole to South pole is less than the diameter at equator.
See Figure 3.4.
• The shape of earth is defined by the diameter at equator and flattening ratio. If
we consider the radii of ellipse as shown in the figure, the flattening ratio will be
given by (a − b)/a.
• There are many approximations of the shape of earth which are in use world wide.
Each of such approximate assumed shape of earth is given a name and called
Datum.
• Most commonly used Datum is known as WGS84. The flattening ratio for WGS84
is around 1/298. The radius at equator is 6378137 meters.
3.4 Projection Transformation 67

Figure 3.4: Shape of earth and its parameters

Datum (the assumed shape of earth) and the projection in combination is used to
define a Coordinate Reference System. Following combinations and many more are
possible:
• WGS84 (datum) and Geographic coordinate system (Without projection)
• WGS84 and UTM 45N (It can represent only 84◦ to 90◦ East only)
• JGD2000 and Geographic coordinate system
• JGD2000 and UTM 53N (some portion of Japan)
We will try to understand some details with exercise.

3.4 Projection Transformation


Let us recall the first exercise where we displayed the world countries. We had used
ne_50m_admin_0_countries shapefile to display data. Let us have a look at the data.
Browse the folder Exercise01 using windows file explorer. You can see multiple file with
the same name but different extensions as:
• ne_50m_admin_0_countries.shp
• ne_50m_admin_0_countries.dbf
• ne_50m_admin_0_countries.prj
• ne_50m_admin_0_countries.shx etc.
These files as a set make up a shapefile which is one of the formats of GIS vector
data. You may not be able to display the data in GIS if any of the files is missing. File
68 Chapter 3. Coordinate Reference System

with extension .prj contains the information about the type of Coordinate Reference
System used in the shapefile.

3.4.1 Assign Projection


The following exercise will show you how to assign projection to a vector data.

Exercise 3.1 Assignment of Coordinate Reference System


We had used some zip files in the second chapter. Let us create a folder Exercise03
and unzip the admin-palika.zip and 1000k.zip.
Let us have a look inside the unzipped folder.
For example, there is a shapefile named admin_ar inside 1000k. The file with
extension .prj is missing. Which means that this shapefile does not have projection
information. Let us try to display it in QGIS. What happens?
You will see a warning message ‘CRS was undefined, defaulting to EPSG:4326
WGS84’. This is because the projection for the shape file is not defined. It is good
that QGIS tries to display the data in default CRS, that is, WGS 84 Geographic
Coordinate system. Now let us do the exercise in steps:
1. Create a folder WGS84 under Exercise03.
2. In QGIS we have displayed admin_ar.
3. In the list panel right click the layer and click Save as.
4. Refer to correspondingfigure and follow the next steps. Number in the brackets
correspond to the number in the figure.
a. In Save vector layer as dialog, click browse (1) and select file name
admin_ar_wgs.shp inside newly created WGS84 folder.
b. Click the pictorial button (2) for selecting the CRS.
c. Coordinate Reference System Selector dialog will be displayed.
Let us observe the dialog. It has six parts. 1) information about
the dialog, 2) Filter, 3) Recently used coordinate reference system
(it will be empty at first), 4) Coordinate systems of the world 5)
Selected coordinate system and 6) detail of the projection. You can
explore the coordinate systems of the world by expanding each one.
d. In the filter write wgs 84 (3). Matching names will be displayed in the list
inside Coordinate systems of the world.
e. Select WGS 84 (4) under Geographic Coordinate system and click OK
(5).
f. Click OK in the Save vector layer as dialog.
3.4 Projection Transformation 69

Let us see the contents of the shapefile inside WGS84 folder. You will see a file
with extension .prj. Zoom the map to the extent of admin_ar layer. Move the cursor
on the map and observe the coordinates in the status bar. The x-coordinates will be
80 to 90 and y-coordinate will be 25 to 30.
Repeat the above exercise for other shapefiles, for example, admin_ln in the
directory 1000k. Let us compare the projection (.prj) files created for each shapefile.
You can open these projection files with Notebook or any text editing software. By
examining the two files you can see that they are completely identical. Which means
70 Chapter 3. Coordinate Reference System

you can:
• copy admin_ar_wgs.prj which is created in the new directory (WGS84) and
• paste into 1000k directory and change the name of file to admin_ar.prj.
• Now, if you add the admin_ar shapefile in QGIS it will not show any warning.
• In the same way, you can copy-paste the projection file and rename it to match
the remaining shapefiles.


3.4.2 Projection transformation of vector data


In the above exercise we assigned the projection to the shapefile. In the next exercise,
we will transform the shapefile, which is currently in WGS84 Geographic Coordinate
system, to another projection. This process is called projection transformation. In the
following exercise, we are going to:
1. Change the CRS of the shapefile of administrative boundaries of Nepal from User
CRS to WGS84
2. Select the features of province 1.
3. Transform the CRS of the shapefile again to UTM 45N.
Let us follow the steps below :

Exercise 3.2 Projection transformation


User CRS to WGS84
a)
1. Create a new folder UTM inside Exercise03
b) In QGIS, click New tool from Project toolbar .
c) You may save or discard previously opened file.
d) Now add the vector layer ADMIN_GAPANAPA inside folder admin-
palika to the map. Observe the right corner of the status bar (figure
@(fig:statusBarCRS). It shows the CRS of the shapefile. We see a small
globe icon and User 100000. This is the CRS of current map. If you
hover over the map you can see some details.
e) Follow the previous exercise and save this shapefile in WGS84 folder as
admin_gapanapa_wgs.
2. Select features from province 1
a) Once again click New tool from Project toolbar and save or discard
previously opened file.
b) Add newly created admin_gapanapa_wgs shapefile to the map. Now
once again observe the CRS (right corner of the status bar). Now it is
EPSG:4326, which means WGS84 and Geographic Coordinate system.
c) From the Attributes toolbar click Select features using an expression
3.4 Projection Transformation 71

tool. This tool has an image of ε.


d) In the Select by expression dialog, write expression as "province" = 1.
e) Click Select at the bottom of the dialog. Close the dialog. You can observe
that the features in the province 1 will turn yellow.
f) By moving the cursor in horizontal direction above the selected features,
you can observe that the coordinates vary from around 86◦ to 88◦ . Which
means the features lie in UTM 45N zone.
3. Transform from WGS84 to UTM 45N
a) Right click the layer and click Save as.
b) In the Save vector layer as dialog, click Browse and save the file as
province_1_utm45n inside UTM folder.
c) Check Save only selected features in the dialog.
d) Click CRS button, CRS selection dialog will appear.
e) In the filter write 45n. From the matching CRS in the list, select WGS
84/UTM zone 45n.
f) Click OK in the CRS selector dialog and then in the Save Vector layer
dialog.
g) Click New tool from Project toolbar. Save or discard the current project.
h) Add newly created province_1_utm45n shapefile. Once again observe the
CRS. It is now EPSG:32645 which means UTM 45N projection. you may
save the project as ‘ex03a.qgs’

3.4.3 What is EPSG?

We saw in the last section that CRS is represented in the form EPSG:n, where n is a
number. So, what is EPSG? It is short form of ‘European Petroleum Survey Group’.
There are many CRS’s in use and EPSG coded all (most of) the CRS and gave a code to
each. Hence, the CRS can be expressed as EPSG:n where n is the EPSG code.
Some EPSG codes and there are name are given below:
• EPSG:4326 WGS84 (World Geodesic System 1984) Geographic coordinate sys-
tem
• EPSG:32644 Project coordinate system at zone UTM 44N based on WGS84 datum
• EPSG:32645 Project coordinate system at zone UTM 45N based on WGS84 datum
http://spatialreference.org/ is the best place to find different spatial refer-
ences (Coordinate reference system), their meaning, locations and codes. You are advised
to spend at least an hour or two to acquaint yourself to the meaning of CRS.
72 Chapter 3. Coordinate Reference System

3.4.4 Projection transformation of raster data


From above examples, we understood that the GIS software can transform vector data
from one CRS to another CRS in simple steps. What is involved in transforming vector
data? Basic element of a vector data are points. Lines and polygons are formed by
joining points. We need to find the coordinates of each point (with known coordinates in
one CRS) in new CRS. It is done by using simple formula. We don’t need to know the
formula of transformation as it is done by QGIS internally. Theory behind the process
of transforming raster data from one CRS to another is a bit complicated compared to
the transforming of vector data. Observe figure 3.5. It shows a rectangular grid created
in WGS84(GCS) on the left and the same when viewed in WGS84(UTM45N). We can
see that the lines are curved and tappering. We know that the raster data are made of
rectangular cells. Therefore, simple transformation of each grid cells cannot produce the
new raster. As such, in principle, we need to create a raster of same size with selected
cell size in new CRS and then copy the values from corresponding cells in the original
raster data. This process is called warping. The process may sound complecated but GIS
accomplishes the task without any difficulty. We will show this in the following exercise.

Figure 3.5: Rectangular grid in two different CRS

Exercise 3.3 Projection transformation of raster data, step by step


We will use the elevation data which we used in Chapter 2. Follow the steps
below.
1. Add raster data (ASTGTM2_N27E086_dem.tif) to the map.
2. Let us observe the data. The CRS is EPSG:4326 which means it is WGS84(GCS).
Right click the layer and click Properties.
3.4 Projection Transformation 73

a) Select Metadata in the dialog box, left pane. You can see various proper-
ties associated with the data. (Note: all GIS data has associated metadata
which gives you many important information).
b) Scroll down the right pane to view the properties section which has its
own vertical scroll bar.
c) Scroll down this section to find various properties such as Statistics,
Dimensions, Pixel Size, Extent etc.
d) You can see that size of each pixel is around 0.000278◦ . The extent of the
data is from around 86 to 87 in x-direction and 27 to 28 in y-direction.
e) If we need to change the data to UTM projection, we need to select the
UTM zone. From the data, it is clear that it lies in UTM 45N zone.
3. From menu, click Raster ⇒ Pro jections ⇒ warp(Repro ject). In the next
steps the numbers in brackets are associated with the numbers in the figure.
4. Select Output file (1) and save the output in the UTM folder.
74 Chapter 3. Coordinate Reference System

5. Check Target CRS (2). Select CRS by writing 45N in the filter and selecting
EPSG:32645 from the list (3).
6. Set the resampling method as Near(4).
7. Set No data values as -9999 (5).
8. Click OK (6). In the confirmation dialogs click OK and finally click Close on
Warp(reprojection) dialog. You may save the project as ‘ex03b.qgs’.
9. Click New tool from the Projection toolbar. Add the newly created raster
elevation data to the map. You can observe the corners by zooming. You can
also find the cell size of the newly created raster data. How?


3.5 Why do we need so many different CRS?


When you tried to select CRS in the last exercises, you might have observed that there
are 100s of CRS in use. You might question the necessity of having so many CRS. Some
points below, can provide you the reason for this.
• WGS84 is the most used datum worldwide. However, the shape of earth assumed
by this datum does not fit well whole the world. As such many countries have
developed different models (assumed shape) of the earth which fits the shape of a
given portion of the earth. Some examples are:
– JGD2000 : Known as Japan Geodetic Datum, it fits the shape of earth at or
near Japan.
– NAD 1983: North American Datum etc
• Geographic coordinate system (GCS) gives the most accurate location of a place.
That is why many GIS data are available in GCS. Examples are:
– Google map
– Many satellite data (ASTER DEM elevation data etc)
• However, it is difficult to show the data on a flat surface.
• Distance, area and other geometric calculations are not possible in GCS.
These are the reasons we need to switch the GIS data from one coordinate system to
another. We also need to work in different projections. That is why, it is necessary to
know which projection we need to work for a given situation. However, we don’t need
to go in depth about the process of transformation and theories behind them. Geodesy, in
itself, is a vast subject which needs effort to master. Meanwhile we can do our GIS with
the knowledge provided in this chapter.
4. Database Management

Database is the backbone of any information system. In this chapter we will learn about
database and its handling in QGIS.

4.1 What is information system


Information is defined in Merriam Webster (https://www.merriam-webster.com/
dictionary/information) as “the communication or reception of knowledge or intel-
ligence”. Information can be obtained from various sources in various ways. In early
days of human civilization we needed very little information. With the modernization our
information need has become very complex. Before we started using computer, most of
the information in a government or commercial organization were kept and maintained
in files and register. As such information retrieval was time consuming. Therefore we
can say that in early times information system consisted of drawers, cabinets, files and
registers. A simple information system consists of:
1. Hardware : Computer
2. Software : Database management software
Information system allows an organization to keep all the information in an organized
way so that it can be easily updated and retrieved. In order to maintain an information
system we need a database management system (DBMS) software. There are several
free and proprietary database management software as listed below:
• PostgreSQL (free DBMS)
• MySQL (free)
• MS Access (Proprietary, Microsoft)
• Oracle Database (Proprietary, Oracle)
76 Chapter 4. Database Management

• SQLite (free) etc.


We will use SQLite to learn some basic functions of database management system.

4.2 Basic tutorial for Database management


First of all, download sample database from https://www.dataquest.io/blog/
python-pandas-databases/. Scroll down to find the link to sample database or down-
load directly from https://www.dropbox.com/s/a2wax843eniq12g/flights.db?
dl=0. The website was accessed on 29ˆth December, 2018. In case you don’t find
the database at the above location, you can download another database from http:
//www.sqlitetutorial.net/sqlite-sample-database/. The two databases are
different however you can work following the steps explained below (some of the steps
may not be possible in another database).
Exercise 4.1 Database tutorial: Observe the database contents
Following tutorial explains how to access a SQLite data base and observe the
information inside the database.
• Save the database (flights.db) inside GIS_Exercise\Exercise04
• Open QGIS.
• Click Menu Database⇒Database Manager as shown in figure.

• Click Menu Database⇒Database Manager. In the new window, we can see


several DM Manager listed.
• Right click Spatialite and click New connection as shown in figure ??.
• In the ‘Choose SQLite/Spatialite file’ dialog box open the ‘flights.db’
• Now flights.db will be listed under Spatialite. We can see that there are 3 tables
airlines, airports and routes listed under flights.db.
4.2 Basic tutorial for Database management 77

We can see that a single database can have multiple tables. Now let us see what
we can do with these tables. Click one of the tables under spatialite. As shown in
the following figure, information about the table will appear on the right pane of DB
Manager window.

Now click Table tab on the right pane. You can see the contents of table. See
figure below (it shows part of the table).
78 Chapter 4. Database Management

You can check the information and contents of each table. Use horizontal and
vertical scroll bars to see the hidden contents. Let us try to observe what kind of data
are kept in each tables. You can easily find the number of records in each table by
just scrolling up and down.


We can retrieve the required information from a Database Management System


(DBMS). Let us see how the following questions can be answered by the DBMS?
 Example 4.1 Sample questions
1. Which and how many countries are listed in the airlines table?
2. How many airports are listed for each country?
3. Which routes are operated by RA (Nepal Airlines)
4. Which airlines are operating from Delhi to Hongkong?


These information can be retrieved by asking questions. There is a standard sentence


format to ask questions to the database table. This is called SQL (Sequential Query
Language, pronounced as S-Q-L or sequel).
Let us now try to answer the above questions. Before that let us try to understand the
basic SQL statements as explained in the following exercise.

Exercise 4.2 Database Tutorial: Basic SQL for Selection


DB Manager window has a tool named SQL Window which adds a SQL
4.2 Basic tutorial for Database management 79

window tab on the right pane. Remember to select the flights database before
opening SQL Editor tool.
• Let us try with simplest SQL. Write SELECT * from airlines; in the Query
window.
• Click execute. See the figure below.

In the above example, we displayed all the rows of the table airlines. Now try some
more complex SQL queries. Try following queries one by one and observe the output.
1. SELECT * FROM airlines WHERE country=’Russia’;
2. SELECT * FROM airlines WHERE country=’Russia’ ORDER BY icao;
3. SELECT id, name, icao, country, active FROM airlines
WHERE country=’Russia’ ORDER BY icao;
4. SELECT id, name, city, country, code, icao, altitude FROM airports
WHERE country=’Nepal’;
5. SELECT id, name, city, country, code, icao, altitude FROM airports
WHERE country=’Nepal’ AND id>2000 AND id<2100;
6. SELECT airline, airline_id, source, dest, codeshare, stops
FROM routes
WHERE source=’KTM’ ORDER BY dest DESC;
The SQL statements are fairly simple and follow general spoken language. Let us
summarize what we observed by executing above SQL statements.
1. General structure of SQL statement is SELECT [columns] FROM [table name]
WHERE [Where clause joined with AND] ORDER BY [columns] LIMIT
[number of rows].
2. Check the information of any of the 3 tables as explained in above exercise. We can
see that each column has a type. For example, airlines table has 9 columns. The
80 Chapter 4. Database Management

column named index is INTEGER while all the others are TEXT. SQLite database
table can have three types of columns (also called fields). They are:
• INTEGER (Can have integer numbers eg., 1, 10, 299,12568833 etc)
• REAL (Represents decimal numbers, such 1.25, 2.5)
• TEXT (Consists of strings such as name of the places etc which are repre-
sented by text)
3. While SQLite supports several types of column such as INTEGER,TEXT, REAL,
DATE, time etc.
4. In the above SQL statements, the words have different colors. The blue colored
words are keywords. Column names are black. Structure of where clause is
writeen in the form: column <operator> value. Where operator can be =, >, <,
LIKE, UNLIKE etc. Note that while comparing text column, the value should
be enclosed in single quote. Integer and real values should not be enclosed into
quotes.

4.3 Using Selection Statements in Database Management


We have got basic idea of the kinds of queries we can execute in SQLite database. Now
let us try to explore some more functions of database manager. Check the output of
following SQL statement.

SELECT airline, airline_id, source, dest, codeshare, stops


FROM routes WHERE source=’KTM’ ORDER BY dest LIMIT 5;

Table 4.1 shows the output of the above SQL.

Table 4.1: Output of the SQL

airline airline_id source dest codeshare stops


EY 2222 KTM AUH None 0
YT 16133 KTM BDP None 0
YT 16133 KTM BHR None 0
YT 16133 KTM BIR None 0
RA 3637 KTM BKK None 0

What is the fullname of airline in the above table? What does BHR mean in the dest
column? These data are kept in other two tables airlines and airports. Can you find
which column of routes is related to airlines table? Similarly, which column of routes
is related to airports?
We can query multiple tables in a single query when one column of a table is
related to any column of another table. Write the following SQL statement and execute.
4.3 Using Selection Statements in Database Management 81

Following SQL is a single SQL. It can be written in multiple lines with semicolon at the
end.
SELECT routes.airline, routes.airline_id, routes.source, routes.dest,
airlines.name,
airports.city, airports.country
FROM routes, airlines, airports
WHERE source=’KTM’
AND routes.airline_id =airlines.id
AND routes.dest_id=airports.id
ORDER BY dest LIMIT 5;
What did we do in the above statement? We selected columns from three tables
such that airline_id column of route table and id column of airlines table are equal.
Similarly, dest_id column of routes table is equal to id column of airports table. With
practice, this type of simple SQLs can be easily mastered. However, it is possible to write
fairly complex SQLs for which you need to refer some proper reference on database
management.
Now let us try to answer the questions in Example 4.1. Following is the solution to
each question. The SQL statements is self explanatory. Try to test some more questions.
• Which and how many countries are listed in the airlines table?
This question needs to be split into two. First let us try to find which countries are
listed in airlines table. If you try to list all the rows, same country will be listed
multiple times. Therefore, we need to us UNIQUE keyword. Try the following
SQL.
SELECT DISTINCT(country) FROM airlines;
You can see that one row in the result shows NULL value. Which means that some
of values in the country column are empty. To omit NULL values in the result,
we use IS NOT NULL as shown in following SQL.
SELECT DISTINCT(country) FROM airlines
WHERE country IS NOT NULL;
You can find the number of countries listed in the airlines table by simply scrolling
down the output of the SQL. However, there is standard SQL query for counting
the number of results, as shown below.
SELECT COUNT( DISTINCT(country)) FROM airlines
WHERE country IS NOT NULL;
• How many airports are listed for each country?
This question is simple one. We need to use (group by) keyword to find the
number of airports in each country as shown in the following SQL example.
SELECT country, count(*) FROM airports
GROUP BY country;
• Which routes are operated by RNA (Nepal Airlines)?
This is question is not very hard. You can try by yourself before looking at the
82 Chapter 4. Database Management

SQL below. Remember that you need to combine all the three tables as the routes
table does not have the listing of the name of airlines or the full name of source
and destination.
SELECT airlines.name, airports.city, routes.dest
FROM routes, airlines, airports
WHERE airlines.icao = ’RNA’ –-International Civil Aviation Organization
(ICAO) code for airport name
AND airlines.id = routes.airline_id
AND airports.id = routes.source_id;
In the above code, we introduced comment. Anything written after – is treated as
comment and will not be executed. We get following table as output by executing
the above SQL.

Table 4.2: Output of the SQL

name city dest


Nepal Airlines Doha KTM
Nepal Airlines Hong Kong KTM
Nepal Airlines Kathmandu BKK
Nepal Airlines Kathmandu DOH
Nepal Airlines Kathmandu HKG
Nepal Airlines Kathmandu KUL
Nepal Airlines Kuala Lumpur KTM
Nepal Airlines Bangkok KTM

This table does not show the destination. If you replace airports.id = routes.source_id
by airports.id = routes.dest_id then you will get only the name of destination city.
Therefore, you need to join two different selection statements as below. We create
two selections. The first selection statement compares the id of table airports
with source_id of routes table. In the second statement we compare the id of
airports table with dest_id of routes table. The two tables are named as t1 and
t2 respectively. Finally we compare the outputs of two selection statements by
using common column which is index column of routes table. Here we need
to remember that some words such as index are reserved words for SQLite and
should be written inside double quote.
SELECT t1.name, t1.city AS from_city, t2.city AS to_city
FROM
(SELECT routes."index", airlines.name, airports.city, routes.dest
FROM routes, airlines, airports
WHERE airlines.icao = ’RNA’ –- ICAO code for airport name
AND airlines.id = routes.airline_id
4.3 Using Selection Statements in Database Management 83

AND airports.id = routes.source_id) AS t1

LEFT JOIN

(SELECT routes."index", airlines.name, airports.city, routes.source


FROM routes, airlines, airports
WHERE airlines.icao = ’RNA’ –- ICAO code for airport name
AND airlines.id = routes.airline_id
AND airports.id = routes.dest_id) AS t2

WHERE t1."index" = t2."index";


• Which airlines are operating from Delhi to Hong Kong?
Let us execute and check the output of following statements.
– SELECT * FROM airports WHERE city = ’Delhi’;
– SELECT * FROM airports WHERE city = ’Hongkong’;
The first statement outputs two rows as expected. However, the second statement
does not produce any result. Sometimes we don’t know the pronunciation of a
word, or there might be multiple pronunciation of same word, especially place
names. If we know part of the text we can write the statement as follows.
SELECT * FROM airports WHERE city LIKE ’h%kong’;
In the above SQL, the names of city in the airports table is compared with
h%kong where % is used as wild card. It can match any text which starts from ’h’
and ends in ’kong’.
Now let us try to answer the above question. Try to think of the logic and make an
SQL statement and execute in the DB Manager before looking the following code.
SELECT t1."index" AS route_id, t1.airline, t1.city AS from_city,
t2.city AS to_city
FROM
(SELECT routes."index", airline, city FROM routes, airports
WHERE routes.source_id = airports.id
AND airports.city = ’Delhi’) AS t1
LEFT JOIN
(SELECT routes."index", airline, city FROM routes, airports
WHERE routes.dest_id = airports.id
AND airports.city LIKE ’h%kong’) AS t2
WHERE t1."index"=t2."index";
The above SQL outputs as in the Table 4.3.
Table 4.3 shows the abbreviated form of the airline names. You need to consider
airlines table in the SQL statements so that name of airlines could be output instead of
the abbriviated form. Try to write a SQL which outputs the names of airlines in stead of
abbriviation.
84 Chapter 4. Database Management

Table 4.3: Output of the SQL

route_id t1.airline from_city to_city


4078 9W Delhi Hong Kong
10418 AI Delhi Hong Kong
17852 CX Delhi Hong Kong
24160 EY Delhi Hong Kong
44970 OZ Delhi Hong Kong

Observe the information contents of each table again and think about what further
information you can get from these tables. You need to practice writing SQL to improve
your understanding of SQL.

4.4 Creating and editing table in a database


In the previous section (4.3) we tried to retrieve information from single and multiple
tables using simple to complex SQL statements. The three tables were available for the
exercise. Now let us create a table from scratch.
Exercise 4.3 Creating table in SQLite database
We need to write a SQL statement as shown below to create a new table.
CREATE TABLE daily_flights (fid INTEGER PRIMARY KEY autoincrement,
departure TIME, arrival TIME, price REAL);

Above SQL creates a new database. After executing the SQL, if the daily_flights
table does not appear in the list then click on the Refresh tool in DB Manager window.
Select Info tab on the right pane. You will see the information about the table as
follows.


Table 4.4: Field and types of new table

cid name type


0 fid integer (auto increment)
1 departure time
2 arrival time
3 price real

After creating a table, we need to fill it. New rows are add by using INSERT
keyword. Practice the following exercise.
4.4 Creating and editing table in a database 85

Exercise 4.4 Insert rows and edit data in the table


In the above table, we forgot to add route_id column which is the main key to
relate with the index column of routes table. Without this column we cannot know
the flight route. We could have written a complete SQL in the previous exercise which
is much preferred. However, we can add columns to a table by using SQL. We can
insert rows of data into table. Let us see what kinds of editing can we do with the
newly created table.
1. Add new column to table
The syntax of adding new column is: ALTER TABLE [table name] ADD
COLUMN [column name][data type];
ALTER TABLE daily_flights ADD COLUMN route_id REAL;

2. Insert data rows


Data rows are inserted by using following syntax:
INSERT INTO [table name] ([columns separated by comma])
VALUES ([values separated by comma and using appropriate quoting]);

Write the following SQL statements in the SQL window and execute one by one.
Remember that time column needs to be written as HH:MM or HH:MM:SS.
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’09:30’, ’13:30’, 313.55, 4078);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’21:30’, ’01:30’, 400.0, 10418);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’12:15’, ’16:15’, 425.70, 4078);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’12:45’, ’17:30’, 290.00, 17582);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’18:10’, ’23:00’, 600.00, 10418);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’19:30’, ’23:40’, 520.00, 24160);
INSERT INTO daily_flights
(departure, arrival, price, route_id)
VALUES (’04:30’, ’07:50’, 250.0, 44970);

ALTER TABLE daily_flights ADD COLUMN duration REAL;


86 Chapter 4. Database Management

Now observe the contents in the table by selecting table tab in the right pane
of the DB Manager window.
3. Update table
Now let us try to find the duration of each flight. Add duration column to the
table as follows.
ALTER TABLE daily_flights ADD COLUMN duration REAL;
In the newly created column let us try to enter the value of duration. When the
new column is created, all the values are filled by NULL. To change any value
in a column we need to use UPDATE keyword. To do mathematical operation
with time column we need to use a function called julianday. Try the following
SQL to update duration column.
Following syntax is used to update column(s) of table.
UPDATE [Table name] SET [[Column = value],[Column=value]. . . ] WHERE
[Where clause]
UPDATE daily_flights SET duration=round((julianday(arrival) -
julianday(departure))*24.0,2);
Try to use the above SQL without round function. You can also create another
column and fill it with price in different currency.


4.5 Information System vs Geographic Information System


So far we have discussed about the database management which does not contain
any information about geographic location. By adding geographic information to the
database, we can turn it into spatial database and the system into geographic information
system.

4.5.1 Converting non-spatial database to spatial database


The flights database consists of three tables. One of the tables, airports, contains two
columns: latitude and langitude. They are just numerical values. We can convert this
non-spatial table into spatial table using the latitude and longitude. We need to do some
operations out of QGIS. Follow the exercise 4.5.
Exercise 4.5 Convert to spatial database
For converting non-spatial database to spatial database, we need to add some
tables related to coordinate reference system(CRS). The process is not very straight
forward. We need to use command line interface in windows. The exercise steps are
listed below.
1. Start command line as administrator. See figure and steps below.
• Click start button.
• Type cmd.
• Right click Command Prompt and select Run as administrator
4.5 Information System vs Geographic Information System 87

2. Load spatial extension.


• In the command prompt change directory to QGIS binary by typing cd
"C:\ProgramFiles\QGIS3.2\bin"
• To run SQLite database, type command sqlite3 D:/GIS_Exercise04/
flights.db
• In the sqlite3 environment, type select load_extension("mod_spatialite.dll");
and enter.
• Type SELECT InitSpatialMetaData(); and enter. (Note: This com-
mand may take a few minutes to complete.)
3. Make a vector point data from airports table.
• Copy airports table and create table airport_pt using following SQL.
(Note: The SQL can be run in the same command prompt or inside DB
Manager)
CREATE TABLE airport_pt AS
88 Chapter 4. Database Management

SELECT * FROM airports;


• Now add geometry column to our newly created table airport_pt using
the following SQL.
SELECT AddGeometryColumn( ’airport_pt’ , ’geom’, 4326, ’POINT’,
’XY’);
If you explore the info of the table airport_pt you can see a column
named ‘geom’ is added to the table, however, all the value in the column
are NULL. We need to update the column using function makepoint as
in the following SQL.
UPDATE airports_pt SET geom = makepoint(CAST(longitude AS
REAL), CAST(latitude AS REAL), 4326);
We use CAST longitude as REAL because the type of column longitude
is text. We need to convert it to REAL (Double precision).
• After executing the above SQL, right click flight.db in the DB Manager
and click Re-connect. Now the airport_pt table will be shown as vector
data table. When you click airport_pt table, Preview tab on the right
pane will become active. Select Preview tab and observe. We can add
the layer to QGIS canvas by double-clicking airport_pt table in the list.
4. Make a vector line data from routes table.
• It is necessary to join routes table and airports table and obtain the
coordinate of source location and the destination location for each route.
Following SQL can be used for this purpose.
CREATE TABLE route_line AS
SELECT t1."index" AS id, t1.longitude AS lon1,
t1.latitude AS lat1, t2.longitude AS lon2,
t2.latitude AS lat2
FROM
(SELECT routes."index", airports.longitude,
airports.latitude
FROM routes, airports
WHERE airports.id = routes.source_id) AS t1

LEFT JOIN

(SELECT routes."index", airports.longitude,


airports.latitude
FROM routes, airports
WHERE airports.id = routes.dest_id) AS t2

WHERE t1."index" = t2."index";


• Add geometry column to the newly created database table route_line by
4.6 Summary of database management system 89

executing the following SQL in the DBManager window.


SELECT AddGeometryColumn(’route_line’, ’geom’, 4326,
’LINESTRING’, ’XY’);
• Update geometry column geom. To update geometry column with lines,
we need to join two points created from 1. lon1 and lat1 & 2. lon2 and
lat2. Following SQL shows how to accomplish this.
UPDATE ’route_line’
SET geom=makeline(makepoint(CAST(lon1 AS REAL),
CAST(lat1 AS REAL), 4326),
makepoint(CAST(lon2 AS REAL),
CAST(lat2 AS REAL), 4326));
Load route_line to the QGIS canvas by double clicking. Now the canvas
looks like the following figure.

4.6 Summary of database management system


Now let us summarize the properties and functions of database management system in
GIS.

4.6.1 Definition of database and DBMS


Definition 4.6.1 Database
Database is defined as organized collection of data. (Wikipedia)

Definition 4.6.2 Database Management System (DBMS)


DBMS is a software which provide creation, editing etc of a database. A DBMS
provide following functions.
1. Create database (We did not practice in this session)
2. Update database
• Creating, deleting database table.
• Adding or deleting columns to a table.
90 Chapter 4. Database Management

• Inserting or deleting data rows to/from a table.


3. Query database
Querying a database is basically about selection of data rows from single or
multiple tables. We practiced simple to complex selection statements using one
more than one tables. We can get variation information from database using
queries.
4. Analyze database
5. Database administration
Wikipedia defines database administration as the function of managing and
maintaining database management systems (DBMS) software.
Purpose of database administration is to keep database up to date as well as to
keep the database software updated so as to use state of the art technology.

4.6.2 DBMS applications


There are various software which deal with the database management. Some of them
are listed in the introduction of this chapter. Apart from these software, GIS also
provides interface and tools to deal with database. We can do almost everything related
to database management within GIS. QGIS provides to deal with MySQL database,
Spatialite database, PostGIS (Spatial extension of PostgreSQL) database etc. We already
dealt with SQLite and Spatialite database and practiced variatio functions related to
DBMS.

What are the components of database?


A database mainly consists of files or tables with fields (columns) and records (columns).
Figure shows the structure of a database table.

Interaction between GIS and DBMS


GIS can interact with GIS using DBMS. For example, PostGIS database, SQLite database
provide functions to deal with their own database. Other way for GIS to interact with
database is to use its own tool to perform all the functions of database management.
QGIS provides both options to interact with database.

Rules of DBMS
There are some rules of DBMS which needs to be considered while managing database.
1. Each column in a table must be unique. No two columns should have same name.
2. Order of columns does not matter.
3. Order of rows does not matter.
4. Each column (field) should have same type of data (text, integer, double, timestamp
etc). We cannot put text and integer data in the same column. Once we create
table, all the column types are also defined. Whatever data we keep in the column,
it will be either treated as defined type or it will raise error. For example, if we
4.6 Summary of database management system 91

Figure 4.1: Structure of database table

insert real (decimal) data in a text column, the data will be treated as text. If we try
to insert text data into a integer column, the DBMS will not accept such operation.
5. Each table should have a primary key. It is suggestion rather than rule. There
should be at least one column which should have only unique values. We can
define a column to accept unique values by adding primary key to the definition.
Such as :
Create Table abc
fid integer primary key,
name text,
...
In the above table, fid column will not accept repeated values.
6. Tables are related to each other.
As we saw in the flights database we used in the exercises, routes table is related
to both airlines and airports table. As the tables are related to each other, it is
also called relational database. Similarly, DBMS is sometimes called RDBMS.

Types of fields (attributes)


There are so many different types of attributes which some of the DBMS support and
others do not. Some the attribute types are listed below.
• Text (or String or Character with specified length)
92 Chapter 4. Database Management

• Integer (Short and Long in ArcGIS)


• Double (real, double precision etc)
• Time (date or timestamp etc)
• Boolean : True or False
5. Working with Vector Data

Main purpose of GIS is to display the features on earth in an understandable way and
to make it possible to analyze the location based data. First of all we need to represent
features on the earth in the form which computer can understand. As we practiced in
first two chapters, we know that features on the earth can be represented as vector data
and raster data. In this chapter, we will talk about vector data in some more details.

5.1 Types of vector data (Geometry)

In chapter 2 we learned that vector data are mainly of three types. They are
1. Point: Features on the earth such as airports, buildings, trees, sports stadium can
be represented in the form of points.
Points are stored in GIS in the form of a pair of x and y coordinates.
2. Line (or polyline): Linear features such as road, river, electric power line, water
supply pipe lines, contour lines etc can be represented as lines.
Polylines are stored as list of points which form the line.
3. Polygon: Enclosed areas such as political boundaries, lakes and ponds, land use
boundaries etc are represented as polygon geometry.
Polygons, same as polylines, are also stored as a list of points with last point
coinciding with the first one.
There is no fixed rules regarding what features should be represented by which type
of geometry. Sometimes we need to show the details of roads, buildings and rivers. In
such cases, these features are represented as polygons.
94 Chapter 5. Working with Vector Data

5.2 Vector GIS Data Formats


In chapters 1 and 2 we displayed different vector layers in QGIS. In these two chapters
we used shapefile format which is developed by ESRI. Similarly, in chapter 4 we created
vector data from non-spatial sqlite database. There are several other vector data formats.
As explained earlier, try to add vector layer to the map canvas. Open the source
database and click the filter beside the file name (see Fig.5.1), in the filter you can see All
Files or any other filter). Click the filter. You will see a list of vector database formats.

5.2.1 File based vector data

Figure 5.1: Vector data formats

Let us have a look at some of these file based vector data formats.
1. ESRI shapefiles: This is one of the most used vector data formats. Every single
single shapefile consists of at least three files with the same name and different
extensions (viz. shp, shx and dbf). Files with extensions shp and shx stores the
location information of all the features of vector data. Files with dbf extension
consists of the attribute data which can be opened with MS Excel or any spread-
sheet software such as Libreoffice Calc etc. Each shapefile consists of single type
of vector data. That is, you can not have multiple types of geometry in a single
shapefile.
2. Geopackage: A GeoPackage is an open, standards-based, platform-independent,
portable, self-describing, compact format for transferring geospatial informa-
5.2 Vector GIS Data Formats 95

tion. The GeoPackage standard describes a set of conventions for storing the
following within a SQLite database: vector features. (source: https://www.
opengeospatial.org/standards/geopackage).
3. Spatialite: SQLite is a file based relational database management system. Spatialite
is a spatial extension to SQLite. In the last chapter we covered spatialite in detail.
One single database should be used for one project.
4. Comma seperated value: You can create a text file and enter attributes and x,y
coordinates separated by comma as shown below.
place, country, latitude, longitude
Eiffel tower, France, 48.8584, 2.2945
Taj Mahal, India, 27.1750, 78.0422
Pashupati Nath, Nepal, 27.7105, 85.3487
5. Keyhole markup language (kml or kmz): kml is an xml based format developed
by google and used by google earth. It is similar to html with user defined tags.
You can try drawing points, lines and polygons in google earth. After drawing
these shapes you can save it as kml. As such, one single kml file can have multiple
vector data types (viz. point, line and polygons).
6. GPS eXchange format (gpx): GPX, or GPS Exchange Format, is an XML schema
designed as a common GPS data format for software applications. It can be used
to describe waypoints, tracks, and routes. The format is open and can be used
without the need to pay license fees. Location data (and optionally elevation, time,
and other information) is stored in tags and can be interchanged between GPS
devices and software (source: wikipedia). Recently, most of the smart phones
have GNSS (Global navigation satellite system) chips which gives location of the
device by communicating to the navigation satellites. Many smart phone apps
record location data in gpx format. We will talk in detail about GNSS in next
chapter.

5.2.2 Relational database management system (RDBMS)


Apart from file based vector data, we can also use several relational database management
systems (RDBMS). RDBMS are very useful and most of the websites use server based
RDBMS for managing their information system. RDBMS software provide multiple
connections to the database simultaneously. As such, multiple users can query or update
the same database at the same time. Most of the information we get from websites are
managed by these database management systems. Some of these RDBMS are listed
below.
1. PostGIS: PostGIS is based on PostgreSQL which is one of the most widely used
open source database management system. PostGIS provide full fledged GIS
without mapping interface. QGIS provides interface to connect with PostGIS
database and do all types of GIS analyses.
2. MSSQL: It is developed and licensed by Microsoft. It is also widely used in server
96 Chapter 5. Working with Vector Data

based system, however it needs commercial license for implementation.


3. Oracle: Oracle is a commercially developed RDBMS and is owned by Oracle
corporation. It is considered as number one RDBMS owing to its functionality.
4. DB2: DB2 is also a commercially owned RDBMS developed by IBM corporation.

5.2.3 Internet based vector data provider


There are few internet based protocols which can be used to provide GIS data over web.
QGIS can access these services and display the GIS data online. Some of these services
are described below.
1. Web Map Service (WMS): The OpenGIS R Web Map Service Interface Standard
(WMS) provides a simple HTTP interface for requesting geo-registered map
images from one or more distributed geospatial databases (source: Open Geospatial
Consortium website at http://www.opengeospatial.org/standards/wms).
2. Web Feature Service (WFS): WFS Interface Standard provides an interface allow-
ing requests for geographical features across the web using platform-independent
calls. (source: Wikipedia)
3. ArcGIS map server: ArcGIS provides several web based map data.

5.3 Characteristics of vector data


As we explained above, vector data are represented mainly as three different geometries.
For example, airport table we used in the last chapter is a point geometry. Each airport is
represented as a single point. In the database terminology, each row of the table is called
record. In GIS these records are known as features. Similarly, if we draw lakes or ponds
as polygon, each single polygon will be one single feature. Every feature of vector data
carries spatial as well as non-spatial information. There are following characteristics of
vector data.
1. Type or classification: We can classify any feature class into different types.
For example, roads can be classified into earthen, gravel and paved. Similarly,
buildings can be classified into residential, academic, government etc.
2. attributes: Each feature class has different attributes. The attribute types can be
further classified into 1) Qualitative and 2) Quantitative. Qualitative attributes
generally store textual information such as name of a place etc. Quantitative
attributes can be:
• Ordinal (or ranking): Such as 1st , 2nd , 3rd etc or hazardous area, moderately
hazardous area, safe area etc.
• interval: Such as age groups (0-10, 10-20, 20-30 etc).
• ratio: Such as length (1m, 2m,3m etc).
3. Geometry: As explained above, a feature can have point, polyline or polygon
geometry.
5.3 Characteristics of vector data 97

4. Relationship: Features are related to each other in terms of location. Following


examples illustrate the concept of relationship.
• Pashupati Nath temple is inside Kathmandu metropolitan city (a point feature
of one feature class is inside a polygon feature of different feature class).
• Bagmati Zone shares boundary with (adjacent to) Janakpur Zone (One
polygon of a feature class is adjacent to another feature of same class)
• Watershed of Bagmati river overlaps with several districts’ boundaries.
• The Ring Road intersects Araniko highway.
• Nearest hospital from my village is at 2km distance
Bold texts in the above statements represent the relationship between different
feature geometries. Geometric relationship between different features provides the
basis for analysis of vector data.
Table 5.1 (matrix) shows the relationship between two different geometries.

Table 5.1: Relationship between different geometries

Point Line Polygon


Point • Is neighbor of • Is near to • Is within
• At a certain distance to • Lies on
Line • Crosses • Is within
• Join • Intersects
Polygon • Overlaps
• Adjacent to
• Is within

5. Quality: Quality of GIS data refers to accuracy. While selecting a GIS data, we
need to take account of different types of errors. It is not possible to get perfect
data by any means. Let us discuss about the different kinds of accuracy and error
in GIS data.
• Positional accuracy: Positional accuracy is related to the error in the geometry.
It is impossible to determine the exact position of any point. However, it
is possible to talk about the level of precision. For example, engineering
surveys using high precision equipment may provide an accuracy in the range
of millimeters while accuracy of data collected by smart phone GNSS can be
in the range of tens of meters. Acceptable level of precision depends upon
the purpose. If we want to do reconnaissance survey of location of landslides
along a road corridor, level of accuracy provided by GNSS based survey
can be acceptable and most economic and fast. But if we want to map the
land property boundary, we will need accuracy in the range of few tens of
98 Chapter 5. Working with Vector Data

centimeters.
• Attribute accuracy: GIS data always consists of attribute data. An attribute
data especially quantitative data may not be always correct. Different means
are used to collect attribute data. Let us suppose that we have to find number
of buildings in different wards of a municipality. If we have high resolution
imagery (e.g. aerial photograph), we can easily count exact number of
buildings. However, if we want to do household economic survey, it will be
very difficult to get exact data due to different but obvious reasons. In this
case also, acceptable accuracy of attribute data depends upon the purpose of
analysis.
• Temporal accuracy: Temporal accuracy refers to whether a GIS data is
accurate for the time it is being considered. For example, a data gathered 10
years ago cannot be correct at present. Therefore, we should check the time
of the data collection and its utility for the purpose.
• Logical consistency: Some GIS data are not logically consistent. Logical con-
sistency generally applies to the adjacent features of a vector data. The Seven
Bridges of Königsberg written by Leonhard Euler in 1736 is a historically
notable problem in mathematics which laid the foundations of graph theory
and prefigured the idea of topology.(See https://www.esri.com/news/
arcuser/0401/topo.html and https://en.wikipedia.org/wiki/Seven_
Bridges_of_K%C3%B6nigsberg).
GIS provides some tools for checking and repairing logical inconsistency.
However, for some of logical inconsistencies, it will be necessary to find
some work around. Following examples elaborate the meaning of logical
consistency.
a. Boundaries of two adjacent districts overlap or have gaps. This type
of error occur when the GIS data is created by digitizing (as explained
later).
b. Same boundary is traced multiple times while digitizing.
c. Sometimes two separate adjacent polygons having gaps or overlap are
merged together to form a single feature. Small polygons appear where
there at the gaps. These polygons are called silver polygons.
d. When manually digitizing contour lines, error may accrue as a result of
overlapping contour lines.
e. Intersecting lines, in some cases, may be inconsistent. For example, if
a road network does not have any overpasses, then there should not be
any line feature crossing other line. They should meet at some vertices.
• Data completeness: While doing a GIS project, we need to gather data from
various sources. We need to check whether the data covers whole of the
geographical area of the project and whether all the attributes needed for our
5.4 Sources of vector data 99

purpose is available.

5.4 Sources of vector data


We used various vector data in the first two chapters. The question is, "Where does those
data come from?". As estimated by various researchers, production or acquisition of
GIS data costs more than 60% of the total cost of a GIS based project. There are many
sources of GIS data. Major part of the GIS data is produced by government agencies as
they have the resources and fund to collect and acquire data. Compared to developed
countries, Nepal is poor in GIS data repository as well as its management. Broadly
speaking there are three ways to acquire data.
1. From government and non-government organizations
2. Derive from remote sensing images and aerial photographs
3. Surveying using traditional equipment or GNSS receivers

5.4.1 Governmental and non-governmental organization source of GIS data


There are few government ministries and department in Nepal which create, acquire and
manage GIS data for various purposes. They also provide these data to the users. They
are listed below:
• Department of Survey under Ministry of Land Management, Cooperatives and
Poverty Alleviation provides GIS data such as: Administrative boundaries, roads,
river and other infrastructures, land use maps etc. It possesses various infrastructure
and resources to produce these maps. Department of Survey is also responsible
for managing high precision geodetic network and other stations with known
coordinates of high accuracy.
Department of survey provides few data free of cost which can be downloaded
from its website. They also provide various data at nominal price, such as: contour
data, land use data etc.
• Department of Mines and Geology provides data related to geology at some price.
Detail information about the type, scale and price of these data can be found at
https://www.dmgnepal.gov.np/general-geology.
• Department of Hydrology and Meteorology provides various data related to hy-
drology and meteorology at some price. However, many data and reports can be
downloaded for free.
• Central Bureau of Statistics provides various census data related to population,
economics etc. Many data and reports are available for download for free.
• Other department and government and non-government agencies also produce and
acquire GIS data according to the requirement. Such as, data about road network,
bridges and traffic can be obtained from Department of Roads.
• Many non-governmental organizations (NGOs) and international non-governmental
organizations (INGOs) also produce GIS data as they support government projects.
100 Chapter 5. Working with Vector Data

These data and their can be searched through their websites or by visiting the
concerned organizations.

5.4.2 Derivation of data from remote sensing images


Recently, remote sensing has become major source of data. Various government and
private agencies world wide provide remotely sensed images to the users. Many of these
images, especially low resolution images, are available for download without any cost,
while high resolution images are sold at some cost. Department of survey had, in the past,
used aerial photographs to create land use data and contour mapping using stereoscopes.
In the second chapter, we downloaded some image data and displayed it in GIS. In
the next chapter, we will learn how to deal with raster data and how to derive secondary
data from such imagery. In this chapter, we will do a simple exercise to extract GIS data
from an image to understand the concept.

5.4.3 Engineering survey and GNSS based survey


Traditionally, most of the GIS data was acquired by civil engineering survey. Various
instruments, such as: theodolite, plane table and other instruments, have been used since
last many decades. Most of the maps thus produced were paper based maps. In the past,
these maps were used for design of civil engineering infrastructures. Specially trained
drafts persons were employed to create those paper maps. Scan of those maps were
provided to users by scanning them and known as blue-print. Recently, some of these
maps have been digitized to make them easier to manage and handle.
Recently, with development of highly accurate GNSS technology, it has become
possible as well as easier to create GIS data. As explained in the next chapter, it is
possible to do GNSS based survey at very lost cost. Owing to this, many organizations,
such as even local government offices, have started to invest in producing GIS data on
their own. Many mobile based apps and their producers provide options to do app based
survey and uploading to the websites. Multiple people can thus be employed to complete
acquisition of GIS data in short time and little resources.

5.5 Deriving GIS data from text documents and images


In this section, we will try to create GIS data from text documents and images.

5.5.1 Creating GIS data from text documents


QGIS supports various text formats. We can use Excel or delimited text files as data layer
for GIS. For the following exercise we will download an excel file of meteorological
stations of Nepal from https://www.dhm.gov.np/download/. There are many pdf
and excel files listed in the website. Download the excel file listed as Meteorological
Stations List Updated on 2009-12-22. Save the file as ‘metStations.xls’ or you can
change the name after downloading.
5.5 Deriving GIS data from text documents and images 101

For using an excel file as data layer for QGIS, the excel file should be properly
formatted. We will format the excel file properly before adding to QGIS as data layer.
There are two ways to use the excel file to create vector layer:
1. Add excel file to the QGIS Layers panel and create vector data using SQL.
2. Save excel file as CSV and add to QGIS as delimited text layer.
Each of the above methods will be explained in the following examples.
Exercise 5.1 Method-I: Add excel as data layer and create vector data
In this exercise we will use the excel file directly. Follow the steps below.
Step-I. Edit the excel file.
1. Open the excel file with MS Excel or LibreOffice Calc or any other spread-
sheet software.
2. Create one more sheet which will be named as Sheet3 by default.
3. Copy only the data rows from the first sheet to the newly created sheet.
Keep the first row empty, that is, paste the data to the second row.
4. Add headings in the first row. Your new sheet should look like as shown in
the Figure .

Step-II. Add the data to QGIS.


1. Drag excel file in the list in Browser panel to the map canvas.
2. Select Sheet3 from the list of layers in the new dialog (see figure).

Step-III. Create vector data from data layer using SQL.


1. Open DB Manager using menu Database⇒DB Manager.
2. In the left pane of DB Manager expand Virtual Layers ⇒ QGIS layers.
Single layer metStations will appear under QGIS layers.
3. Open SQL Window in the DB Manager and write SQL as:
102 Chapter 5. Working with Vector Data

SELECT *,
makepoint(
(floor(long * 0.01) +
(long*0.01 - floor(long*0.01)) * 5.0/3) ,
(floor(lat * 0.01) + (lat*0.01 - floor(lat*0.01)) * 5.0/3)
, 4326
) AS geom
FROM "metStations Sheet3";
Note that the latitude and longitude in the excel file are written as degree
and minute without any separator. As such, we need a bit complex formula
to convert them in to decimal degrees.
4. Load the output of the SQL as vector layer (see figure).

5. You can add the vector data of national or state boundary of Nepal. Change
the symbol based on station type etc to make it more presentable as shown
in Figure 5.2.


After categorizing the metStations layer and applying proper symbols, the image is
produced in layout manager as follows.

Exercise 5.2 Method-II: Add delimited text layer


In this exercise, we will create vector layer from text data. We will do this in two
steps.
• Create csv (comma separated text) file from excel file we used in previous
method.
• Add csv file as vector layer
Step-I. Edit the excel file and save as csv.
1. We saw in last exercise that the latitude and longitude values needs to be
re-calculated using formula. Therefore, we will do it in excel itself.
2. In excel add two columns newlong and newlat respectively.
3. Write the following formula for newlong column.
= FLOOR(H2 ∗ 0.01) + (H2 ∗ 0.01 − FLOOR(H2 ∗ 0.01)) ∗ 5/3
Where old longitude value is in column ‘H’
4. Write the following formula for newlat column.
= FLOOR(G2 ∗ 0.01) + (G2 ∗ 0.01 − FLOOR(G2 ∗ 0.01)) ∗ 5/3
5.5 Deriving GIS data from text documents and images 103

Figure 5.2: Map of weather stations of Nepal

Where old latitude value is in column ‘G’


5. copy the two values to all the rows.
6. Save excel file for future use. Again save the file as CSV. It can be done by
using Save as menu in Excel.
Step-II. Add delimited text layer to QGIS
1. Select menu Layer ⇒ Add Vector Layer ⇒ Add delimited text layer.
2. There are several useful options in the dialog which can help you for future
reference. Change the options as follows:
• Select file (metStations.csv) by clicking browse button beside File
Name.
• File format: Select radio CSV
• Geometry definition: Select radio Point coordinates, select newlong
for X field and newlat for Y field.
3. Click Add button. The vector layer is added as expected. Symbolization
can be done as in previous exercise (refer Figure 5.2).

104 Chapter 5. Working with Vector Data

5.5.2 Creating data from images


As discussed earlier, recently, most of the GIS data are created from aerial photographs
and remotely sensed images. Images are termed as raster data in GIS terminology. We
will discuss about raster data handling and remote sensing technology in later chapters.
However, we will use an image, in this section, to create GIS data.
We will download an image from a website and use it as base data for the creation of
vector data. Next, we will download some vector data from openStreetMap. The process
of creation of data will follow the steps below:
• Georeferencing image data
• Digitizing the feature layers
First of all, let us download the image from https://emergency.copernicus.
eu/mapping/list-of-components/EMSR125. This website contains several images
produced after big earthquake, named as Gorkha earthquake, which occurred in 2015
causing large scale fatalities and economic losses. For the present exercise we will use
the image of Kathmandu, however, you can use any other image you are familiar with.
There are links to image data in formats: jpeg, tiff and pdf with various resolutions. We
will download jpeg image with the resolution of 300dpi from the above mentioned url.
After downloading the image, change its name to eqKTM.jpg.
Georeferencing
Before I explain the meaning of Georeferencing, let us try to add jpeg image layer to
GIS. What will happen?
1. QGIS will prompt for the CRS of the image data. If
2. After displaying the layer in QGIS, move the cursor to the top left of the im-
age. The x and y coordinates displayed in the status bar will be almost equal to
zero. Similarly, if you move the cursor to bottom right corner of the image, the
coordinates will be approximately 10000 and 7000 respectively.
What is the meaning of these coordinate values?
The image in the question does not have any association with the geographic locations.
Therefore the image is displayed in its pixel coordinates. For displaying an image
properly in GIS, it should have defined geographic location and extent. Once an image
is associated with actual geographic location, it is called geolocated image. In order to
associate the downloaded image with geographic location it is necessary to do some
geographic orientation and scaling based on the known locations. Such process is known
as Georeferencing in GIS.
Pixel coordinates vs geographic coordinates
Images saved by non-GIS software does not contain geographic coordinates. As such,
images contained in the reports and documents needs to be georeferenced. Following
figure (Figure 5.3) shows the comparison between pixel coordinates and geographic
coordinates.
Once we know the actual coordinates of some of the points, it is possible to georefer-
ence an image. Following section describes the concept of georeferencing. You can also
5.5 Deriving GIS data from text documents and images 105

Figure 5.3: Pixel coordinates and geographic coordinates

get some idea about georeferencing at http://desktop.arcgis.com/en/arcmap/


latest/manage-data/raster-and-images/fundamentals-for-georeferencing-a-raste
htm.

Concept of Georeferencing
First order polynomial transformation is used to align a non-georeferenced image. Let us
suppose that a point in pixel coordinate is represented by P(x, y) and the same point in
the geographic coordinate is represented by (x0 , y0 ). Then the following two equations
will be used to transform pixel coordinates to geographic coordinates.

x0 = Ax + By +C (5.1)

and

y0 = Dx + Ey + F (5.2)

We need to find the value of six coefficients/constants, viz: A, B,C, D, E&F. If we


know the actual (geographic) coordinates of at least 3 points then the two equations can
be solved for these coefficients/constants.
106 Chapter 5. Working with Vector Data

QGIS has georeferencing plugin pre-installed and available under Raster menu. If
you cannot find the sub-menu for georeferencing, you can display it by following the
steps below.
• Select menu Plugins ⇒ Manage and Install plugins.
• In search box, type georeference.
• While typing in the search box, you will see the list of matching plugins. Check
the box for Georeferecer GDAL.
Now, the Georeferecer menu appears under Raster menu.
Now, let us try to practice georeferencing. As we explained earlier, we need to know
the geographic locations of three points. We can see that image we have downloaded has
grid lines as well as coordinate values written over it. In such cases, it is possible to find
the coordinates of various locaions easily. However, sometimes, we cannot find labeled
images. In such cases, we need to find some vector data with known coordinates and
match the locations visually. We will practice both of these methods in the following
exercises.
Exercise 5.3 Georeferencing by visual matching
For this exercise we need vector data for matching. There are various sources
of GIS data. However, for this exercise, we will download vector data from Open-
StreetMap. We will match this vector data with the image as explained in the following
steps.
Step-I. Download osmdownloader plugin.
Osmdownloader can be downloaded as follows (You will need internet connec-
tion to accomplish this task):
• Select menu Plugins ⇒ Manage and Install plugins.
• In search box, type osmdownloader.
• While typing in the search box, you will see the list of matching plugins.
Select OSMdownloader and click Install button on the bottom right
corner of the dialog.
Now, an icon with a rectangle and an arrow will appear in the toolbox.
This is OSMDownloader tool.
Step-II. Download osm data and display it in QGIS.
1. If you don’t have QuickMapServices plugin installed, then install it in the
same way as other plugins.
2. Select menu Web ⇒ QuickMapServices⇒ OSM ⇒ OSM Standard. A world
map will appear in the map canvas.
3. Zoom the map to the area of Kathmandu.
4. Click OSM Downloader tool and draw a rectangular area around Kathmandu
valley. The extent of the rectangle will appear in a new dialog (see figure
5.5 Deriving GIS data from text documents and images 107

below).

5. Browse the file location for saving the data.


6. Check the box to load the layer after completion of download.
7. Click OK. The file is heavy and could take several minutes or more depend-
ing upon the speed of internet access.
8. After completion of download, a dialog with a list of 5 layers will appear.
You may select all and display.
Step-III. Georeferencing
1. Before starting of the georeferencing, remove OpenStreetMap layer from
Layers panel.
2. It seems that it takes too much time to render (when using zoom, pan
tools etc) the vector data downloaded from OSM. It will be better to save
lines as different format. Right click lines layer and save as Shapefile or
Geopackage file.
3. Remove all the layers of OSM.
4. Default CRS of OpenStreetMap is EPSG:3857 (WGS84:Pseudo Mercator).
As such, the CRS of the map canvas will also be EPSG:3857. We need
to change the CRS of the project by clicking the CRS definition at the
bottom right corner of the interface. In the following dialog you can select
EPSG:4326.
5. Open georeference interface by clicking menu Raster ⇒ Georeferencer.
6. In the Georeferencer window open the jpeg image saved eqKTM.jpg.
Select CRS as WGS84 geographic coordinate system.
7. You will have to match this image with the vector data (mainly roads)
displayed in the map canvas. Before doing the exercise, it will be better to
be acquainted with the vector data by zooming and panning etc.
8. Zoom the map to the area which looks familiar and displayed the labels
using attribute name. Singh Durbar area looks as below.
108 Chapter 5. Working with Vector Data

9. Zoom the image in Georeferencer interface around Singh Durbar. Once you
find the matching location in both the interface, follow the steps below (see
figure):

• Click Add points tool in the Georeferencer.


• Click a location in the image which seems to be a match.
• Click button From map canvas.
• Click the matching location in the map canvas.
10. In the similar way, add two more matching points, known as ground control
points or GCPs. The GCPs should be as far to each other as possible. They
should not be in a straight line.
We need to choose the transformation type. As we already explained
earlier, we will use polynomial transformation of first order. What kind of
5.5 Deriving GIS data from text documents and images 109

transformation type to use depends upon the type of image. In some cases
we may need to choose other types of transformation. We will not go into
detail about each transformation type.
11. To set the transformation type, use Georeferencer menu Settings ⇒ Trans-
formation settings. Set the parameters as follows:
• Transformation type Polynomial1
• Resampling method Nearest neighbour
• Target SRS EPSG:4326
Other parameters can be left as default.
• Click OK
12. Click Start georeferencing tool to complete the task.


In the next exercise, we will describe how to georeference an image which has known
coordinate locations. In some reports and documents, we can find well produced maps
with labels, grids and coordinates written on the map. In such cases, it is possible to
georefernce the image using coordinates printed on the frame of map. Follow the steps
in the next exercise.
Exercise 5.4 Georeferencing from known locations
Open the image eqKTM.jpg in any image viewer. You will see that two types of
coordinates are printed beside the map frame as shown in following figure.

The two coordinate values printed on the image represent two different CRSs,
viz: UTM45N and geographic coordinates. However, horizontal and vertical grid
lines represent UTM projection. Therefore, it is now clear that the map has used
UTM45N for the grids. We will use UTM45N projection and the intersection of grids
for georeferencing. The process is explained in the following steps.
1. Open new QGIS window. We will not use any GIS data in the map canvas.
2. Start Georeferencer.
110 Chapter 5. Working with Vector Data

3. Open image eqKTM.jpg. This time select CRS as UTM45N.


4. Check the x, y coordinates of grid line intersections for at least three corners.
As you can see in the figure below, it is very easy to know the coordinates of
each grid intersection.

5. Click Add point tool and click on one of the grid intersections. Before
clicking the intersection point, it will be better to note down the coordinates.
6. In the next dialog, write the coordinates directly and click OK.
7. Repeat the above two steps for two more corners. You may use all the four
corners.
8. Set the transformation type and complete georeferencing as explained in the
previous exercise.


5.6 Analysis of Spatial Data


Spatial data refers to any kind of GIS data such as vector data, raster data, TIN (Triangu-
lated Irregular Network) data, Point cloud etc. We have till now understood where does
these data come from and how to display it in GIS. In this section we will explain about
the capability of GIS to analyze these spatial data based on their locations, geometries
and attributes.
Geometric relationships between different types of geometries (Table 5.1 provide
the basis for vector based spatial analysis. Spatial analysis is the core of GIS, and many
authors and experts of GIS have explained the meaning and process of spatial analysis in
5.6 Analysis of Spatial Data 111

different ways. Some of them are quoted below.


• Longley et al. [PR05] : Effective spatial analysis requires an intelligent user, not
just a powerful computer.
• Longley et al. [PR05] : Spatial analysis is a set of methods whose results change
when the locations of the objects being analyzed change.
• Goodchild [Goo92]: A GIS is a tool for supporting a wide range of techniques of
spatial analysis, including processes to create new classes of spatial objects, to
analyze the locations and attributes of objects, and to model using multiple classes
of objects and the relationships between them. It includes primitive geometric
operations such as calculating the centroids of polygons, or building buffers around
lines, as well as more complex operations such as determining the shortest path
through a network.
• Fischer et al. [Man11]: In order to undertake spatial data analysis, we require - as
a minimum - information for both location and attribute, regardless, of how the
attributes are measured.
• Tobler’s first law of geography [tobler_1970] states that “everything is related
to everything else, but near things are more related than distant things.". This
statement is very useful in spatial data analysis.
6. An Introduction to GNSS

With advent of smart phones, Global Navigation Satellite System(GNSS) has become
part of our daily life, rather unknowingly. Check whether you have used any of the
following features in your smart phone:
• When you open google website, it asks for permission to access your location.
• In the facebook, have you ever used check-in function?
• In the google maps have you ever searched for direction to a place? Have you ever
navigated using any of the mapping apps while walking or driving?
• Many places are still missing in Google maps. Have you ever contributed to add a
place you know to Google maps.
Smart phone can know your location using the wifi you are connected to or using
the location service provided by GNSS. The location provided by wifi is very coarse
and its accuracy may range in few hundred meters, while smart phone GNSS provide
10-20 meters of accuracy. This chapter describes the theory and practical applications of
GNSS.

6.1 What is GNSS?


You must know that there are several man made satellites flying above the earth in the
space. The purpose of the most satellites is to observe different phenomena on the earth.
Some of them are taking pictures of earth at a given interval, while some of them are
observing clouds and weather phenomena. Apart from these satellites, there are others
called navigation satellites which help us finding our location. It began with GPS (Global
positioning system) satellites launched by USA in 1979. According to Wikipedia, the
GPS project was launched by the U.S. Department of Defense in 1973 for use by the
114 Chapter 6. An Introduction to GNSS

United States military and became fully operational in 1995. It was allowed for civilian
use in the 1980s. Advances in technology and new demands on the existing system have
now led to efforts to modernize the GPS and implement the next generation of GPS
Block IIIA satellites and Next Generation Operational Control System (OCX).
Later, several other countries started developing and launching navigation satellites.
Navigation satellites launched by different countries are listed below:
1. GPS: It is owned by US government and operated by US Department of defense.
GPS is a constellation of 32 navigation satellites some of which may be retired or
replaced over time.
2. GLONASS: GLONASS is abbreviation of Global’naya Navigatsionnaya Sputniko-
vaya Sistema in Russian and is owned by Russian government. Similar to GPS,
GLONASS also has global coverage with 24 number of satellites.
3. Galileo: Galileo is operated by European Space Agency (ESA) and started to
provide service after 2016.
4. BeiDou-2: BeiDou or BDS is a navigation satellite system developed and operated
by the government of China.
5. NAVIC: NAVIC or NAVigation with Indian Constellation is an autonomous re-
gional satellite navigation system developed by Indian Space Research Organisa-
tion (ISRO) (Source: Wikipedia).
6. QZSS: Quasi-Zenith Satellite System (QZSS) has 4 navigation satellites which
cover Asia Pacific region. It is being developed by Japan Aerospace Exploration
Agency (JAXA).

6.2 Components of GNSS


GNSS system has three components. They are:
1. Space segment
2. Control segment
3. User segment

6.2.1 Space segment


Space segment consists of constellations of satellites revolving in different orbits around
the earth. They are moving around the earth at fixed altitude. GPS satellites managed
by USA has 30 actively broadcasting navigation satellites among which at least 6 six
satellites are always visible from any place on the earth. These satellites broadcast their
own position every second.

6.2.2 Control segment


Several ground based stations are established to continuously monitor the satellites’
health and accuracy. GPS has six ground based monitor stations located at Falcon
6.3 How GNSS works? 115

Air Force Base in Colorado, Cape Canaveral, Florida, Hawaii, Ascension Island in
the Atlantic Ocean, Diego Garcia Atoll in the Indian Ocean, and Kwajalein Island in
the South Pacific Ocean. Similarly, Galileo has 2 Ground Control Centres, located in
Oberpfaffenhofen and Fucino for Satellite and Mission Control. Ground stations are
used to monitor the position and health of the satellites and also to upload the ephimeris
and almanac data to the satellites at every fixed interval. Ground based stations can also
upload other data to the satellite.

6.2.3 User segment


The smart phone devices and other devices built specially to receive the navigation signals
are the user segment of the GNSS system. The receivers have built in antenna tuned
to frequency of different satellites. They also have high precision clock and receiver
processors. Receiver processors decode the data received from satellites which broadcast
data in predefined formats and calculate its own location after receiving signals from
more than 3 satellites (Refer section 6.3.2).
Apart from calculation of its own location, recent smart phones can provide back-
ground maps. Smart phone apps may also provide other location based features.

6.3 How GNSS works?


This section is intended to give brief information about the working of GNSS. Signal
transmission by satellites and its processing by the receivers are too complex concepts
to be covered in this book intended for GIS learners. Those interested can refer to the
websites given at the end of this section.
Basic concept behind navigation satellite is:
• Each satellite transmit different signals.
• A receiver (device) on or near earth surface receives the signal.
• The time difference between signal transmission and reception allows the receiver
to calculate its distance from a particular satellite.
• As the position of satellite is itself known, the receiver can calculate its own
position by using simple technique called trilateration which uses the distances
from at least three known satellites.

6.3.1 GNSS signals and their transmission


Navigation satellites are orbiting around the earth in a medium earth orbit (around 20000
km) and are continuously broadcasting signals in the range of 1 GHz to 2 GHz. All of the
satellites use mainly three frequency bands for sending the signals. These are known as
L1 (1575.42 MHz), L2 (1227.60 MHz)and L5 (1176.45 MHz) frequency bands. GNSS
satellites use transmission scheme called CDMA to broadcast signals which are received
by a receiver on or near the surface of the earth. Signals sent by the satellites are
modulated by a unique pseudorandom digital sequence, or code. Each satellite uses a
different pseudorandom code which is also known as signature. A receiver can correlate
116 Chapter 6. An Introduction to GNSS

or synchronize with a particular satellite using this signature. Satellites transmit signals
all these three frequencies (Note: Some more frequencies bands may be added in the
future). These signals contain various information related to the position of the satellite.
An L1 signal provide following information.
• GPS date and time.
• Satellite status and health. When the satellite has some problem, it will transmit
the out-of-service message.
• Satellite ephemeris data, which allows the receiver to calculate the satellite’s
position with extremely high accuracy. Receivers can determine the exact position
of satellite at the time of transmission of the signal.
• Almanac: It contains information about all the satellites in the same constellation.

6.3.2 Calculation of receiver’s location (Trilateration)


Let us suppose that our device receives a signal from one satellite which is located at
point P1(x1, y1, z1) somewhere in the space. The time taken from the satellite to the
receiver is calculated by time difference between receiver time and the satellite time. Let
us suppose that the time taken is t1. If speed of the signal (equal to the speed of light) is
c. Then our device will somewhere on the sphere whose center is located at the satellite
position and radius R1 is given by equation 6.1.

R1 = c × t1 (6.1)

Similarly, let us suppose that the next satellite gives the distance R2. Now, the
receiver should be located somewhere on the ring where the two spheres intersect (see
Fig. 6.1.

Figure 6.1: Intersection of two spheres

Let us suppose that the third satellite makes a sphere of radius R3. Now we have
an intersection of three spheres with radii R1, R2 and R3 as shown in Figure 6.2. Third
6.4 Errors in computation of location 117

sphere intersects with the ring at two points. One is shown in the figure while the other
point is just on the opposite side which is not visible. As the point should be on the earth,
one of the points on the ring can be excluded.

Figure 6.2: Intersection of three spheres

Above explanation illustrates that the location of receiver can be computed by


receiving the signals from three different satellites, provided that the distance is calculated
correctly. However, the assumption that the distance is computed correctly has some
problem. This is because the time recorded by the receiver is not correct to the level of
accuracy required. Even a micro second error in receiver clock will cause an error in the
range of 300m. As such, we need one more satellite to correct the error in the receiver
time. Owing to the error in the receiver clock, fourth sphere (from the fourth satellite)
will not intersect at any of the two points shown in Figure 6.2. The receiver time needs
to be corrected to make the last sphere intersect the other three at a precise point. In this
way, location of the receiver is computed using four satellites. This method is known as
trilateration.

6.4 Errors in computation of location


The reception of signal by the receiver and computation of location involves various
sources of error. As such, GNSS can not provide the location of the receiver as accurately
as it should where precise location is needed. However, it can provide fairly accurate
location for the purpose of navigation and finding the way. The sources of error are
explained in the following sections.

6.4.1 Atmospheric effects


Earth’s atmosphere, especially ionosphere, through which the signals pass, is not always
constant. As such the speed of signal is not always the same. Errors in the calculation
of distance to the satellites cause some error, especially to those satellite which are at
low altitude (vertical angle with earth’s horizon). Smart phones available in the market
receive and analyze L1 signals while survey grade receivers can receive signals from
118 Chapter 6. An Introduction to GNSS

different frequency bands (L1 and L2 frequency). This can minimize the error due to the
effect of the varying conditions of ionosphere.
Another way to reduce the effect of atmospheric error is to use high grade receiver
as a base station with precisely known position. The base station can provide correction
which is almost same for any particular geographic area. The other receivers (known as
rover) which receive only L1 frequency signal can use this correction value to correct its
location. Details of this error and methods of corrections can be found in various links.

6.4.2 Multipath error


Figure 6.3 illustrates the concept of multipath.

Figure 6.3: Multipath problem (image of satellite and receiver created by Iconicbestiary -
Freepik.com)

Specially big buildings cause obstruction to the path of the signals and some satellites
are not visible at some locations due to such obstructions. Futher, the signal is refracted
while passing different layers of atmosphere. As such, the satellite may receive multiple
signals: directly, reflected by obstructions and refracted by atmosphere. This causes
some error in the computed location. This type of error is known as multipath error.
6.5 Practical use of GNSS 119

6.4.3 Ephemeris and clock errors


Empheris data provided by satellite may be erroneous sometimes as it can be 2 hours old.
Similarly, even a nanosecond of error in satellite clock can result in few meters of error.
For detailed explanation on ephemeris and clock error access https://en.wikipedia.
org/wiki/Error_analysis_for_the_Global_Positioning_System.
Following websites provide in detail information about navigation satellites.
• https://www.gps.gov/
• https://www.novatel.com/an-introduction-to-gnss/chapter-1-gnss-overview

6.5 Practical use of GNSS


In this section we will discuss about the use of GNSS for the purpose of navigation and
collecting data for GIS. Recently, smart phones have revolutionized the use of different
technologies. GNSS technology does not require any connection to internet. Many
offline and online maps provide background for map based navigation. Programmers can
use the technology to develop customized applications which utilize GNSS. Many such
applications (or apps) are freely available on the major platforms such as android and
iOS. Some of the free apps are listed below. Few of them are explained in detail with
practical tutorials in the following section.
Note: You need to enable location from GPS for the following apps to work. Various
versions of android provide different interface to enable GNSS. For any version of
android, it requires few simple steps to enable GNSS. However, you can search the
method for your version using internet.

6.6 Mapping and navigation related apps


Some of the location based apps I have used are:
a. Google Maps
b. OSMTracker
c. GPS Test
d. OsmAnd
e. Map.me
f. Fake GPS

6.6.1 Google Maps


Google maps provide mapping and navigation functions to the users. Some snaps of the
user interface shown in following figures illustrate the use of Google Maps.
Figure 6.4 shows the home interface of Google Maps. When you tap the 3-line icon
at the left top, you will see different features provided by the app (Figure 6.5). Some of
the features require you to be logged in with gmail address.
120 Chapter 6. An Introduction to GNSS

Figure 6.4: Google Maps Figure 6.5: Google Maps Figure 6.6: Search the di-
home features rection

As shown in Figure 6.6, we can search for places and get the details of the searched
place. We can also ask for direction to the place as shown in Figure 6.6, by tapping on
Directions at the bottom left. Google Maps gives the shortest route and other one or two
alternative routes 6.7. Additionally, we can contribute to the Google Maps (see Fegure
6.8) in various ways such as:
• Contribute photos of visited places.
• Contribute opinions about visited places and give ratings to restaurants, temples
and many touristic and other places.
• Answer questions to the people who ask questions in the Google Maps.
• Add places that are missing in the Google Maps.
Google Maps is owned by Google, however, many people have contributed to it in
various ways.

6.6.2 OSMTracker
OSMTracker is freely available app which can record the track while moving. It also
allows one to record features on the way (such as: bridges, hospitals, restaurants etc) as
waypoints. The interface of OSMTracker is quite simple and easily comprehensible. Few
screen-shots below illustrates the use of OSMTracker. It will be explained in more detail
in section ??. Unlike Google Maps, it can be used offline. However, it is necessary to be
online to download background maps of the nearby locations. Google Maps uses its own
proprietary map as background, however, OSMTracker uses its own, freely available
Openstreetmap background.
Some features of OSMTracker
• Home screen provide various self-explanatory functions through the 3-dot icon at
6.6 Mapping and navigation related apps 121

Figure 6.7: Google Maps direction Figure 6.8: Google Maps contribu-
feature tion

Figure 6.9: OSMTracker: home Figure 6.10: OSMTracker:tracking


screen and way point screen

the upper right corner of the screen.


• Adding a new track can be done by tapping on the + sign located at the top right
122 Chapter 6. An Introduction to GNSS

Figure 6.11: OSMTracker: options Figure 6.12: OSMTracker: track


while tracking display

corner (Fig. 6.9).


• After starting the track, the screen shows Waiting for GPS fix and some buttons
below (Fig. 6.10). Which means that either the GPS satellites are not visible or
the device is not able to calculate its location from the available satellite positions.
Once the device gets GPS fix (able to calculate location), the buttons on the screen
will become enabled. As you can see, you can take photo, record audio or video or
record a waypoint which can later be exported to GIS.
• While tracking, it is possible to see one’s own location by tapping the 3-dot icon
on the top right corner and then tapping Display track (Fig. 6.11). The track will
be shown as in Fig. 6.12.

6.6.3 OsmAnd
OsmAnd is freely available app which provides offline navigation. It provides map
download facility for displaying offline maps. It is possible to add favorite places and
record the track. Following figures show the functionality of OsmAnd. For detail, it is
advisable to visit the website.

6.6.4 GPSTest
Unlike above three apps, GPSTest does not provide map background. However, it
provides very useful information regarding GNSS. Look at the following figures. Let us
look at some of the features:
6.6 Mapping and navigation related apps 123

Figure 6.13: OsmAnd: home Figure 6.14: OsmAnd: features (op-


screen tions)

Figure 6.15: GPSTest Figure 6.16: Satellites and Figure 6.17: Location of
home screen their SNR satellites in the sky

• As in every location based apps, it needs to get a GPS fix to start showing location.
Buttons at the bottom are toggle buttons and provide link to various informative
interfaces. Try to use these buttons multiple times to get used to the interfaces.
• Home screen provide the coordinates of the location (Fig. 6.15). The format of
124 Chapter 6. An Introduction to GNSS

Figure 6.18: Direction of Figure 6.19: Altitude and


Figure 6.20: Satellite time
movement speed

coordinates can be changed in the setting.


• You can show the number of visible satellites and their signal to noise ratio
(SNR)(Fig. 6.16).
• It is also possible to show the current location of satellites in the sky (Fig. 6.17).
• It also shows direction of movement (heading)(Fig. 6.18), altitude and speed (Fig.
6.19) and satellite based time (Fig. 6.20).

6.6.5 SW Maps
SW Maps is also a freely available GNSS app developed by Softwel Pvt. Ltd, Nepal. It
is heavily packed with features compatible with modern GIS. It is not possible to explain
all the features of this app owing to the space requirement. Some of the features of this
app is explained below. A tutorial using SW Maps in section ?? explains how we can
use the app.
Some features of SW Maps are listed below along with the screen-shots.
• Home screen of the app displays the map, logo and few menus.
• On the top left of the screen you can see the logo of app. Tapping the logo of the
app will show different options, each providing different functions. Some of those
functions will be addressed in the tutorial.
• SW Maps is based on the basic concept of GIS. It can have multiple projects which
are managed separately from each other. Each project may consist of multiple
vector layers. The project icon is the third from the top right. Tapping on project
icon will show project management screen.
6.7 Working with GNSS apps 125

Figure 6.21: SW Maps: home Figure 6.22: SW Maps: features


screen (options)

• Record icon right to the project icon is used to record a feature or just record a
track. The recorded tracks or features can be exported as shapefiles.
• Three dot icon on the top right has options to export the project or as multiple
shapefiles (Zipped).

6.7 Working with GNSS apps


6.7.1 OSMTracker
Complete the following exercise to experience the working of OSMTracker.
Exercise 6.1 Part-1: Tracking with OSMTracker
When you open OSMTracker it will show you the list of previously recorded
tracks. The user interface configuration depends upon OS and version. First of all you
need to click + sign at the upper right or in some older android versions menu to add
track or something similar. Once you add the track, the app will start tracking your
movement. After starting the app, follow the steps to record track and way points.
• You can add various waypoints like car, text note or audio and photograph by
tapping on the related icon.
126 Chapter 6. An Introduction to GNSS

• After completing your track you need to go back to previous screen and from
the menu you need to tap stop current track.

• You can continue the once stopped track (refer to the right figure above).
Long-press the track in the list and tap Resume tracking in the context menu.
Also check other options in the context menu which you can use as needed.
Alternatively, you can tap 3-dot icon at the top right corner and then tap
Continue track in the context menu.
• Any or all tracks can be exported. To export individual track, you need to long
press on the track and tap Export as GPX. The track can also be exported
6.7 Working with GNSS apps 127

to OpenStreetMap website. Exported track resides inside a folder named


OSMTracker which can be exported to your PC. The extension of the file is
gpx.
• Access osmtracker folder where gpx tracks are saved. Save it to your PC.
There are various ways to transfer your file to PC. Please search for any help in
the internet if you don’t know already.

Now let us display the track in QGIS. Following exercise explains how to do it.

Exercise 6.2 Part-2: Displaying the track in QGIS


After copying the gpx file and the photos to the PC (inside D:\GIS_exercise\
Exercise_06_GNSS) you need to add the gpx file to QGIS map. Following the steps
below you can display track in QGIS.
1. Open QGIS.
2. Follow any of the steps explained in section 1.4.1 and add gpx file as vector
layer.
3. The single gpx file consists of multiple layers, as listed below:
• route: Routes are linear feature layer. Routes are saved as Linestring.
• route_points: Vertices of each route and their geometry are recorded in
route_pooints layer.
• track_points: Point vector data which records all the point (at 1 second
interval). Speed and location (x, y, altitude) are recorded.
• waypoints: Point vector data which records the point of interest recorded
by the user while tracking. Waypoints can have photo, text, audio or many
other types of attribute.
• track: It is line vector data which represents linear feature from start to
the end of the track. Track is recorded as Multilinestring.
4. In the present exercise we will use only three layers (viz. track, track_points
and waypoints.). Select three layers as shown in the figure below and click OK.
128 Chapter 6. An Introduction to GNSS

5. We can add popular map backgrounds such as Google Maps, Bing Maps,
OpenStreetMap etc. Let us install plugin called QuickMapServices to display
background. You will need internet connection to install the plugin and also to
show the background layer.
6. Go to menu Plugins ⇒ Manage and Install Plugins.
7. A popup window will be displayed showing the list of installed and available
plugins in the left pane.
8. In the search box type quic. As you go on typing, the list will show only the
plugins matching the search keyword. From the list select QuickMapServices.
You will see the explanation of the plugin and the links. Click Install Plugin
button on the right bottom of the dialog.
9. Link to the plugin is available under Web menu. Select menu Web ⇒ QuickMapSer-
vices. Then test various map backgrounds.


The above exercise just shows how GNSS app, such as OSMTracker, can be used for
tracking and displaying vector data. It depends upon our need to decide how to use such
apps.

6.7.2 SW Maps
General concept of SW Maps
SW Maps is based on the concept of GIS and data layers. While working with SW Maps
we work in the following order.
1. Create project: We can create a new project from scratch or use a template. A
template consist of a set of feature classes without any data. When we use a
template we don’t need to do next two of the following steps.
2. Add layers of data: We can add layers of data as required. Each layer of data can
be point, polyline or polygon.
3. Add attributes: It is necessary to create attributes for each layer of data.
4. Record features: Once the layers and attributes are created we can record features
of different classes.
In the following exercise we will try to understand the concept and possible use of
SW Maps. While the concept of the SW Maps will not change, the interface may change
with version upgrade. You will need to modify the steps accordingly.
6.7 Working with GNSS apps 129

Exercise 6.3 Part-1: Create SW Maps project and record features


Following steps will show you how to create a new project with all the layers and
attributes.
Step-I. Create new project
1. When you start SW Maps app, it will show an option to start with previous
project or to open a project. Click open a project.

2. Open Project dialog will show the following options.


• the list of existing projects to select from
• start with previously active project
• create a new project.
130 Chapter 6. An Introduction to GNSS

3. Tap on New Project (see figure above, left). In the new dialog write the
name of the project as you like. In the present example, name of the project
is Campus Survey. Tap Create button (see figure above right).
Step-II. Add layers
In this step, we will add three layers with three different geometries (point, line,
polygon) to understand how each type of geometry are recorded.
1. To show the list of projects, tap on 3-dot icon on the top-right and select
Projects (See figure below, left). Note: You can add or delete projects using
this screen.

2. While your project Campus Survey is selected, tap on the layers icon
(third from top right), as shown in figure above right.
6.7 Working with GNSS apps 131

3. Tap on the + sign beside Layers and select GPS Recorded Feature. Note:
You can add existing vector data or raster data stored in the mobile from
this context menu.

4. Write the name of the layer as building, geometry as polygon. You can also
change the symbol.

Similarly, we can add other layers in the same way so that we have total
three layers: Building, Road and trees, with three different geometries.
132 Chapter 6. An Introduction to GNSS

Layer name Geometry


Building Polygon
Road Line
Tree Point
Step-III. Add attributes
1. In the list of layers, tap Building layer to select it. On the right of the layer
name, you will see two icons: one for setting the attributes and another to
delete the layer. Tap on the settings icon. (see left figure).

2. Tap + sign beside Layer Attributes (See above, right figure).


3. Write the name of the attribute as Name, keep the attribute type as TEXT
and tap on ADD.
6.7 Working with GNSS apps 133

4. Now we will create another field which can have only limited values. Again
tap + beside Layer Attributes. Write bldType in the Attribute Name and
attribute type as OPTIONS (above, right figure). A + sign appear beside
Options. Click on the + sign to add options.
5. Add following options:
• Academic
• Administrative
• Other

6. In the same way as explained above, add two more attributes: nfloors as
134 Chapter 6. An Introduction to GNSS

NUMERIC and photo as Photo. Now we have four attributes as shown in


above-right figure.
7. We can add several attributes to the Road and Tree layers as needed.
8. Finally, we have following layers and attributes.

Layer name Attribute Attribute Type


Buliding Name Text
bldType Options: academic,
administrative,
other
nfloors Numeric
photo Photo
Roads Name Text
Photo1 Photo
Photo2 Photo
Trees plantName Text
girth Numeric
photo Photo
Step-IV. Record features
1. Tap the record icon (marked as REC) to record feature and select Record
Feature in the context menu.
2. You will see an interface which allows you to type the attributes and record
the feature. The attributes with Photo as attribute type will have an icon of
camera.
3. Type or select (in case of options) each attribute values. ID and Remarks
are extra attributes added by default. Tap the REC icon at the bottom.
Note: The REC icon will be hidden when you are recording point feature.
You will have to record by tapping the bottom right icon to add location.
When you start recording line or polygon feature REC icon will change
into STOP.
6.7 Working with GNSS apps 135

4. Point features will be recorded once you tap on the icon. Therefore, you
need to be careful to fill all the attribute values before recording the feature.
5. In case of line or polygon, you need to tap STOP icon to end recording the
feature.
6. When you record a new line or polygon feature, check whether the radio but-
tons New or Existing is checked. If Existing is checked then the recording
will continue for existing feature.
7. After recording a feature, use back button to go to previous screen. It
will show you recorded features (see left figure below). When you click a
feature, it will show you details of that feature and options to delete or edit
(right figure, below).
136 Chapter 6. An Introduction to GNSS

8. After finish the recording of features, the project can be exported to the
storage. Alternatively, the project can be directly uploaded to a ftp. You can
create a ftp in your PC and upload it directly to PC using upload feature.
Long press logo icon and tap on the Export menu. Check the items you
want to export. For this exercise, export only 2D shapefiles including photos.
The exported file resides inside SW_Maps/Exports as zip file.
9. Transfer the zip file to your PC and display in QGIS as explained in the
next exercise.


There are several things we can do with SW Maps. SW Maps supports external GPS
device connected through bluetooth or OTG cable. You can also create a template from
your project which can be shared to others. Templates can be used where same features
are to be recorded by different users. By using template, creation of same feature classes
and attributes in multiple devices can be avoided. This can be used in a multi-user project
such as economic survey, building damage survey after an earthquake etc. It is suggested
to try all the capabilities of SW Maps and take full advantages of these functionalities.
Now let us try to display these shapefiles exported from SW Maps in QGIS. We
have already displayed GIS data in map canvas and also created layouts in the previous
chapters. In the present exercise we will show how we can create a report from the data
exported from SW Maps.
Exercise 6.4 Part-2: Display shapefiles and create report in QGIS
Following steps will show you how to create a new project with all the layers and
attributes.
1. Unzip the exported data inside, for example, D:\GIS_exercise\Exercise_
6.7 Working with GNSS apps 137

06_GNSS.
2. Add building and road layer to the map canvas. Symbolize them properly.
3. From menu click Project ⇒ New Report. New report window will open.
4. Click + sign below Report Organizer and select Static layout section.

5. A section will be added. Click Edit button beside Include section(checked).


An empty section will be added. Let us add the map and texts as shown.
138 Chapter 6. An Introduction to GNSS

6. Let us add title section (Static layout section) for Road feature class as shown
in the figure below.
7. Now let us add Field group section. By adding a Field group section, we
are adding multiple pages to the report. The number of pages is equal to the
number of features in the feature class. Follow the steps below to complete
adding road features. Refer the figure below.

a. In the layer select Road_2d.


b. Select field name which will be used as unique id to which the pages
will be sorted.
c. Check Include body and click Edit. A map canvas will be displayed.
To add map elements to the canvas, see the figure below. It has a title,
map, two images and and a table. Following steps explains how to add
each of these elements.
6.7 Working with GNSS apps 139

d. Add map to the canvas. In the Item properties select Controlled by


report.
e. Add title text at the top and change the text as <font size="40"
color="green 50"> Road: [% "name" %]</font>. The field in-
side square brackets are variables which will change with pages. Check
Render as html if you use html as above. You may edit the html code
as you like.
f. Add image from tools. Click ε sign beside the text for image source
and click Edit.
g. If you have unzipped the exported data from SW Maps is inside D:
\GIS_exercise\Exercise_06_GNSS and your unzipped folder name
is CampusSurvey, then write the following expression in the expression
box.

’D:/GIS_exercise/Exercise_06_GNSS/CampusSurvey’ + replace(
"photo1", ’\\’, ’/’).
140 Chapter 6. An Introduction to GNSS

Here we use slash as directory separator. The location of the image


saved in the field photo1 starts from
Photos. Therefore ’\’ needs to be replaced by ’/’. Using the above
expression will allow to display different image for each feature.
h. In the same way you can also use another image from attribute photo2
also.
i. Now let us add table on the right side which shows the values of each
attribute. Add a text element to the canvas and edit the text as below.
Check Render as html
Road Properties</br>
<tablestyle="width:100%"border="1">
<tr>
<td>name</th>
<td>[% name %]</th>
</tr>
<tr>
<td>Remarks</td>
<td>[% Remarks %]</td>
</tr>
<tr>
<td>Length</td>
<td>[% LENGTH %]m</td>
</tr>
</table>
j. In the similar way we can add Building section (Static layout section)
as shown below.

k. Then add the map canvas with map elements. We need to set the map
scale to fixed so that the surrounding area is clearly visible.
6.7 Working with GNSS apps 141


Bibliography

[Goo92] Michael F. Goodchild. “Geographical information science”. In: International


Journal of Geographical Information Systems 1.4 (1992), pages 31–45. URL:
https://www.geog.ucsb.edu/~good/papers/166.pdf (visited on
01/25/2019).
[Man11] Jinfeng Wang Manfred M. Fischer. Spatial data analysis: Models, methods
and techniques. Springer, 2011.
[Net18] Markes Neteler. Processing Landsat 8 data in GRASS GIS 7: Import and vi-
sualization. 2018. URL: https://courses.neteler.org/processing-
landsat8-data-in-grass-gis-7/ (visited on 12/26/2018).
[PR05] David J. Maguire Paul A. Longley Michael F. Goodchild and David W.
Rhind. Geographic Information Systems and Science. Wiley, 2005.
[Tes19] abc def Testing Testing. This bibliography testing. 2019.
[Wes+15] C.J. van Westen (end) et al. Multi-hazard risk assessment. 2015. URL:
ftp : / / ftp . itc . nl / pub / westen / Multi _ hazard _ risk _ course /
Exercises/Multi-hazard%20exercise%20book.pdf (visited on 12/26/2018).

You might also like