Book Image

Mastering Geospatial Development with QGIS 3.x - Third Edition

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

Mastering Geospatial Development with QGIS 3.x - Third Edition

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

Overview of this book

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.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

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.

Note

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 Managericon

, 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:

Note

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)

Note

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:

  1. Click on the OpenData Source Manager icon
    or press Ctrl + L
  2. On the left, choose the database you want to connect to, and, in the connection window, click on the New button
  3. Add all the connection details required

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

  1. Click on the Open Data Source Manager icon
  2. 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

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.