Practical Introduction to QGIS
by Karsten Vennemann
Live Online Session each day
8:30 am – 4:30 pm PST (UTC-7 h )
1 hour lunch break + two 15 minute breaks
Day 1 Tuesday May 26th 2020
Day 2 Wednesday May 27th 2020
Day 3 Thursday May 28th 2020
Karsten Vennemann
QGIS
a very capable
and flexible
Desktop GIS
QGIS Workshop
Karsten Vennemann slide 2 of 13
Practical QGIS
Overview and Foundations of QGIS
The QGIS project and it’s
open source community
QGIS Workshop
slide 3 of 13
Practical QGIS
QGIS
QGIS - Desktop GIS
originally a GIS viewing environment QGIS for the Linux desktop but is
available for Solaris, Windows and Mac. Support for many data Formats
QGIS Workshop
slide 4 of 13
Practical QGIS
QGIS Facts
QGIS Workshop
slide 5 of 13
Practical QGIS
QGIS Highlights
„Intermediate“ Desktop GIS
all basic and intermediate GIS Functionality
support for many input formats
easily extensible and highly customizable
extended comprehensive Analytic capabilities
-> Processing Tools and modeler
automation and custom tool development via
Python scripting (Python bindings and pyQT integration)
Enables plug-in and user interface development
Very active User and Developer Community
rapid development, good community support
QGIS Workshop
slide 6 of 13
Practical QGIS
Why and What
What is Open Source (GIS)?
Open source means that the source code is available to the general
public for use, distribution, and modification from its original design
free of charge (among a long list of other requirements)
Open Source ≠ Open Standards
While most open source geospatial software is built on the
standards of the Open Geospatial Consortium (OGC) the
term “Open Source” it is not synonymous with Open
Standards because both proprietary and open source
software can be compliant with the OGC Open Standards.
http://www.opengeospatial.org
OSGeo is the organization that supports the development
of the highest quality open source geospatial software.
http://www.osgeo.org
QGIS Workshop
slide 7 of 13
Practical QGIS
The OS Culture
QGIS Workshop
slide 8 of 13
Practical QGIS
List of common FOSS software licenses
QGIS Workshop
slide 9 of 13
Practical QGIS
The „Tribes“ of FOSS4G
QGIS Workshop
slide 10 of 13
Practical QGIS
Some Foundations
Some of the Foundations of OS Software (Tools)
A few libraries that are the foundation of many
Open Source and commercial Geospatial Software Packages
GDAL (Raster) and OGR (Vector)
Geospatial Data Abstraction Library / Open GIS Simple Features Reference Implementation
Tools for reading, writing and processing of
raster and vector data sets -> formats
Important base for many Desktop GIS systems e.g. ArcGIS
OGR extends Mapserver formats
Oracle Spatial, ESRI Geodatabase (MDB), TIGER, MapInfo…
PROJ4 is a library for cartographic projection routines
stand alone projection utility “proj”
libraries for more than 2500 projections (e.g. EPSG list)
GeoTools is an open source Java GIS toolkit is a library for
cartographic projection routines
Similar usage as OGR and GDAL for Java based projects
Udig and GeoServer are based on GeoTools
QGIS Workshop
slide 11 of 13
Practical QGIS
Examples for practical use of GDAL/OGR
Raster / Image processing
run automatically from server side scripts
on server bash shell
image mosaicing, reprojection
custom scripts to process 3 band tiff images e.g.
vegetation vigor classification (Landsat 7+ 8)
assemble synthetic map images , grayscale for
background + color classified raster map
QGIS Workshop
slide 12 of 13
Practical QGIS
Practical Introduction
The QGIS software and spatial data
QGIS Desktop, additional software
Spatial Data
Data Sources Examples
volunteer efforts Open Street Map
Natural Earth Data
GADM data
data portals e.g. USGS Earth Explorer
QGIS Workshop
slide 13 of 13
Practical QGIS
Practical Introduction
The map document
open the Kenya Map
data/kenya/kenya_exercises.qgz
QGIS Workshop
slide 14 of 13
Practical QGIS
Using workshop maps and data
Tour of the Interface
including but not limited to
Adding data
Changing cartographic style/
representation
Displaying and arranging map layers
Attribute tables and indentifying attributes
Feature selections and filters
Data conversions / export
Using tool bars
QGIS Workshop
slide 15 of 13
Practical QGIS
Quick Tour
– Menu Bar provides access to all the main functions and plugins
– Toolbars provide one-click common functions, and task-specific
functions
– Layer List shows all data layers currently added to the project
– Status Bar provides some vital information about the
current project settings
– Python Console allows you to script Python code within QGIS
– Map View provides a dynamic visualization of the active data
layers that can be mapped
QGIS Workshop
slide 16 of 13
Practical QGIS
QGIS Basics and Interface Overview
Supported Data Formats
Exploring and using vector and raster data
Layer + map properties
Symbology / Cartography
QGIS Workshop
slide 17 of 13
Practical QGIS
Exercises - Basic Functionalities
Using workshop maps and data
QGIS Workshop
slide 18 of 13
Practical QGIS
Settings
Properties and Options - user interface (Task 1)
CRS (Task 1.1)
Menu -> Project -> Properties
QGIS Workshop
slide 19 of 13
Practical QGIS
Settings
Properties and Options - user interface (Task 1)
Review Options (Task 1.2)
Menu -> Settings -> Options
QGIS Workshop
slide 20 of 13
Practical QGIS
Settings - Options - user interface (Task 1)
Digitizing (Task 1.3)
enable and define
snapping behavior
QGIS Workshop
slide 21 of 13
Practical QGIS
Settings - Options - user interface (Task 1)
Canvas and Legend
(Task 1.4)
Set “Save path” to relative
change selection color and more
QGIS Workshop
slide 22 of 13
Practical QGIS
Exercises - Creating Maps
QGIS Workshop
slide 23 of 13
Practical QGIS
Creating Maps (Task 2)
create a new, empty project (Task 2.1)
add at least three vector layers (Task 2.2)
add two Seattle data set layers
open layer properties – style
change color and outline ( use “single symbol” for one layer and
“categorized” for the other layers as options )
note the advanced option of rule based classification
create a new “print composer” (layout) (Task 2.3)
QGIS Workshop
slide 24 of 13
Practical QGIS
Creating Maps (Task 2.4)
– add map item (Task 2.4.1)
– add legend item (Task 2.4.2)
QGIS Workshop
slide 25 of 13
Practical QGIS
Creating Maps (Task 2.4)
review options in print composer (Task 2.4.3)
add scale bar map item
add north arrow
save project (*.qgz) (Task 2.4.4)
save work as template (*.qgt)
(Task 2.4.5)
export map as image (Task 2.4.6)
close print composer and create
new project from your template
(Task 2.4.7)
QGIS Workshop
slide 26 of 13
Practical QGIS
Exercises
Working with tables and layers
QGIS Workshop
slide 27 of 13
Practical QGIS
Working with tables and layers (Task 3)
– open existing QGIS map document data/seattle/seattle_exercises.qgz
– add census tracts layer data/seattle/data/tracts_seattle.shp
and /seattle/census/sea_tracts.csv + review attribute data tables
– join information for people in poverty using fields geoid10 and Id2
– classify layer
„graduated“
– needs more work
because field is joined
as a „text“ field
– calculate virtual field
using decimal number
format
QGIS Workshop
slide 28 of 13
Practical QGIS
Working with tables and layers (Task 3)
QGIS Workshop
slide 29 of 13
Practical QGIS
Example Rule based Rendering with Pie Charts
Project \examples\maps\pie_charts_rulebased.qgz
QGIS Workshop
slide 30 of 13
Practical QGIS
Workshop Day 2
QGIS Workshop
slide 31 of 13
Practical QGIS
QGIS - Managing Raster Data
QGIS Workshop
slide 32 of 13
Practical QGIS
QGIS - Managing Raster Data
Virtual Raster
You can deal with multiple files like they are one file by creating a virtual raster.
This can be done by selecting the Raster > Miscellaneous > Build Virtual Raster
(Catalog) menu option. This creates a mosaic of the images (like a seamless layer
in MapInfo or a mosaic raster layer in ArcGIS).
QGIS Workshop
slide 33 of 13
Practical QGIS
QGIS - Managing Raster Data
Build Overviews (Pyramids in ArcGIS)
You can also create pyramids on multiple datasets in one go by using the
Raster > Miscellaneous > Build Overviews menu option.
This allows for a batch mode. It has more advanced options, and its best to read
this webpage to understand them
QGIS Workshop
slide 34 of 13
Practical QGIS
Exercises – Raster data
QGIS Workshop
slide 35 of 13
Practical QGIS
Managing Raster Data (Task 4)
open existing QGIS map document
data/kenya/seattle_exercises.qgz
load 4 Kenya DEM raster layers
*.tif files in /data/kenya/dem/
(Task 4.1)
create a vrt file from the
four dem layers (Task 4.2)
create hill shade,
slope,
and aspect layers
from DEM (Task 4.3)
QGIS Workshop
slide 36 of 13
Practical QGIS
Managing Raster Data (Task 5)
in existing QGIS map document
/data/kenya/kenya_exercises.qgz
open layer properties for
“Precipitation in mm”
/data/kenya/newrain.tif
review the existing
Rendering type and
the other types
available
review the existing
classification
change to show
only 5 classes
QGIS Workshop
slide 37 of 13
Practical QGIS
Spatial Analysis and Tools
Geospatial Processing in QGIS - Exercises
Using the geo-processing tools and
graphical model builder
Exercises
e.g. counting trees
in Seattle neighborhoods
QGIS Workshop
slide 38 of 13
Practical QGIS
QGIS – Processing Toolbox
Enabling R Package (Statistical Software)
QGIS Workshop
slide 39 of 13
Practical QGIS
Exercises - Analysis
QGIS Workshop
slide 40 of 13
Practical QGIS
Analysis (Task 6)
– open existing QGIS map document
data/seattle/seattle_exercises.qgs
– make a map of the neighborhoods colored
based on the number of trees in each
neighborhood (Task 6.1)
– label the neighborhoods including
the total count of trees (Task 6.2)
Hint: You’ll need a spatial join.
QGIS Workshop
slide 41 of 13
Practical QGIS
Analysis (Task 6)
Creating a selection
QGIS Workshop
slide 42 of 13
Practical QGIS
Analysis (Task 6)
Calculating numbers
“Count points
in polygon”
Or
„Join attributes
by location“
QGIS Workshop
slide 43 of 13
Practical QGIS
Analysis (Task 7)
– Make a map of the number of trees per capita
(Task 7.1)
Hint: You’ll need population data from tracts and a
field calculation.
QGIS Workshop
slide 44 of 13
Practical QGIS
Analysis (Task 7)
– Use the data provided and
geoprocessing tools to locate areas
where the city should plant more trees (Task 7.2)
– The manner in which you define/determine
this is up to you.
Hints:
– You could set a threshold on the number of
trees per area (or capita)
– You could use “Rule based” classification
QGIS Workshop
slide 45 of 13
Practical QGIS
Spatial Analysis and Tools
QGIS Plug-ins
Default Plug-ins: e.g. DB Manager
Resource Sharing
OpenLayers (Google, Bing, Openstreetmap base maps)
Georeferencer
Semi Automatic Classification Plug-in (Remote sensing)
Others
QGIS Workshop
slide 46 of 13
Practical QGIS
Resources
Documents
PDF under workshop/docs/books folder (version 3.4)
QGIS User Guide
QGIS Training Manual
A Gentle Introduction to GIS
PyQGIS Developer Cookbook
QGIS Map Design - (can be bought from the Locate Press web site )
Learning QGIS (third edition) – (can be bought at the Packt web site )
The PyQGIS Programmer's Guide. Extending QGIS 3 with Python 3
Other resources for learning QGIS
OSGEO Foundation
Conferences
Email lists
User groups
OSGEO Planet blog aggregator
Geo For All is dedicated to promote the adoption of free and open source software for geospatial
technology through education, research and public awareness.
GeoAcademy Class videos on YouTube
Class materials download
QGIS Workshop
slide 47 of 13
Practical QGIS
Workshop Day 3
Advanced functionalities with QGIS
QGIS Workshop
slide 48 of 13
Practical QGIS
Introduction
Layer Properties
Lots of settings
interesting options including
Flexible UI Attribute
tables
Attribute Forms
e.g. using defined
value drop down
menus
Custom Actions
Python code
QGIS Workshop
slide 49 of 13
Practical QGIS
Using Layer ‘Actions’
to automate things
QGIS Workshop
slide 50 of 13
Practical QGIS
Layer Actions
Open Wikipedia web page on click on a country on the map
QGIS Workshop
slide 51 of 13
Practical QGIS
Layer Actions
Example: \examples\maps\open_wiki_page.qgz
Open Wikipedia web page on click on a country on the map
QGIS Workshop
slide 52 of 13
Practical QGIS
Editing Layers and
custom interfaces
QGIS Workshop
slide 53 of 13
Practical QGIS
Editing Layers
Using defined value drop down menus
Example: \examples\maps\editing.qgz
QGIS Workshop
slide 54 of 13
Practical QGIS
Interfaces with QT Designer
Can be installed via OSGeo4w, includes custom QGIS widgets,
can be saved as *.ui file, a tutorial is here
QGIS Workshop
slide 55 of 13
Practical QGIS
Adding a custom *.ui file
Layer Properties -> Attribute Form
QGIS Workshop
slide 56 of 13
Practical QGIS
QGIS and Spatial Databases
Extending GIS Capabilities
file based vs. server based
QGIS Workshop
slide 57 of 13
Practical QGIS
Spatialite
Spatialite – file based Spatial Database
Spatialite GUI
https://www.gaia-
gis.it/fossil/libspatialite/index
QGIS Workshop
slide 58 of 13
Practical QGIS
PostGIS
PostGIS – Spatial Database
PostGIS is an extension for PostgreSQL
adds support for geographic objects to PostgreSQL
enables PostgreSQL server to be used as a backend spatial
database for GIS
Spatial operations and analysis simply mean running a
(spatial) SQL query in the database
Similar functions to ESRI Arc SDE but also much more ….
QGIS Workshop
slide 59 of 13
Practical QGIS
PostGIS
PostGIS Functions
Spatial SQL
QGIS Workshop
slide 60 of 13
Practical QGIS
PostGIS
pgAdmin – GUI base
Database administration tool
QGIS Workshop
slide 61 of 13
Practical QGIS
Example for practical use of the PostGIS Database
Unified data storage and retrieval
GIS functionalities
Find nearest spatial features
Nearest road (reverse geocoding)
Nearest conspecific plant species (Whippet model)
Buffer, locate within another feature, and calculate
distances (modeling)
Model calculations of attributes
(leading to prioritization scores)
Extension of Web GIS capabilities
Data queries for dynamic data display
QGIS Workshop
slide 62 of 13
Practical QGIS
Working with PostGIS data in QGIS
Create Database connections in Browser, right click …
POSTGIS Connection
Host: terra8.terragis.net
Database: osgis
User: wsosgisuser
Pw: wspractialqgis42
QGIS Workshop
slide 63 of 13
Practical QGIS
DB Manager working with PostGIS data in QGIS
Import / export data
Dynamic query layers
QGIS Workshop
slide 64 of 13
Practical QGIS
Examples - Dynamic Layers with Spatialite or PostGIS
Project \examples\maps\dynamic_data.qgz
1. get weather data from the web and display closest weather station + measure distance
QGIS Workshop
slide 65 of 13
Practical QGIS
Examples - Dynamic Layers with Spatialite or PostGIS
Project \examples\maps\dynamic_data.qgz
2. Automatically buffer point to create flooded area, select and display affected roads
QGIS Workshop
slide 66 of 13
Practical QGIS
Using Python and
R (Statistics program) scripts
QGIS Workshop
slide 67 of 13
Practical QGIS
QGIS + R Package (Statistical Software)
Official R webpage and download links
R Studio
Articles R + Geospatial use
Geospatial data in R and Beyond R, an Integrated Statistical
Programming
Environment and GIS Spatial data and R
R scripts and GIS integration
R-scripts in Processing "Spatial data processing framework for
QGIS" Plug-in (formerly Sextante plug-in)
Needs to be enabled in Processing menu / providers:
After R is enabled (and installed on your operating system) you can
run the scripts from the Processing Toolbox – see next page
Note that R Packages need to installed via an R interface
QGIS will find all R packages only if present in local user folder
QGIS Workshop
slide 68 of 13
Practical QGIS
QGIS
Python Interface
Three main options
Python console
Processing tools
Plugins
Good overview about Python in QGIS
Understanding Python in QGIS - Victor Olaya
https://github.com/volaya/qgis-python-course
Tools such as
WinPython ( IDE + QT Designer)
QT Designer
Plugin-Builder 3 Plugin
Creates a QGIS plug-in template
for use as a starting point in plug-in development
QGIS Workshop
slide 69 of 13
Practical QGIS
Example Python Console
Example to label countries with custom function
Project \examples\maps\countries_label_hemisphere.qgz
Code \examples\scripts\active_layer_hemisphere.py
QGIS Workshop
slide 70 of 13
Practical QGIS
Example Python and R in Processing
Enabling Providers
QGIS Workshop
slide 71 of 13
Practical QGIS
Example R Processing
Example create BOX plot from Field Data Point Layer
QGIS Workshop
slide 72 of 13
Practical QGIS
Additional Notes
QGIS Workshop
slide 73 of 13
Practical QGIS
Example 3D View
Project \examples\maps\wa_olypmic_pen_elev_3d.qgz
QGIS Workshop
slide 74 of 13
Practical QGIS
Example Map in RStudio (no QGIS needed)
\examples\scripts\more\tz_cloropleth_carto2.r
QGIS Workshop
slide 75 of 13
Practical QGIS
QGIS – Metadata
viewing, editing, exporting, etc
What are our options for documenting database or shape files
with metadata?
Starting with QGIS 3.6 one can enter information about the layer via
the layer properties window and save metadata as a file (QMD file) or
"Save as Default“ right click layer, choose Metadata tab
QGIS Workshop
slide 76 of 13
Practical QGIS
QGIS - Joining Tables
tutorial
http://www.qgistutorials.com/en/docs/performing_table_joins.html
QGIS - Building a Map Atlas
tutorial
https://docs.qgis.org/3.10/en/docs/training_manual/forestry/forest_maps.html
QGIS – Topology
step-by-step tutorial:
https://docs.qgis.org/3.10/en/docs/training_manual/create_vector_data/topo_ed
iting.html
QGIS - Grass integration - two options:
Using the Processing plug-in (Spatial data processing framework for QGIS)
is easy to use
Using the Grass plug-in - has more functions but is more difficult to use
installation via OSGeo4W “advanced” mode
QGIS Workshop
slide 77 of 13
Practical QGIS