Training Manual: (OSGIS-2015)
Training Manual: (OSGIS-2015)
Edited by
Dr. Anurag Ohri
Organized By
Department of Civil Engineering,
Indian Institute of Technology
(Banaras Hindu University),
Varanasi-221005, Uttar Pradesh, India
Acknowledgement
The Conveners of the Workshop acknowledge the work of Mr Ujjawal Gandhi in the
field of Q GIS. Some portions of his tutorials exercises were used for the workshop.
We also extend our thanks to our esteemed Head of The Department Prof. Devendra
The Conveners are also thankful to the Student Mr. Satya Prakash Maurya who has
(Convener)
Excerise No 1
Basics of QGIS
Basics of QGIS
Advanced functions
QGIS provides integration with other open-source GIS packages,
including PostGIS, GRASS, and MapServer to give users extensive
functionality. Plugins, written in Python or C++, extend the capabilities of QGIS.
Plugins exist to geocode using the Google Geocoding API, to perform geoprocessing
similar to the standard tools found in ArcGIS, and to interface
with PostgreSQL/PostGIS, SpatiaLite and MySQL databases.
Development:
Gary Sherman began development of Quantum GIS in early 2002, and it became an
incubator project of the Open Source Geospatial Foundation in 2007. Version 1.0
was released in January 2009. Latest version in 2.10 released in June 2015.
Written in C++, QGIS makes extensive use of the Qt library. QGIS allows integration
of plugins developed using either C++ or Python. In addition to Qt, required
dependencies of QGIS include GEOS and SQLite. GDAL, GRASS GIS, PostGIS,
and PostgreSQL are also recommended, as they provide access to additional data
formats.
QGIS runs on multiple operating systems including Mac OS X, Linux, UNIX,
and Microsoft Windows. For Mac users, the advantage of QGIS over GRASS GIS is
that it does not require the X11 windowing system in order to run, and the interface is
much cleaner and faster. QGIS can also be used as a graphical user interface to
GRASS. QGIS is maintained by an active group of volunteer developers who
regularly release updates and bug fixes. As of 2012 developers have translated
QGIS into 48 languages and the application is used internationally in academic and
professional environments.
Licencing
As a free software application under the GNU GPL, QGIS can be freely modified to
perform different or more specialized tasks. There are also numerous plug-
ins available which expand the software's core functionality.
1
Graphical User Interface of QGIS
When QGIS starts, you are presented with the GUI as shown in the figure (the
numbers 1 through 5 in circles are discussed below).
The QGIS GUI is divided into five areas:
1. Menu Bar
2. Tool Bar
3. Map Legend
4. Map View
5. Status Bar
QGIS Configuration
QGIS is highly configurable through the Settings menu. Choose between Panels,
Toolbars, Project Properties, Options and Customization.
From View> Panels and View>Toolbar you can customize the QGIS window. You
can on or off any panel or toolbar
2
Project Properties
For Setting the Project properties goto Project→Project Properties, you can set
project-specific options. These include:
In the General Tab you can set the project title, selection and background
color, layer units, precision, and the option to save relative paths to layers can
be defined. If the CRS transformation is on, you can choose an ellipsoid for
distance calculations. You can define the canvas units (only used when CRS
transformation is disabled) and the precision of decimal places to use. You can
also define a project scale list, which overrides the global predefined scales.
The CRS Tab enables you to choose the Coordinate Reference System for this
project, and to enable on-the-fly re-projection of raster and vector layers when
displaying layers from a different CRS.
With the third Identify layers Tab, you set (or disable) which layers will respond
to the identify tool
The Default Styles Tab lets you control how new layers will be drawn when
they do not have an existing .qml style defined. You can also set the default
transparency level for new layers and whether symbols should have random
colours assigned to them. There is also an additional section where you can
define specific colors for the running project. You can find the added colors in
the drop down menu of the color dialog window present in each renderer.
The tab OWS Server allows you to define information about the QGIS Server
WMS and WFS capabilities, extent and CRS restrictions.
The Macros Tab is used to edit Python macros for projects. Currently, only
three macros are available: openProject(), saveProject() and closeProject().
The Relations Tab is used to define 1:n relations. The relations are defined in
the project properties dialog. Once relations exist for a layer, a new user
interface element in the form view (e.g. when identifying a feature and opening
its form) will list the related entities. This provides a powerful way to express
e.g. the inspection history on a length of pipeline or road segment.
3
Using Plugins
Plugins in QGIS add useful features to the software. Plugins are written by QGIS
developers and other independent users who want to extend the core functionality of
the software. These plugins are made available in QGIS for all the users.
Core Plugins
Core plugins are already part of the standard QGIS installation. To use these, you
just
need to enable them.
Click on Plugins ‣ Manage and Install Plugins.... to open the Plugin Manager
dialog.
Even if this is your first time using QGIS, you will see a lot of plugins listed under the
Installed tab. This is because they are Core Plugins and were installed during QGIS
installation.
Let's enable one of the plugins. Check on the checkbox next to Spatial Query
Plugin. This will enable the plugin and you will be able to use it.
4
One thing to note is that plugins have the ability to insert menu items at various
locations and create new panels and toolbars. Sometimes it is difficult to know how
to find the newly enabled tools. Once clue is to look in the plugin discription. Here the
description says Category: Vector. That indicates that the plugin would be found
under the Vector menu once enabled. Click Close.
Now that the Spatial Query Plugin is enabled, you can go to the Vector ‣ Spatial
Query to use the functionality added by the plugin.
Adding Data
To add the raster or vector data in QGIS goto Layer ‣Add Layer ‣ Add Vector
Layer or Layer ‣Add Layer ‣ Add Raster Layer.
QGIS support many Raster and Vector Format.
5
Exercise No 2
Georeferencing Topo Sheets and
Scanned Maps
Georeferencing Topo Sheets and Scanned Maps
Most GIS projects require georeferencing some raster data. Georeferencing is the
process of assigning real-world coordinates to each pixel of the raster. Many times
these coordinates are obtained by doing field surveys - collecting coordinates with a
GPS device for few easily identifiable features in the image or map. In some cases,
where you are looking to digitize scanned maps, you can obtain the coordinates from
the markings on the map image itself. Using these sample coordinates or GCPs
(Ground Control Points ), the image is warped and made to fit within the chosen
coordinate system. In this tutorial we will discuss the concepts, strategies and tools
within QGIS to achieve a high accuracy georeferencing.
Procedure
1.Georeferencing in QGIS is done via the ‘Georeferencer GDAL’ plugin. This is a
core plugin - meaning it is already part of your QGIS installation. You just need to
enable it.
Go to Plugins ‣ Manage and Install Plugins and enable the Georeferencer GDAL
plugin in the Installed tab. See Using Plugins for more details on how to work with
plugins.
3. The plugin window is divided into 2 sections. The top section where the raster will
be displayed and the bottom section where a table showing your GCPs will appear.
4. Now we will open our JPG image. Go to File ‣ Open Raster. Browse to the
saved image in folder QGIS_Tutorial>Georeferencing of the scanned map and
click Open.
6
5. Next, you are required to choose the raster’s coordinate reference system (CRS).
This is to specify the projection and datum of your control points. If you have
collected the ground control points using a GPS device, you would have the WGS84
CRS. If you are geo-referencing a scanned map like this, you can obtain the CRS
information from the map itself. Looking at our map image, the coordinates are in
Lat/Long. There is no datum information given, so we have to assume an
appropriate one. Since it is India and the map is quite old, we can bet the Everest
1830 datum would give us good results.
In filter write Everest and from the list choose Everest 1830> Click OK.
If you have coordinates from GPS in WGS84 coordinate system you can chose
EPSG: 4326 coordinate reference system.
7
6. Now we need to assign coordinates to some points on this map. If you look
closely, you will see coordinate grid with markings. Using this grid, you can
determine the X and Y coordinates of the points where the grids intersect.
Click on Edit>Add Point in
7. In the pop-up window, enter the coordinates. Remember that X=longitude and
Y=latitude. Click OK.
8
8. You will notice the GCP table now has a row with details of your first GCP.
9. Similarly, add at least 4 GCPs covering the entire image. The more points you
have, the more accurate your image is registered to the target coordinates.
10. Once you have enough points, go to Settings -> Transformation settings.
11. In the Transformation settings dialog, choose the Transformation type as Thin
Plate Spline. Name your output raster as 1870_southern_india_georef.tif. Choose
EPSG:4326 as the target SRS so the resulting image is in a widely compatible
datum. Make sure the Load in QGIS when done option is checked. Click OK.
9
12. Back in the Georeferencer window, go to File ‣ Start georeferencing. This will
start the process of warping the image using the GCPs and creating the target
raster.
13. Once the process finishes, you will see the georeferenced layer loaded in QGIS.
10
Exercise No. 3
Digitizing Map Data
QGIS Tutorials
Digitizing Map Data
Digitizing is one of the most common tasks that a GIS Specialist has to do. Often a
large amount of GIS time is spent in digitizing raster data to create vector layers that
you use in your analysis. QGIS has powerful on-screen digitizing and editing
capabilities that we will explore in this tutorial.
Procedure
1. Before we start, we need to set default Digitizing Options.
Go to Settings ‣ Options...
2. Select the Digitizing tab in the Options dialog. Set the Default snap mode to
To vertex and segment. This will allow you to snap to the nearest vertex or
line segment. I also prefer to set the Default snapping tolerance and Search
radius for vertex edits in pixels instead of map units. This will ensure that the
snapping distance remains constant regardless of zoom level. Depending on
your computer screen resolution, you may choose an appropriate value. Click
OK.
3. Now we are ready to start digitizing. We will first create a roads layer and
digitize the roads around the park area.
Select Layer ‣ Create Layer ‣ New shapefile Layer....
11
You may also choose to create a New Spatialite Layer.... Spatialite is an
open database format similar to ESRI's geodatabase format. Spatialite
database is contained within a single file on your hard drive and can contain
diferent types of spatial (point, line, polygon) as well as non-spatial layers.
This makes is much easier to move it around instead of a bunch of
shapefiles. In this tutorial, we are creating a couple of polygon layers and a
line layer. You can always load a shapefile layer and save it as spatialite or
any other format you want.
4. In the New shapfile Layer dialog, select Line as the Type. The base
topographic map is in the EPSG:4326 – WGS84 CRS, so we can select the
same CRS for our roads layer. When creating a GIS layer, you must decide
on the attributes that each feature will have.
Since this is a roads layer, we will have 3 basic attributes – Name, Class and
Length.
Enter Name as Text Data as the Name of the attribute in the New
attribute section and click Add to attribute list.
Similarly create a new attribute Class of the type Text data and Length of
the type Decimal Number data and Click OK.
After this save the shapefile with name Roads in the folder
QGIS_Tutorial>Digitization
5. Once the layer is loaded, click the Toggle Editing button to put the layer in
editing mode.
12
6. Click the Add feature button. Click on the map canvas to add a new vertex.
Add new vertices along the road feature. Once you have digitized a road
segment, right-click to end the feature.
7. After you right-click to end the feature, you will get a pop-up dialog called
Attributes. Here you can enter attributes of the newly created feature. Since the
pkuid is an auto-incrementing field, you will not be able to enter a value manually.
Leave it blank and enter the road name as it appears on the topo map. Optionally,
assign a Road Class value as well. Click OK. Leave the Length field Blank.
Note
You can use the scroll wheel of the mouse to zoom in or out while digitizing. You can
also hold the scroll button and move the mouse to pan around.
13
8. The default style of the new line layer is a thin line. Let's change it so we can
better see the digitized features on the canvas. Right click the Roads layer
and select Properties.
9. Select the Style tab in the Layer Properties dialog. Increase the width and
change the color. Click OK. You can also choose from different symbols.
10. Click on the Save Layer Edits button to save all the features in layer.
11. Right click the Roads layer and Open Attribute Table. Enter the ID and
select Length in the field and type $length in text box. Press Update All. Length of
all the lines will display in the length column.
14
12. You can also change the symbol of Roads as per different fields in column
Class. Right click the Roads layer and select Properties. The various styling
options are located in the Style tab of the Properties dialog.
13. Clicking on the drop-down button in the Style dialiog, you will see there are
five options available - Single Symbol, Categorized, Graduated, Rule Based
and Point displacement. We will explore the Categorized.in this tutorial.
14. Select Categorized. In Column field select Class and Click on Classify
Button. All the Classes with different symbols will display. You can change the
symbol of any Class by double clicking on symbol. Click Ok. Roads Features
symbols in Map will change.
15
15. In the Snapping Options dialog, check the Enable topological editing. This option
will ensure that the common boundaries are maintained correctly in polygon layers.
Also check the Enable snapping on intersection which allows you to snap on an
intersection of a background layer.
16. You can also save the Road.shp file into another format or in any other
projection system. In this we will save the road file into WGS 84 / Pseudo
Mercator EPSG: 3857 CRS which is a projected reference system. It will help
us to calculate the distances and areas in metric unit.
17. Now we will create a polygon layer representing the State boundaries.
Go to Layer ‣ New Layer ‣ New Shapefile Layer.... Select Polygon as the Type.
Create a new attribute called Name and Area. Click OK. Save the new layer as
States.
16
18. Polygon layers offer another very useful setting called Avoid intersections of new
polygons. Go to Settings ‣ Snapping Options.... Check the box in the Avoid Int
column in the row for the Parks layer. Click OK.
19. Now click on Add feature to add a polygon. With the Avoid intersections of new
polygons, you will be able quickly digitize a new polygon without worrying about
snapping exactly to the neighboring polygons.
Right-click to finish the polygon and enter the attributes. Magically the new polygon
is shrunk and snapped exactly to the boundary of the neighboring polygons! This is
very useful when digitizing complex boundaries where you need not be very precise
and still have topologically correct polygon. Click Toggle Editing to finish editing
the States layer.
20. Right click the Roads layer and Open Attribute Table. Enter the ID and select
Area in the field and type $area in text box. Press Update All. Area of all the
polygons will be displayed in the length column.
You can also Label the states by right click on properties. Goto Lable Tab. Then
Label this layer with> Name>Ok.
17
21. Attribute or Non Spatial Query:
Now we will do the attribute query in Vector Data. From attribute data we will try to
find out the roads whose Length is greater than 1300000 m and Class is SH.
18
22. Spatial Query:
Now we will do the Spatial Query in GIS. Spatial Query A statement or logical
expression that selects geographic features based on location or spatial relationship.
For example, a spatial query might find which lines are contained within a polygon or
set of polygons, find features within a specified distance of a feature, or find features
that are adjacent to each other.
19
23. Buffer:
A buffer in GIS is a zone around a map feature measured in units of distance or time. A buffer is
useful for proximity analysis.
We will generate the buffer around road features.
Goto Processing> Toolbox. In Processing Toolbox Search Buffer
Buffer Tools in all the software will be displayed in the screen. We will select the buffer tool of QGIS.
20
Exercise No 4
Making A Map: Print Composer
QGIS Tutorials
Making a Map
Often one needs to create a map that can be printed or published. QGIS has a
powerful tool called Print Composer that allows you to take your GIS layers and
package them to create maps.
Procedure:
1. To assemble our map. Go to Project ‣ New Print Composer.
2. You will be prompted to enter a title for the composer. You can write any
name or leave it empty and click Ok.
Note:
Leaving the composer name empty will assign a default name such as Composer1
3. In the Print Composer window, click on Zoom full to display the full extent of
the
Layout. Now we would have to bring the map view that we see in the QGIS
Canvas to the composer. Go to Layout ‣ Add Map.
4. Once the Add Map button is active, hold the left mouse button and drag a
rectangle where you want to insert the map. The map will display in the
rectangle. You can adjust the position by moving the box.
5. You can also adjust the scale, rotation and extent of map display by
changing the parameters in the Item Properties Panel in the Right. 13. Let us
adjust the zoom level for the given map. Click on the Item Properties tab and
enter 6000000 for Scale value.
6. Before we make any changes to the layers in the main QGIS window, check
the Lock layers for map item and Lock layer styles for map item boxes.
This will ensure that if we turn off some layers or change their styles, this view
will not change.
21
7. Now that we have the map inset ready, we will add a grid to the main map.
Select the Map 0 object from the Items panel. In the Item properties tab,
scroll down to the Grids section. Click the Add a new grid button.
22
8. By default, the grid lines use the same units and projections as the currently
selected map projections. However, We can select a different CRS for the grid
by Click on the change...button next to CRS.
9. Select the Interval values as 2 degrees in both X and Y direction. You can
adjust the Offset to change where the grid lines appear.
10. Scroll down to the Grid frame section and select a frame style that suits
your taste. Also check the Draw coordinates box. In Format select
Degree, minutes with suffix. Select Coordinate Precision to 0 in the
last.
11. Now we will add a North Arrow to the map. The Print Composer comes with
a nice collection of map-related images - including many types of North
Arrows. Click Layout ‣ Add Image.
12. Holding your left mouse button, draw a rectangle on the top-right corner of
the map canvas. On the right-hand panel, click on the Item Properties tab and
expand the Search directories section and select the North Arrow image of
your liking.
23
13. Now we will add a scale bar. Click on Layout ‣ Add Scalebar.
Click on the layout where you want the scalebar to appear. In the Item Properties
tab, make sure you have chosen the correct map element for which to display the
scalebar. Choose the Style that fit your requirement. In the Segments panel, you can
adjust the number of segments and their size.
24
14. You can also add the label or any text in the map. Click on Layout ‣ Add Label.
Try it yourself.
15. You can also add the Legend in the map. Click on Layout ‣ Add Legend.
16. Save the image in the format of your liking. Goto Composer‣ Export as image
or Composer‣ Export as pdf.
17. You can also save the Template for further use by going to Composer ‣ Save
as template
25
Exercise No 5
Raster Data and Analysis
QGIS Tutorial
Interpolating Point Data
Interpolation is a commonly used GIS technique to create continuous surface from
discrete points. A lot of real world phenomena are continuous - elevations, soils,
temperatures etc. If we wanted to model these surfaces for analysis, it is impossible
to take measurements throughout the surface. Hence, the field measurements are
taken at various points along the surface and the intermediate values are inferred by
a process called 'interpolation'. In QGIS, interpolation is achieved using the built-in
Interpolation plugin.
Procedure
1. Open QGIS. Go to Layer ‣ Add Layer ‣ Add Vector Layer..
2. In the Select layers to add... dialog, hold the Shift key and select
Arlington_Soundings.shp and Boundary.shp layers. Click OK. You
will see the 2 layers loaded in QGIS.
3. You will see the 2 layers loaded in QGIS. The Boundary layer represents
the boundary of the lake. Un-check the box next to it in the Table of Contents.
4. In the second layer Arlington_Soundings, though the data looks like
lines, it is a series of points that are very close.
5. Click the Zoom icon and select a small area on the screen. As you zoom
closer, you will see the points. Each point represents a reading taken by a
Depth Sounder at the location recorded by a DGPS equipment.
26
6. Open the Attribute Table. In this case, the ELV_GWT attribute
contains the depth of the lake at the location. As our task is to create a depth
profile and elevation contours, we will use these values as input for the
interpolation.
7. Make sure you have the Interpolation plugin enabled. See Using
Plugins for how to enable plugins. Once enabled, go to Raster ‣
Interpolation ‣ Interpolation.
8. In the Interpolation dialog, select Arlington_Soundings as the Vector layers in
the Input panel. Select ELV_GWT as the Interpolation attribute. Click Add.
9. Select the Interpolation method as TIN. Change the Cellsize X and Cellsize
Y values to 10. This value is the size of each pixel in the output grid. Since our
source data is in a projected CRS with Feet-US as units, based on our
27
selection, the grid size will be 10 feet. Click on the ... button next to Output file
and name the output file as elevation_GWT.tif. Click OK.
Note:
Interpolation results can vary significantly based on the method and parameters you
choose. QGIS interpolation supports Triagulated Irregular Network (TIN) and Inverse
Distance Weighting (IDW) methods for interpolation. TIN method is commonly used
for elevation data whereas IDW method is used for interpolating other types of data
such as mineral concentrations, populations etc. See the Spatial Analysis module of
the QGIS documentation for more details.
10. You will see the new later elevation_GWT loaded in QGIS. Right-click the
layer and select Zoom to layer.
11. Now you will see the full extent of the created surface. Interpolation does not
give accurate results outside the collection area. Let's clip the resulting
surface with the lake boundary. Go to Raster ‣ Extraction ‣ Clipper.
12. Name the Output file as elevation_GWT_clip.tif. Select the Cliiped mode as
Mask layer. Select Boundary as the Mask layer`. Click OK.
28
13. A new raster elevation_GWT_clip will be loaded in QGIS. We will now style
this layer to show the difference in elevations. Note the min and max elevation
values from the elevation_tin layer. Right-click the elevation_GWT_clip
layer and select Properties.
14. Go to the Style tab. Select Render type as Singleband pseudocolor. In the
Generate new color map panel, select Spectral color ramp. As we want to
create a depth-map as opposed to a height-map, check the Invert box. This
will assign blues to deep areas and reds to shallow areas. Click Classify.
29
15. Now you have a elevation relief map for the lake generated from the individual
depth readings. Let's generate contours now. Go to Raster ‣ Extraction ‣
Contours.
30
16. In the Contour dialog, enter contours as the Output file for contour lines. We
will generate contour lines at 5ft intervals, so enter 5.00 as the Interval
between contour lines. Check the Attribute name box. Click OK.
17. The contour lines will be loaded as contours layer once the processing is
finished. Right-click the layer and select Properties.
18. Go to the Labels tab. Check the Label this layer with box and select ELEV as
the field. Select Curved as the Placement type and click OK.
31
ELV_GROUND field in attribute Table.It will create the DEM (Digital Elevation
Model for the Ground Surface.
20. Now using the Raster Calculator tool, we will generate the raster file for depth.
We will subtract Layer Elevation_GWT_Clip.tif from Elevation_Ground_Clip.tif
file.
32
22. You can also do the raster spatial query like using Raster Caculator. We will
select the area where Depth of GWT is more than 12 m and Elevation of GWT
is more than 540 m.
33
34