Mastering Geospatial Development with QGIS 3.x - Shammunul Islam - E-Book

Mastering Geospatial Development with QGIS 3.x E-Book

Shammunul Islam

0,0
33,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Go beyond the basics and unleash the full power of QGIS 3.4 and 3.6 with practical, step-by-step examples


Key Features:


One-stop solution to all of your GIS needs Master QGIS by learning about database integration, and geoprocessing toolsLearn about the new and updated Processing toolbox and perform spatial analysis


Book Description:


QGIS is an open source solution to GIS and widely used by GIS professionals all over the world. It is the leading alternative to proprietary GIS software. Although QGIS is described as intuitive, it is also, by default, complex. Knowing which tools to use and how to apply them is essential to producing valuable deliverables on time.


Starting with a refresher on the QGIS basics and getting you acquainted with the latest QGIS 3.6 updates, this book will take you all the way through to teaching you how to create a spatial database and a GeoPackage. Next, you will learn how to style raster and vector data by choosing and managing different colors. The book will then focus on processing raster and vector data. You will be then taught advanced applications, such as creating and editing vector data. Along with that, you will also learn about the newly updated Processing Toolbox, which will help you develop the advanced data visualizations. The book will then explain to you the graphic modeler, how to create QGIS plugins with PyQGIS, and how to integrate Python analysis scripts with QGIS.


By the end of the book, you will understand how to work with all aspects of QGIS and will be ready to use it for any type of GIS work.


What you will learn:


Create and manage a spatial databaseGet to know advanced techniques to style GIS data Prepare both vector and raster data for processing Add heat maps, live layer effects, and labels to your maps Master LAStools and GRASS integration with the Processing Toolbox Edit and repair topological data errors Automate workflows with batch processing and the QGIS Graphical Modeler Integrate Python scripting into your data processing workflows Develop your own QGIS plugins


Who this book is for:


If you are a GIS professional, a consultant, a student, or perhaps a fast learner who wants to go beyond the basics of QGIS, then this book is for you. It will prepare you to realize the full potential of QGIS.


Shammunul Islam is a consulting spatial data scientist at the Institute of Remote Sensing, Jahangirnagar University, and a senior consultant at ERI, Bangladesh. He develops applications for automating geospatial and statistical analysis in different domains such as in the fields of the environment, climate, and socio-economy. He also consults as a survey statistician and provides corporate training on data science to businesses. Shammunul holds an MA in Climate and Society from Columbia University, an MA in development studies, and a BSc in statistics. Simon Miles is a GIS/web developer working for the Royal Borough of Windsor and Maidenhead, and has been working in the GIS industry since 2003. Both in the office and at home, he works using open source technologies. His main kit or stack includes QGIS, PostGIS, Python, GDAL, Leaflet, JavaScript, and PHP. His main focus presently is on digital delivery/transformation, chiefly through the consolidation of data, applications, and legacy systems, and replacing these with APIs and web applications. In 2013, Simon helped to establish the UK QGIS user group, which holds regional meetings two or three times a year. Kurt Menke, GISP, a former Albuquerque, New Mexico, USA-based archaeologist, has an MS in geography from the University of New Mexico in 2000. He has founded Bird's Eye View to apply his expertise with GIS technology toward ecological conservation. His other focus areas are public health and education. He is an avid GIS proponent since he began writing MapServer applications in 2002. He has authored Discover QGIS. In 2015, Kurt was voted in as an OSGeo Charter Member. He is a FOSS4G educator and a co-author of the GeoAcademy. In 2015, he was awarded the Global Educator of the Year Team Award by GeoForAll as part of the GeoAcademy team. He authors an award-winning blog on FOSS4G technologies and their use in community health mapping. Richard Smith Jr., GISP, is an assistant professor of geographic information science in the School of Engineering and Computing Sciences at Texas A&M University – Corpus Christi. He has a Ph.D. in geography from the University of Georgia and holds an MSc in computer science and a BSc in geographic information science from Texas A&M University-Corpus Christi. Richard actively researches in cartography, systems integration, and the use of geospatial technology for disaster response. He is an advocate for FOSS4G and building a FOSS4G curriculum. He is also one of the co-authors of the FOSS4G Academy. Luigi Pirelli is a QGIS core developer and software analyst with a degree in computer science from Bari University. He worked for 15 years in the Satellite Ground Segment and Direct Ingestion for the European Space Agency. He is also involved in GFOSS world, contributing in QGIS, GRASS, & MapServer core, and developing and maintaining many QGIS plugins. Luigi is the founder of the OSGEO Italian local GFOSS chapter. He has taught PyQGIS, delivering training from basic to advanced levels, and supporting companies to develop their own specific QGIS plugins. He founded a local hackerspace group. Bricolabs.cc. He likes training groups on conflict resolution. Other than this book, he has also contributed to the Lonely Planet guide Cycling Italy. John Van Hoesen, GISP, is an associate professor of geology and environmental studies at Green Mountain College in rural west-central Vermont, USA. He earned an MS and a Ph.D. in geology from the University of Nevada, Las Vegas, in 2000 and 2003. He is a certified GISP with a broad background in the geosciences and has used some flavor of GIS to evaluate and explore geological processes and environmental issues since 1997. John has used and taught graduate, undergraduate, and continuing education courses using some variants of FOSS GIS since 2003.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 416

Veröffentlichungsjahr: 2019

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Mastering Geospatial Development with QGIS 3.xThird Edition

 

An in-depth guide to becoming proficient in spatial data analysis using QGIS 3.4 and 3.6 with Python

 

 

 

 

 

 

Shammunul Islam
Simon Miles
Kurt Menke, GISP
Richard Smith Jr., GISP
Luigi Pirelli
John Van Hoesen, GISP

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Mastering Geospatial Development with QGIS 3.x Third Edition

Copyright © 2019 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

 

Commissioning Editor:Richa TripathiAcquisition Editor:Yogesh DeokarContent Development Editor:Unnati GuhaTechnical Editor: Dinesh ChaudharyCopy Editor: Safis EditingProject Coordinator:Manthan PatelProofreader: Safis EditingIndexer:Priyanka DhadkeGraphics:Jisha ChirayilProduction Coordinator:Aparna Bhagat

 

First published: March 2015 Second edition: September 2016 Third edition: March 2019

Production reference: 1270319

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78899-989-2

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the authors

Shammunul Islam is a consulting spatial data scientist at the Institute of Remote Sensing, Jahangirnagar University, and a senior consultant at ERI, Bangladesh. He develops applications for automating geospatial and statistical analysis in different domains such as in the fields of the environment, climate, and socio-economy. He also consults as a survey statistician and provides corporate training on data science to businesses. Shammunul holds an MA in Climate and Society from Columbia University, an MA in development studies, and a BSc in statistics.

 

 

Simon Miles is a GIS/web developer working for the Royal Borough of Windsor and Maidenhead, and has been working in the GIS industry since 2003. Both in the office and at home, he works using open source technologies. His main kit or stack includes QGIS, PostGIS, Python, GDAL, Leaflet, JavaScript, and PHP. His main focus presently is on digital delivery/transformation, chiefly through the consolidation of data, applications, and legacy systems, and replacing these with APIs and web applications. In 2013, Simon helped to establish the UK QGIS user group, which holds regional meetings two or three times a year.

 

 

Kurt Menke, GISP, a former Albuquerque, New Mexico, USA-based archaeologist, has an MS in geography from the University of New Mexico in 2000. He has founded Bird's Eye View to apply his expertise with GIS technology toward ecological conservation. His other focus areas are public health and education. He is an avid GIS proponent since he began writing MapServer applications in 2002. He has authored Discover QGIS. In 2015, Kurt was voted in as an OSGeo Charter Member. He is a FOSS4G educator and a co-author of the GeoAcademy. In 2015, he was awarded the Global Educator of the Year Team Award by GeoForAll as part of the GeoAcademy team. He authors an award-winning blog on FOSS4G technologies and their use in community health mapping.

Richard Smith Jr., GISP, is an assistant professor of geographic information science in the School of Engineering and Computing Sciences at Texas A&M University – Corpus Christi. He has a Ph.D. in geography from the University of Georgia and holds an MSc in computer science and a BSc in geographic information science from Texas A&M University-Corpus Christi. Richard actively researches in cartography, systems integration, and the use of geospatial technology for disaster response. He is an advocate for FOSS4G and building a FOSS4G curriculum. He is also one of the co-authors of the FOSS4G Academy.

 

 

Luigi Pirelli is a QGIS core developer and software analyst with a degree in computer science from Bari University. He worked for 15 years in the Satellite Ground Segment and Direct Ingestion for the European Space Agency. He is also involved in GFOSS world, contributing in QGIS, GRASS, & MapServer core, and developing and maintaining many QGIS plugins. Luigi is the founder of the OSGEO Italian local GFOSS chapter. He has taught PyQGIS, delivering training from basic to advanced levels, and supporting companies to develop their own specific QGIS plugins. He founded a local hackerspace group. Bricolabs.cc. He likes training groups on conflict resolution. Other than this book, he has also contributed to the Lonely Planet guide Cycling Italy.

 

 

John Van Hoesen, GISP, is an associate professor of geology and environmental studies at Green Mountain College in rural west-central Vermont, USA. He earned an MS and a Ph.D. in geology from the University of Nevada, Las Vegas, in 2000 and 2003. He is a certified GISP with a broad background in the geosciences and has used some flavor of GIS to evaluate and explore geological processes and environmental issues since 1997. John has used and taught graduate, undergraduate, and continuing education courses using some variants of FOSS GIS since 2003.

 

 

About the reviewers

 

Giuseppe De Marco, a Ferentino based agricultural engineer, has a Bachelor's in agriculture from the University of Pisa. He started programming at an early age. He developed deep interests in geography and GIS during his bachelor’s. He then got introduced to GRASS and QGIS while working with Eris commercial products. Since QGIS 1.7.4, he has been developing plugins for it, In 2008, he partnered with his 2 colleagues and started Pienocampo (open field), a website that hosts plugins made by him which are also hosted on OGIS official repository. He likes studying geography, surveying, tree risk assessment, landscaping, bioengineering, and farm consulting. He also likes imparting knowledge on how to use QGIs and other open source software.

 

 

Chima Obi is the lead geospatial analyst at AGERPoint Inc. He has over 4 years of experience as a geospatial analyst. His specialty includes processing LIDAR data and feature extraction from raster/imagery data utilizing Python and R programing, as well as exploring other open source geospatial tools. He got his Bachelors in soil science from the Federal University of Technology, Owerri, Nigeria in 2010. He moved to the United States where he obtained his master’s degree in environmental science and got a certification in Geospatial information systems in 2016. Prior to working at AGERPoint, he worked as a geospatial analyst at West Virginia District of Highways in 2015 and 2016.

I would like to express my gratitude to my friends and family, and most importantly to my wife, for their wonderful encouragement and support. Also, my biggest thanks go to Packt Publishing for choosing me to be a part of this awesome book review.

 

 

 

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Mastering Geospatial Development with QGIS 3.x Third Edition

About Packt

Why subscribe?

Packt.com

Contributors

About the authors

About the reviewers

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Section 1: Introduction

A Refreshing Look at QGIS

Release schedules

QGIS downloading and installation

Installing QGIS on Windows

Installing QGIS on macOS

Installing QGIS on Ubuntu Linux

Installing QGIS only

Installing QGIS and other FOSSGIS packages

QGIS on Android

Installing QGIS on a Chromebook

QGIS in a browser

What's new?

A tour of QGIS

Familiarizing yourself with QGIS Desktop

Loading data into QGIS Desktop

Loading vector data

Loading raster data

Loading databases

Loading web services

Working with CRS

Working with tables

Creating table joins

Editing data

Snapping

Styling vector data

Styling raster data

Blending modes

Composing maps

Adding functionality with plugins

Custom QGIS variables

Summary

Section 2: Getting Started

Styling Raster and Vector Data

Choosing and managing colors

Knowing color picker components

Changeable panels in the color picker

Color ramp

Color wheel

Color swatches

Color sampler

Color picker components in the Layers panel

Managing color ramps

Managing the QGIS color ramp collection

Renaming a color ramp

Removing a color ramp

Exporting a color ramp

Importing a color ramp

Adding a color ramp

Adding a gradient color ramp

Adding a random color ramp

Adding a ColorBrewer color ramp

Adding a cpt-city color ramp

Editing a color ramp

Styling singleband rasters

Paletted raster band rendering 

Singleband gray raster band rendering

Singleband pseudocolor raster band rendering

Singleband pseudocolor interpolations

Styling multiband rasters

Raster color rendering

Raster resampling

Styling vectors

Single-symbol vector styling

Categorized vector styling

Graduated vector styling

Rule-based vector styling

Point-displacement vector styling

Point cluster vector styling

Inverted polygons vector styling

Heatmap vector styling

2.5 D vector styling

Vector layer rendering

Layer transparency

Layer blending mode

Feature blending mode

Control feature rendering order

Using diagrams to display thematic data

Parameters that are common to all diagram types

Diagram size parameters

Diagram placement parameters

Adding attributes to diagrams

Creating a pie chart diagram

Creating a text diagram

Creating a histogram chart diagram

Saving, loading, and setting default styles

Saving a style

Loading a style

Setting and restoring a default style

Adding and renaming styles in the current QGIS project

Summary

Creating Spatial Databases

Fundamental database concepts

Describing database tables

Knowing about table relationships

Reviewing the basics of the structured query language

Creating a spatial database

Connecting to a GeoPackage

Importing data into a GeoPackage

Importing a vector file

Importing a layer from map canvas

Working with tables

Creating a new table within an existing GeoPackage

Renaming a table

Editing an existing table field/column

Deleting a GeoPackage table 

Exporting tables out of a GeoPackage

Creating queries and views

Using select statements

Creating a spatial view

Dropping a spatial view

Summary

Preparing Vector Data for Processing

Merging vectors

Converting vector geometries

Creating polygon centroids

Converting lines into polygons

Converting polygons into lines

Creating polygons surrounding individual points

Voronoi polygons

Delaunay triangulation

Extracting nodes (vertices)

Simplifying and densifying features

Converting between multipart and singleparts features

Adding geometry columns to an attribute table

Using basic vector Geoprocessing Tools

Spatial overlay tools

Using the Clip and Difference tools

Using the Intersect and Symmetrical Difference tools

Overlaying polygon layers with Union

Creating buffers

Generating convex hulls

Dissolving features

Defining coordinate reference systems

Understanding the PROJ.4 definition format

Defining a new custom coordinate reference system

Setting Definitions

Viewing a statistical summary of vector layers

Advanced field calculations

Exploring the field calculator interface

Writing advanced field calculations

Calculating and formatting current date

Calculating with geometry

Operators

Conditions

Conditionals

Summary

Preparing Raster Data for Processing

Merging rasters

About converting raster files

Translating

Exporting to a raster

Exporting a raster to a GeoPackage

Clipping a raster

Converting rasters into vectors

Converting from vector to raster (rasterize)

Reclassifying rasters 

Summary

Section 3: Diving Deeper

Advanced Data Creation and Editing

What's new in editing?

CAD-style digitizing tools

Adding a circle

Adding a circle from two points

Adding a circle from three points

Adding a rectangle

Adding a rectangle from Extent

Adding a rectangle from its center point

Adding a rectangle from three points

Adding a regular polygon

Adding a regular polygon from the center and from a corner

Adding a regular polygon from two points

Vertex tool

Creating points from coordinate data

Mapping well-known text representations of geometry

Geocoding address-based data

How address Geocoding works

The first example – Geocoding using web services

The second example – Geocoding using local street network data

Georeferencing imagery

Understanding ground control points

Using the Georeferencer GDAL plugin

The first example – Georeferencing using a second dataset

Getting started

Entering ground control points

Transformation settings

Completing the operation

The second example – Georeferencing using a point file

Checking the topology of vector data

Installing the topology checker

Topological rules

Rules for point features

Rules for line features

Rules for polygon features

Using the topology checker

Repairing topological errors via topological editing

Example 1 – Resolving duplicate geometries

Example 2 – Repairing overlaps

Setting the editing parameters

Repairing an overlap between polygons

Example 3 – Repairing a gap between polygons

Summary

Advanced Data Visualization

Using live layer effects

Creating beautiful effects with inverted polygon shapeburst fills

Creating coastal vignettes

Studying area mask

Using the 2.5D renderer

Creating 3D views 

Creating an Atlas

Basic Atlas configuration

Dynamic titles

Dynamic legends

Highlighting the coverage feature

The power of geometry generators

Working with the Data Plotly plugin

Summary

Section 4: Becoming a Master

The Processing Toolbox

Introducing the Processing Toolbox

What's new in the Processing Toolbox?

Configuring the Processing Toolbox

Viewing the Processing Toolbox

Running algorithms in the Processing Toolbox

Using the Processing Toolbox

Performing raster analysis with GRASS

Calculating shaded relief

Calculating least-cost path

Calculating slope using r.slope

Reclassifying the new slope raster and the land use raster

Combining reclassified slope and land use layers

Calculating the cumulative cost raster using r.cost

Calculating the cost path using LCP

Evaluating a viewshed

Clipping elevation to the boundary of the park using GDAL

Calculating viewsheds for towers using r.viewshed

Combining viewsheds using r.mapcalc.simple

Performing analysis using SAGA

Evaluating a habitat

Calculating elevation ranges using the SAGA Raster calculator

Clipping land use to the park boundary using Clip grid with polygon

Querying land use for only surface water using the SAGA Raster calculator

Finding proximity to surface water using GDAL Proximity

Querying the proximity for 1,000 meters of water using the GDAL Raster calculator

Reclassifying land use using the Reclassify grid values tool

Combining raster layers using the SAGA Raster calculator

Exploring hydrologic analysis with SAGA

Removing pits from the DEM

Deriving streams

Selecting the streams

Delineating the streams

Calculating the upstream area above Fort Klamath

Summary

Automating Workflows with the Graphical Modeler

Introducing the graphical modeler

Opening the graphical modeler

Configuring the modeler and naming a model

Working with your model

Adding data inputs to your model

Adding algorithms to your model

Running a model

Editing a model

Documenting a model

Saving, loading, and exporting models

Executing model algorithms iteratively

Nesting models

Using batch processing with models

Converting a model into a Python script

Summary

Creating QGIS Plugins with PyQGIS and Problem Solving

Webography - where to get API information and PyQGIS help

PyQGIS cookbook

API documentation

The QGIS community, mailing lists, and IRC channel

Mailing lists

IRC channel

The Stack Exchange community

Sharing your knowledge and reporting issues

The Python Console

Getting sample data

My first PyQGIS code snippet

My second PyQGIS code snippet - looping the layer features

Exploring iface and QGis

Exploring a QGIS API in the Python Console

Creating a plugin structure with Plugin Builder

Installing Plugin Builder

Locating plugins

Creating my first Python plugin - plugin_first

Setting mandatory plugin parameters

Setting optional plugin parameters

Generating the plugin code

Compiling the icon resource

Plugin file structure - where and what to customize

Exploring main plugin files

Plugin Builder-generated files

A simple plugin example

Adding basic logic to TestPlugin

Modifying the layout with Qt Designer

Adding two pull-down menus

Modifying GUI logic

Modifying plugin logic

Classifying layers

Populating the combo box

Understanding self

Showing and running the dialog

Some improvements

More detail of the code

Setting up a debugging environment

What is a debugger?

Installing Aptana

Setting up PYTHONPATH

Starting the Pydevd server

Connecting QGIS to the Pydevd server

Connecting using the Remote Debug QGIS plugin

Debugging session example

Creating a PyDev project for TestPlugin

Adding breakpoints

Debugging in action

Summary

PyQGIS Scripting

Where to learn Python basics

Tabs or spaces – make your choice!

How to load layers

How to manage rasters

Exploring QgsRasterLayer

Visualizing the layer

Managing vector files

Managing database vectors

Vector structure

The basic vector methods

Describing the vector structure

Describing the header

Describing the rows

Exploring QgsGeometry

Iterating over features

Describing iterators

Editing features

Updating the canvas and symbology

Editing through QgsVectorDataProvider

Changing a feature's geometry

Changing a feature's attributes

Deleting a feature

Adding a feature

Editing using QgsVectorLayer

Discovering the QgsVectorLayerEditBuffer class

Changing a feature's geometry

Changing a feature's attributes

Adding and removing a feature

Running Processing Toolbox algorithms

Listing all available algorithms

Getting algorithm information

Running algorithms from the console

Running your own processing script

Creating a test Processing Toolbox script

Running the script

Interacting with the map canvas

Getting the map canvas

Explaining Map Tools

Setting the current Map Tool

Getting point-click values

Getting the current Map Tool

Creating a new Map Tool

Creating a map canvas event handler

Creating a Map Tool event handler

Setting up the new Map Tool

Using point-click values

Exploring the QgsRubberBand class

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Welcome to Mastering Geospatial Development with QGIS 3.x, Third Edition. With the release of QGIS 3, QGIS has broken new ground in enhancing the user experience with new features – this book aims to introduce you to these features. Throughout 11 chapters, you will explore QGIS 3.4 and QGIS 3.6, with particular emphasis on data processing, creation, editing, and visualization, with data stored in databases such as Spatialite, GeoPackages, and PostGIS.

Who this book is for

If you are a GIS professional, a consultant, a student, or perhaps a fast learner who wants to go beyond the basics of QGIS, then this book is for you. It will prepare you to realize the full potential of QGIS.

What this book covers

Chapter 1, A Refreshing Look at QGIS, covers those features that were new to QGIS in version 3.0 and those that have now been introduced at version 3.4 and version 3.6.

Chapter 2, Styling Raster and Vector Data, explores styling raster and vector data for display. First, color selection and color ramp management are covered. Next, single-band and multi-band raster data is styled using custom color ramps and blending modes. Then, complex vector styles and vector layer rendering are covered.

Chapter 3, Creating Spatial Databases, introduces the user to the use of databases that are locally stored in file directories, such as Spatialite and GeoPackages. Users will learn how to create their own local database, as well as how to add data into it from scratch, or import existing data. 

Chapter 4, Preparing Vector Data for Processing, introduces you to the tools and functions that come as standard within QGIS for working with vector datasets. 

Chapter 5, Preparing Raster Data for Processing, introduces you to the tools and functions that come as standard within QGIS for working with rasters.

Chapter 6, Advanced Data Creation and Editing, provides advanced ways to create vector data. As there is a great deal of data in tabular format, this chapter will cover mapping coordinates and addresses from tables. Next, georeferencing of imagery into a target coordinate reference system will be covered. The final portion of the chapter will cover testing topological relationships in vector data and correcting any errors via topological editing.

Chapter 7, Advanced Data Visualization, covers the powerful data visualization tools found only in QGIS.

Chapter 8, The Processing Toolbox, begins with an explanation and exploration of the QGIS Processing Toolbox. Various algorithms and tools, available in the toolbox, will be used to complete common spatial analyses and geoprocessing tasks for both raster and vector formats. To illustrate how these processing tools might be applied to real-world questions, two hypothetical scenarios are illustrated, relying heavily on the GRASS and SAGA tools.

Chapter 9, Automating Workflows with the Graphical Modeler, covers the purpose and use of the graphical modeler to automate analysis workflows. In this chapter, you will develop an automated tool/model that can be added to the Processing Toolbox.

Chapter 10, Creating QGIS Plugins with PyQGIS and Problem Solving, covers the foundational information required to create a Python plugin for QGIS. Information about the API and PyQGIS help will be covered first, followed by an introduction to the iface and QGis classes. Next, the steps required to create and structure a plugin will be covered. The chapter will be wrapped up after providing you with information on creating graphical user interfaces and setting up debugging environments to debug code easily.

Chapter 11, PyQGIS Scripting, covers topics on integrating Python analysis scripts with QGIS outside of the Processing Toolbox. Layer loading and management are first covered, followed by an exploration of the vector data structure. Next, the programmatic launching of other tools and external programs are covered. Lastly, the QGIS map canvas is covered with respect to how a script can interact with the map canvas and layers within.

To get the most out of this book

You should have good knowledge of Python and QGIS. 

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-Geospatial-Development-with-QGIS-3.x. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Also, you can download data for exercises at https://qgis.org/downloads/data/.

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781788999892_ColorImages.pdf.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Section 1: Introduction

QGIS 3 is the first major new release of QGIS in several years. This section reviews what major changes will be treated as assumed knowledge for the remainder of the book.

This section contains the following chapter: 

Chapter 1

 

A Refreshing Look at QGIS

A Refreshing Look at QGIS

In this chapter, we will review the basic functionality of QGIS and explore some of the new features of versions starting from 3.4. If you need a refresher on QGIS or a quickstart guide to QGIS, you should read this chapter. The topics we will cover in this chapter are as follows:

Downloading QGIS and its installation

The QGIS graphical user interface

Loading data

Working with

coordinate reference systems

(

CRS

)

Working with tables

Editing data

Styling data

Composing a map

Finding and installing plugins

QGIS is a volunteer-led development project licensed under the GNU General Public License, and was started by Gary Sherman in 2002. The project was incubated with the Open Source Geospatial Foundation (OSGeo) in 2007, with QGIS 1.0 being released in 2009. The continued development of QGIS is supported by an active and vibrant community from around the world. Many people assume that they can only help with the development of QGIS if they can perform computer programming, but this is false! QGIS has many community members that write documentation, test the program for bugs, translate documents, answer forum questions, and provide financial support. QGIS user groups exist as well, aiming to bring people together to share experiences of QGIS. It is easy to get involved, and the authors encourage you to consider contributing. Learn about how to get involved at http://qgis.org/en/site/getinvolved/.

Release schedules

Currently, a new version of QGIS is released around every four months. The version released each spring is designated as a long-term release (LTR). This means it will be supported for one calendar year. Each quarter, a new stable version is released and bug fixes applied to the LTR. The LTR is recommended for production environments since it has a slower release cycle. At the time of writing, QGIS 3.4.5 is the current LTR, with version 3.6 available for download.

It is possible to have multiple versions of QGIS installed on a single machine.

QGIS downloading and installation

QGIS can be installed on Windows, macOS, Unix, Linux, and Android operating systems, making it a very flexible software package. Both the binary installers and source code can be downloaded from download.qgis.org. In this section, we will briefly cover how to install QGIS on Windows, macOS, and Ubuntu Linux. For the most up-to-date installation instructions, refer to the QGIS website.

Installing QGIS on Windows

On the QGIS website, download the correct version of QGIS for your Windows machine. Downloadable executable files come in 32-bit and 64-bit flavors. We recommend downloading the latest release as advertised on the QGIS website download page. 

For Windows, there are two installation options, which are as follows:

QGIS Standalone Installer

: The standalone installer installs the binary version of QGIS and the

Geographic Resource Analysis Support System

(

GRASS

) using a standard Windows installation tool. You should choose this option if you want an easy installation experience of QGIS. This is also the ideal installation method for organizations or businesses wishing to deploy QGIS to multiple users.

OSGeo4W Network Installer

: This provides you with the opportunity to download either the binary or source code version of QGIS, as well as experimental releases of QGIS. Additionally, the OSGeo4W installer allows you to install other open source tools and their dependencies.

If you are unsure on how to install QGIS, the QGIS website contains details on how to do this.

Installing QGIS on macOS

The QGIS website provides download mac installer packages for macOS, that contain readme files for the installation of QGIS. Documentation and support for QGIS on macOS has greatly improved, and while it is beyond the scope of this chapter to detail the install process and document any possible issues that might incur during installation, the GIS Stack Exchange (https://gis.stackexchange.com/) is a great refresh resource.

Installing QGIS on Ubuntu Linux

There are two options when installing QGIS on Ubuntu: installing QGIS only, or installing QGIS as well as other Free and Open Source Software for Geographical Information Systems (FOSSGIS) packages. Either of these methods requires the use of the command line, sudo rights, and the apt-get package manager.

Installing QGIS only

Depending on whether you want to install a stable release or an experimental release, you will need to add the appropriate repository to the /etc/apt/sources.list file.

With sudo access, edit /etc/apt/sources.list and add the following line to install the current stable release or the current release source code, respectively:

deb http://qgis.org/debian trusty main deb-src http://qgis.org.debian trusty main

Depending on the release version of Ubuntu you are using, you will need to specify the release name as trusty, saucy, or precise. For the latest list of QGIS releases for Ubuntu versions, visit download.qgis.org.

With the appropriate repository added, you can proceed with the QGIS installation by running the following commands:

sudo apt-get update sudo apt-get install qgis python-qgis

To install the GRASS plugin (recommended), install the optional package by running this command:

sudo apt-get install qgis-plugin-grass

Installing QGIS and other FOSSGIS packages

The ubuntugis project installs QGIS and other FOSSGIS packages, such as GRASS on Ubuntu. To install the ubuntugis package, remove the http://qgis.org/debian lines from the /etc/apt/sources.list file and run the following commands:

sudo apt-get install python-software-properties sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get update sudo apt-get install qgis python-qgis qgis-plugin-grass

QGIS on Android

At the time of writing, there is really only one Android QGIS application available on Google Play, called QField, developed by OPENGIS.ch from Switzerland. Users of QGIS can save their projects to their Android device and then reopen them in QField. The application comes with Geolocation capabilities, data editing, and photos captured, to name just a few of its features.

Further information on QField can be found at http://www.qfield.org/docs/index.html.

While QField may currently (at the time of writing) be one of the main Android QGIS applications available, the underlying architecture of QGIS, namely QT5 and Python3, mean that development and deployment of user-created Android applications is not far away, thanks to crowdfunding opportunities organized by such companies as Lutra Consultancy and North Road.

Installing QGIS on a Chromebook

It is possible to install the Ubuntu Linux operating system on a Chromebook via Crouton (https://chromebook.guide/crouton/). This essentially creates a dual boot environment allowing you to switch between the Chrome OS and Ubuntu very quickly with some keyboard strokes. Once Crouton is set up, QGIS can be installed via the preceding Ubuntu QGIS install processes. 

While Chromebooks are relatively cheap, they are weak, if not lacking, in hardware such as graphic cards. Therefore, while it is possible to install QGIS on a Chromebook, we would suggest that doing so is for hobbyists looking to explore/test the capabilities of this union and that it would not be suitable for production environments.

QGIS in a browser

Using the RollApp website (https://www.rollapp.com), you can access QGIS, plus a range of other open source software in your web browser. This means that for Chromebook and iPad (for example), users can access QGIS without physically installing any software or making system configuration changes. RollApp is designed around using cloud base storage, such as Google Drive, Dropbox, and Box. This makes sharing data and projects very easy.

What's new?

With the release of version 3 of QGIS comes a host of new features and tools—far too many to document here, but if you are interested, take a look at http://changelog.qgis.org/en/qgis/version/3.4-LTR. For the new addition to QGIS 3.6, have a look at this http://changelog.qgis.org/en/qgis/version/3.6.0/. The biggest shift in QGIS 3.x is the migration from Python 2 to 3, which has extended the functionality to run scripts, processes, and tasks. Further to this, the underlying application used to build the QGIS interface, called Qt as of version 3.x, runs off Qt5.

To highlight perhaps just a few of these new features, note the following:

Data Source Manager

: The

Data Source Manager

(accessed via  or

Ctrl

+

L

) i

s perhaps the most notable visual change of 3.4, as it is presented as the default tool to accessing data to load onto the

Map

 

Canvas:

Opening layers over HTTP(s), FTP, and cloud storage

: Sharing and accessing data through QGIS has gotten a whole lot easier with 3.x series. No longer does data need to be stored on a local or networked drive; instead, data can be accessed through HTTP(s), FTP, or via cloud storage providers such as Google Drive. There are now really no limits as to how QGIS can fetch, receive, and display GIS data.

Filters

:

 

In previous versions of QGIS, it has been difficult to know which layers have had filters applied to them.

 

In version 3.4, this has been remedied with a filter icon being placed on all layers that have filters applied. A user can click on the filter icon to gain quick access to the query builder.

Import geotagged photos

: Photos that have been geotagged (which is commonly set as a default function on most modern smartphones) can now be uploaded onto the Map Canvas and represented as a point value. The metadata associated with the photo can also be accessed.

Save project to Postgres

:

 

This is a truly remarkable step forward for QGIS. The ability to save a QGIS project to a database table adds a new level of security, but also accessibility, to QGIS. It is now possible to simply send someone postgres connection details and, once added into QGIS, this will allow the user to access permission-based projects and layers (tables) stored on the database. This means that no data, no projects, and indeed, no physical files need to be handled by a user to access QGIS data.

Locator Search Bar

:

 

Located in the bottom left, below the panels, is the

Locator Search

bar that is a quick finder for processes, tools, and can even be configured to search layers.

3D and mesh

: There has been significant investment in 3D in version 3. 3D views of data can now be seen in its own

Map View

, which runs in parallel to the main Map Canvas. Mesh data can now be loaded into QGIS and viewed in 3D.

Print Layouts

:

 

Other than a change of name from Print Compose to Print Layouts, QGIS 3.4 brings some new elements to the Print window, such as the ability to add 3D views. There have been changes to the

Item Properties

to increase overall functionality.

Identity tool for mesh layers:

In QGIS 3.6, we can use

Identify 

tool with mesh layer. We can see the value of both scalar and vector component 

To have a look at the features of QGIS 3.6, please visit this link: https://qgis.org/en/site/forusers/visualchangelog36/index.html. For a look at the new editions in QGIS 3.4, please refer to this link: https://qgis.org/en/site/forusers/visualchangelog34/. If you visit any of these pages, you will find link for new features for all the versions of QGIS.

A tour of QGIS

QGIS is composed of two programs: QGIS Desktop and QGIS Browser. Desktop is used for managing, displaying, analyzing, and styling data. Browser is used for managing and previewing data. This section will give you a brief tour of the graphical user interface components of both QGIS Desktop and QGIS Browser.

Familiarizing yourself with QGIS Desktop

The QGIS interface is divided into four interface types: Menu Bar, Toolbars, Panel, and Map Canvas. The following screenshot shows QGIS Desktop with all four interface types displayed:

The Map Canvas shows the styled data added to the QGIS project. The Menu Bar, displayed across the top, provides access to most of the QGIS functions. The Toolbars provide quick access to QGIS core functionality. The Toolbars can be arranged to either float independently or dock at the top, bottom, left, or right sides of the application—equally, toolbar ideas can be removed from the screen via Settings | Interface Customization.

If you are going to use the Interface Customization tool to remove icons, make a backup file first of the current UI (User Interface) of QGIS. When the Enable Customization button is checked, click on the Save button and save the .ini file to a safe place. Then, make your changes but remove icons and so on. If you ever what QGIS looking as it did, prior to the removal of icons that you made, use the Loadfrom file option to reinstall the original backup .ini file that you created. Note that if you change the UI via the Interface Customization tool, then you'll need to close QGSIS before you see the changes take effect.

The panels, such as Browser and Layers, provide a variety of functionality and can be arranged to either float independently or dock above, below, right, or left of the map display or side by side as tabs.

QGIS Desktop offers a number of customization options. You can toggle the visibility of toolbars by navigating to View | Toolbars, or by right-clicking on the Menu Bar and then enabling the Toolbars button, which will open a context menu allowing you to toggle the toolbar and panel visibility. You can assign shortcut keys to operations by navigating to Settings | Configure shortcuts. You can also change application options, such as interface language and rendering options, by navigating to Settings | Options.

Loading data into QGIS Desktop

One strength of QGIS is its ability to load a large number of data types. In this section, we will cover loading various types of data into QGIS Desktop.

In general, data can be loaded in a number of ways. The main way, which will be covered in detail in this section, is to use the Data Source Manager.

Alternatively, using the Browser panel, navigate to the data you wish to load, and then either drag the data onto the Map Canvas or right-mouse click on it and choose Add Selected Layer(s) to canvas.

Under Settings | Add Layer from the main Menu.

Also, you can drag and drop data/files from your native operating systems file manager. Even ZIP files that contain .shp files can be added to the Map Canvas in this way.

Loading vector data

To load vector files using the Data Source Manager, click on the Open Data Source Manager icon , or press Ctrl + L. From the list of layer types on the left, choose Vector. You now have the option to load a Vector file for a number of Source type options:

The source type contains four options: File, Directory, Database, and Protocol: HTTP(S), cloud, etc. When you choose a source type, the source interface will change to display the appropriate options. Let's take a moment to discuss what types of data these four source types can load:

There is a big push to move users away from using ESRI shapefiles, replacing it instead with GeoPackages (more will be discussed about these later). QGIS, in the first instance, will prompt you to save to this format over .shp.

File

: This can load flat files that are stored on disk. The commonly used flat file types are as follows:

GeoPackage (

.gpkg

)

ESRI shapefile (

.shp

)

GeoJSON (

.geojson

)

Geography Markup Language (

.gml

)

AutoCAD DXF (

.dxf

)

Comma-separated values (

.csv

)

GPS eXchange Format (

.gpx

)

Keyhole Markup Language (

.kml

)

SQLite/SpatiaLite (

.sqlite

/

.db

)

Directory

: This can load data stored on disk that is encased in a directory. The commonly used directory types are as follows:

U.S. Census TIGER/Line

Arc/Info Binary Coverage

Database

: This can load databases that are stored on disk or those available through service connections. The commonly used database types are as follows:

ODBC

ESRI Personal GeoDatabase

MSSQL

MySQL

PostgreSQL

Protocol

: This can load protocols that are available at a specific URL. In QGIS 3.4, these protocols have been extended to include calls to

HTTP/

HTTPS/

FTP

,

AWS S3

, and

Google Cloud Storage

, adding to the previous

GeoJSON

and

CouchDB

options:

Loading raster data

To load raster files using the Data Source Manager, click on the Open Data Source Manager icon , or press Ctrl + L. From the list of layer types on the left, choose Raster.

You now have the option to load a raster file for File or Protocol: HTTP(S), cloud, etc. (much like Vector):

The commonly used raster types supported by GDAL are as follows:

ArcInfo ASCII Grid (

.asc

)

Erdas Imagine (

.img

)

GeoTIFF (

.tif

/

.tiff

)

JPEG/JPEG-2000 (

.jpg

or

.jpeg

/

.jp2

or

.j2k

)

Portable Network Graphics (

.png

)

RasterLite (

.sqlite

)

USGS Optional ASCII DEM (

.dem

)

The Geospatial Data Abstraction Library (GDAL) is a free and open source library that translates and processes vector and raster geospatial data formats. QGIS, as well as many other programs, uses GDAL to handle many geospatial data processing tasks. You may see references to OGR or GDAL/OGR as you work with QGIS and GDAL. OGR Simple Features Library references the vector processing parts of GDAL. OGR is not really a standalone project, as it is part of the GDAL code now; however, for historical reasons, OGR is still used. More information about GDAL and OGR can be found at http://gdal.org. GDAL is an OSGeo (http://osgeo.org) project.

Loading databases

QGIS supports PostGIS, SpatiaLite, Microsoft SQL Server, and Oracle databases. Regardless of the type of database you wish to load, the loading sequence is very similar. Therefore, instead of covering specific examples, the general sequence will be covered.

To create a new database connection using the Data Source Manager, perform the following:

Click on the

Open

Data Source Manager

icon

or press

Ctrl

+

L

On the left, choose the database you want to connect to, and, in the connection window, click on the

New

button

Add all the connection details required

To add a layer once a connection has been established, perform the following:

Click on the 

Open Data Source Manager

icon

Click on

Connect

When connected successfully, you will be presented with a list of layers that can be added to the Map Canvas. An alternative and perhaps better method for loading data on the Map Canvas is to use the Browser panel once you have created the new database connection. Using the Browser panel gives the user a cleaner overview of the layers and tables that can be added to the Map Canvas. 

Note that the window will look the same for any database you choose, except for the window name.

Loading web services

QGIS supports the loading of OGC-compliant web services such as WMS/WMTS, WCS, and WFS. Loading a web service is similar to loading a database service in that you must first set up the connection to the service, and then connect to the service to choose which layers to add to the Map Canvas.

As an example, to add a WMS service, click on the Open Data Source Manager icon or press Ctrl + L, and, on the left-hand side of the window, click on WMS/WMTS.

Click on the New button and give the new connection details a name (this is a free text friend, so the name can be anything you wish) and then add in the URL of the WMS/WMTS. Once completed, click on OK.

As with viewing data from databases in the previous section, to view the data available via the connection that you have established via the Data Source Manager, it is best to access the data via the browser panel.

Working with CRS

When working with spatial data, it is important that a CRS is assigned to the data and the QGIS project. To view the CRS for the QGIS project, click on Properties under Project, and choose the CRS tab.

It is recommended that all data added to a QGIS project be projected into the same CRS as the QGIS project. However, if this is not possible or convenient, QGIS can project layers on the fly to the project's CRS.

If you want to quickly search for a CRS, you can enter the EPSG code to quickly filter through the CRS list. An EPSG code refers to a specific CRS stored in the EPSG Geodetic Parameter Dataset online registry that contains numerous global, regional, and local CRSs. An example of a commonly used EPSG code is 4326, which refers to WGS 84. The EPSG online registry is available at http://www.epsg-registry.org/.