Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering  QGIS
Mastering  QGIS

Mastering QGIS: Go beyond the basics and unleash the full power of QGIS with practical, step-by-step examples , Second Edition

Arrow left icon
Profile Icon Corti Profile Icon Kurt Menke, GISP Profile Icon Van Hoesen, GISP Profile Icon Pirelli Profile Icon Smith Jr., GISP +1 more Show less
Arrow right icon
€8.99 €36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (4 Ratings)
eBook Sep 2016 486 pages 2nd Edition
eBook
€8.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Corti Profile Icon Kurt Menke, GISP Profile Icon Van Hoesen, GISP Profile Icon Pirelli Profile Icon Smith Jr., GISP +1 more Show less
Arrow right icon
€8.99 €36.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (4 Ratings)
eBook Sep 2016 486 pages 2nd Edition
eBook
€8.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering QGIS

Chapter 1. A Refreshing Look at QGIS

You are probably anxious to get started using QGIS. In this chapter, we will review the basic functionality of QGIS, which will be assumed knowledge for the remaining chapters in this book. If you need a refresher on QGIS or a quick-start 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. It was started by Gary Sherman in 2002. The project was incubated with the Open Source Geospatial Foundation (OSGeo) in 2007. Version 1.0 was 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. 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 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 this book, QGIS 2.14 is the stable version and is also the current LTR.

Tip

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

QGIS download and installation

QGIS can be installed on Windows, Mac OS X, 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, Mac OS X, and Ubuntu Linux. For the most up-to-date installation instructions, refer to the QGIS website.

Installing QGIS on Windows

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.
  • 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.

Installing QGIS on Mac OS X

Follow these steps to install QGIS on a Mac:

  1. As an initial step, it is often necessary to change your Mac security preferences to Allow apps downloaded from: Anywhere.
  2. The Mac QGIS installation files are available from http://www.kyngchaos.com/software/qgis.
  3. Download and install the GDAL Complete 1.11 framework package.
  4. Download and install NumPy: http://www.kyngchaos.com/software/python.
  5. Download and install the Matplotlib Python module.
  6. Download and install the QGIS Mac OSX Installer.
  7. Navigate to your applications folder and locate the QGIS.app. Double click to launch.
  8. At this point, you can change your Mac security settings back to Allow apps downloaded from: Mac App Store and Identified Developers.

    Tip

    Note: QGIS requires the following versions of the MAC operating system: OS X Mavericks (10.9), Mountain Lion (10.8), or Lion (10.7).

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's 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

The following information box describes QGIS options for Android devices.

Note

There is an experimental version of QGIS available in the Google Play Store (https://play.google.com/store/apps/details?id=org.qgis.qgis). You can find more information about this at http://www.qgis.org/en/site/forusers/alldownloads.html#android.

The download page is available at http://qgis.org/downloads/android/.

A related data collection app has recently been announced and it is named QField. It is described as a field data capture and management app that is compatible with QGIS. It is available in the Google Play Store. You can find more information on this app at http://www.opengis.ch/android-gis/qfield/.

Installing QGIS on a Chromebook

It is possible to install Ubuntu Linux on a Chromebook via Crouton. This essentially creates a dual boot environment allowing you to switch between the Chrome OS and Ubuntu very quickly with some keyboard strokes. At that point, QGIS can also be installed normally on the Ubuntu OS. There are very thorough instructions for installing Ubuntu at the following link: http://www.voltron00x.com/?p=1091. If you would like to try this, it is best to purchase a Chromebook with the Intel Core i3 processor and 4 GB of RAM.

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 to manage and preview 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 Display. The following screenshot shows QGIS Desktop with all four interface types displayed:

Familiarizing yourself with QGIS Desktop

The map display shows the styled data added to the QGIS project and, by default, takes up the majority of the space in QGIS Desktop. The menu bar, displayed across the top, provides access to most of QGIS Desktop's functionality. The toolbars provide quick access to QGIS Desktop functionality. The toolbars can be arranged to either float independently or dock at the top, bottom, left, or right sides of the application. 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.

There are four toolbars that are particularly useful, and it is recommended that you enable them:

  • The File toolbar provides quick access to create, open, and save QGIS projects and create and manage print composers
  • The Manage Layers toolbar contains tools to add vectors, rasters, databases, web services, and text layers, and also create new layers
  • The Map Navigation toolbar contains tools that are useful for panning, zooming, and refreshing the map display
  • The Attributes toolbar provides access to information, selection, field calculator, measuring, bookmarking, and annotation tools

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 or the enabled Toolbars button, which will open a context menu allowing you to toggle 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.

User interface themes

A new feature of QGIS Desktop is user interface themes. These are similar to skins for the application. These can be found by clicking Settings on the Menu bar and choosing Options. On the General tab, there is an option for UI Theme. If you are doing some late-night mapping, you might experience eye fatigue from the normal bright interface. Click the dropdown arrow and choose Night Mapping. The QGIS interface will switch to a dark skin.

User interface themes

You can also create your own themes. Start by reviewing the QSS style file that creates the Night Mapping theme from GitHub: https://github.com/qgis/QGIS/tree/master/resources/themes. To create a new theme, modify this file and save it to your .qgis2\themes folder.

Familiarizing yourself with QGIS Browser

The QGIS Browser interface (shown in the following screenshot) is composed of three parts: Toolbar, Data Tree view, and Information Panel:

Familiarizing yourself with QGIS Browser

The data tree view is an expandable tree listing of all geospatial data files on your computer and through connections. The information display, which takes most of the space on the application, contains four tabs that provide different views of the selected data in the data tree listing, and they are as follows:

  • Param: This tab displays details of data that is accessed through connections, such as a database or WMS.
  • Metadata: This tab displays the metadata (if any) of the selected data.
  • Preview: This tab renders the selected data. You can zoom into the data using your mouse wheel and pan using the arrow keys on your keyboard.
  • Attributes: This tab displays the attribute table associated with the selected data. You can sort the columns by clicking on the column headings. This tab is only available for vector data.

The toolbar provides access to four functions. The Refresh function reloads the data tree view, while the Manage WMS function opens the WMS management screen allowing you to manage the WMS connections. The New Shapefile function opens the new vector layer dialog, allowing new shapefiles to be created. Finally, the Set layer CRS function allows you to define the coordinate reference system of the geospatial data file that is selected in the data tree view.

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 four ways. The first way, which will be covered in detail in this section, is to use the Add Layer menu under Layer and select the appropriate type of data that you wish to load. The second way is to open the Browser panel, navigate to the data you wish to load, and then drag the data onto the map display or onto the Layers panel. The third way to load data is to enable the Manage Layers toolbar and click on the button representing the data type that you wish to load. The fourth way is to locate the data in QGIS Browser, drag the data, and drop it onto the QGIS Desktop map display or the Layers panel.

Loading vector data

To load vector files, click on Add Vector Layer by navigating to Layer | Add Layer. This will open the Add Vector Layer dialog that will allow us to choose the source type and the source of the dataset that we wish to load.

The source type contains four options: File, Directory, Database, and Protocol. 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:

  • File: This can load flat files that are stored on disk. The commonly used flat file types are as follows:
    • 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 URI. QGIS currently supports loading the GeoJSON and CouchDB protocols.

Loading raster data

To load raster data into QGIS, click on Add Raster Layer by navigating to Layer | Add Layer. This will open a file browser window and allow you to choose a GDAL-supported raster file. 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)

To add an Oracle GeoRaster, click on Add Oracle GeoRaster Layer by navigating to Layer | Add Layer, then connect to an Oracle database to load the raster. More information about loading database layers is given in the following section.

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.

First, click on Add Layer under Layer and then choose the database type you wish to load. This will open a window with options for adding the data stored in a database. As an example, the following screenshot shows the window that opens when you navigate to Layer | Add Layer | Add SpatiaLite Layer:

Loading databases

Tip

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

To load data from a database, we must first create a connection to the database. To create a new connection, click on the New button to open a connection information window. Depending on the database type you are connecting to, different connection options will be shown. Once you have created a database connection, select it from the drop-down list and click on Connect; you will see a list of all layers contained within the database display. If there are a large number of tables, you can select Search options and perform a search on the database. To load a layer, select it in the list and click on Add. If you only wish to load a portion of the layer, select the layer and then click on Set Filter to open the query builder. If you set a query and then add the layer, only the filtered features will be added.

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, then connect to the service to choose which layers to add to the map canvas.

As an example, to add a WMS service, click Layer | Add Layer | Add WMS/WMTS Layer. On the window that appears, click New to open the Create a new WMS connection window (shown in the following figure) where you can define the parameters of the new service. Enter a Name for the service, the URL of the service, set any of the remaining options that may apply, and then click OK to add the service as an available connection.

Loading web services

With the new service added, make sure it is selected, then click Connect to connect to the service, and list the available layers. To add a layer to the map canvas, select it, choose the Image encoding, Coordinate Reference System, and Layer name, and then click Add.

Tip

Some services support multiple CRS. After connecting to a service, select a layer and then click Change to choose the coordinate system to use.

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 Project 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.

Note

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 which contains numerous global, regional, and local CRS. 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/.

To enable on-the-fly projection, perform the following steps:

  1. Click on Project Properties under Project.
  2. Choose the CRS tab and Enable 'on the fly' CRS transformation.
  3. Set the CRS that you wish to apply to the project and make all layers that are not set to the project's CRS transform on the fly.

To view the CRS for a layer, perform the following steps:

  1. Open the layer's properties by either navigating to Layer | Properties or by right-clicking on the layer in the Layers panel.
  2. Choose Properties from the context menu and then choose the General tab.
  3. If the layer's CRS is not set or is incorrect, click on Specify to open the CRS selector window and select the correct CRS.

To project a layer to a different CRS, perform the following steps:

  1. Right-click on the layer in the Layers panel and then choose Save As from the context menu.
  2. In the Save vector layer as dialog, set the file format and filename, then set CRS to Selected CRS, click on Change to set the target CRS, and save the file.

To create a new CRS or modify an existing CRS, perform the following steps:

  1. Click on Custom CRS under Settings to open the Custom Coordinate Reference System Definition window.
  2. Click on the Add new CRS button to add a new entry to the CRS list.
  3. With the new CRS selected, we can set the name and parameters of the CRS. The CRS properties are set using the PROJ.4 format. To modify an existing CRS, click on Copy existing CRS and select the CRS from which you wish to copy parameters; otherwise, enter the parameters manually. Some background on PROJ.4 is provided below.

    Tip

    PROJ.4 is another OSGeo (http://osgeo.org) project used by QGIS, and it is similar to OGR and GDAL. This project is for managing coordinate systems and projections. For a detailed user manual for the PROJ.4 format used to specify the CRS parameters in QGIS, download it from http://download.osgeo.org/proj/OF90-284.pdf.

Working with tables

There are two types of table you can work with in QGIS: attribute tables and standalone tables. Whether they are from a database or associated with a shapefile or a flat file, they are all treated the same. Standalone tables can be added by clicking on the Add Vector Layer menu by navigating to Layer | Add Layer. QGIS supports the table formats supported by OGR, along with database tables. Tables are treated like any other GIS layer; they simply have no geometry. Both types of table can be opened within Desktop by selecting the layer/table in the Layers panel, and then by either clicking on Open Attribute Table under Layer, or by right-clicking on the data layer and choosing Open Attribute Table from the context menu. They can also be previewed in QGIS Browser by choosing the Attributes tab.

The table opens in a new window that displays the number of table rows and selected records in the title bar. Below the title bar are a series of buttons that allow you to toggle between editing, managing selections, and adding and deleting columns. Most of the window is filled with the table body. The table can be sorted by clicking on the column names. An arrow will appear in the column header, indicating either an ascending or a descending sort. Rows can be selected by clicking on the row number on the left-hand side. In the lower-left corner is a Tables menu that allows you to manage what portions of the table should be displayed. You can choose Show All Features (default setting), Show Selected Features, Show Features Visible on Map (only available when you view an attribute table), Show Edited and New Features, create column filters, and advanced filters (expression).

The lower-right corner has a toggle between the default table view and a forms view of the table. An attribute table is shown in the following screenshot, with parts of the table window identified:

Working with tables

Attribute tables are associated with the features of a GIS layer. Typically, one record in the attribute table corresponds to one feature in the GIS layer. Standalone tables are not associated with GIS data layers. However, they may have data of a spatial nature from which a spatial data layer can be generated (for more information, see Chapter 6, Advanced Data Creation and Editing). They may also contain data that you wish to join to an existing attribute table with a table join, which we will cover in the next section.

Creating table joins

Let's say that you need to make a map of the total population by county. However, the counties' GIS layers do not have population as an attribute. Instead, this data is contained in an Excel spreadsheet. It is possible to join additional tabular data to an existing attribute table.

There are two requirements, which are as follows:

  • The two tables need to share fields with attributes to match for joining
  • There needs to be a cardinality of one-to-one or many-to-one between the attribute table and the standalone table

To create a join, load both the GIS layer and the standalone table into QGIS Desktop. QGIS will accept a variety of standalone table file formats including Excel spreadsheets (.xls and .xlsx), dBase (.dbf) files, and comma separated value (.csv) files. You can load this tabular data using the Add Vector Layer menu by navigating to Layer | Add Layer and setting the file type filter to All files (*) (*.*) as shown in the following screenshot:

Creating table joins

Once the data is loaded, a join can be completed by following these steps:

  1. Select the GIS layer in the Layers panel that will receive the new data from the join.
  2. Navigate to Layer | Properties and choose the Joins tab.
  3. Click on the add join button (the one with a green plus sign).
  4. Choose the Join layer, Join field, and Target field values. The Join layer and Join field values represent the standalone table. The Target field value is the column in the attribute table on which the join will be based.

    Note

    Although in this example the join field and the target field have the same name, this is not a requirement. The two fields merely need to hold the same unique ID.

  5. At this point, you can choose Cache join layer in virtual memory, Create attribute index on join field, or Choose which fields are joined. The last option lets you to choose which fields from the join layer to append to the attribute table. A new feature also allows you to set a Custom field name prefix. At this point, the Add vector join window will look like the following screenshot.
  6. Once created, the join will be listed on the Joins tab. The extra attribute columns from the Join layer will be appended to the attribute table, where the value in the Join field matched the value in the Target field.
  7. The additional data from the join can be used to query the data and style the data.
  8. Joins can be modified by selecting the join and clicking the pencil edit button. They can be removed by clicking on the remove join button (the one with a red minus sign):
    Creating table joins

Tip

Joins only exist in virtual memory within the QGIS Desktop document. To preserve the join outside the map document, click on Save as... under Layer and save a new copy of the layer. The new layer will include the attributes appended via the join.

Editing data

Vector data layers can be edited within QGIS Desktop. Editing allows you to add, delete, and modify features in vector datasets. The first step is to put the dataset into edit mode. Select the layer in the Layers panel and click on Toggle Editing under Layer. Alternatively, you can right-click on a layer in the Layers panel and choose Toggle Editing from the context menu. Multiple layers can be edited at a time. The layer currently being edited is the one selected in the Layers panel. Once you are in the edit mode, the digitizing toolbar (shown in the following screenshot) can be used to add, delete, and modify features:

Editing data

From left to right, the tools in the digitizing toolbar are as follows:

  • The Current Edits tool allows you to manage your editing session. Here, you can save and roll back edits for one or more selected layers.
  • The Toggle Editing tool provides an additional means to begin or end an editing session for a selected layer.
  • The Save Layer Edits tool allows you to save edits for the selected layer(s) during an editing session.
  • The Add Features tool will change to the appropriate geometry, depending on whether a point, line, or polygon layer is selected. Points and vertices of lines and polygons are created by clicking on the map canvas. To complete a line or polygon feature, right-click. After adding a feature, you will be prompted to enter the attributes.
  • The Add circular string tool (enabled only when editing lines and polygons) allows you to add a line with a set radius. This tool has two options, accessed through the drop-down menu: Add circular string, and Add circular string by radius. The Add circular string tool allows you to create a circular string freehand by clicking to create two nodes, then dragging your mouse to create the arc. Add circular string by radius allows you to specify the radius of the string numerically.
  • The Move Feature(s) tool lets you move features by clicking on them and dragging them to the new position.
  • The Node Tool lets you move individual feature vertices. Click on a feature once with the tool to select it and the vertices will change into red boxes. Click again on an individual vertex to select it. The selected vertex will turn into a dark-blue box. Now, the vertex can be moved to the desired location. Additionally, edges between vertices can be selected and moved. To add vertices to a feature, simply double-click on the edge where you want the vertex to be added. Selected vertices can be deleted by pressing the Delete key on the keyboard.
  • Features can be deleted, cut, copied, and pasted using the Delete Selected, Cut Features, Copy Features, and Paste Features tools.

Snapping

Snapping is an important editing consideration. It is a specified distance (tolerance) within which vertices of one feature will automatically align with vertices of another feature. The specific snapping tolerance can be set for the whole project or per layer. The method for setting the snapping tolerance for a project varies according to the operating system, which is as follows:

  • For Windows, navigate to Settings | Options | Digitizing
  • For Mac, navigate to QGIS | Preferences | Digitizing
  • For Linux, navigate to Edit | Options | Digitizing

In addition to setting the snapping tolerance, here the snapping mode can also be set to vertex, segment, or vertex and segment. Snapping can be set for individual layers by navigating to Settings | Snapping options. Individual layer snapping settings will override those of the project. The following screenshot shows examples of multiple snapping option choices:

Snapping

Note that there are also checkboxes for Enable topological editing and Enable snapping on intersection, which are covered in more detail in Chapter 6, Advanced Data Creation and Editing.

Tip

There are many digitizing options that can be set by navigating to Settings | Options | Digitizing. These include settings for Feature Creation, Rubberband, Snapping, Vertex markers, and Curve Offset Tool. There is also an Advanced Digitizing toolbar, which is covered in Chapter 6, Advanced Data Creation and Editing.

Styling vector data

When you load spatial data layers into QGIS Desktop, they are styled with a random single symbol rendering. To change this, navigate to Layer | Properties | Style.

There are several rendering choices available from the menu in the top-left corner, which are as follows:

  • Single Symbol: This is the default rendering in which one symbol is applied to all the features in a layer.
  • Categorized: This allows you to choose a categorical attribute field to style the layer. Choose the field and click on Classify, and QGIS will apply a different symbol to each unique value in the field. You can also use the Set column expression button to enhance the styling with a SQL expression.
  • Graduated: This allows you to classify the data by a numeric field attribute into discrete categories. You can specify the parameters of the classification (classification type and number of classes) and use the Set column expression button to enhance the styling with a SQL expression.
  • Rule-based: This is used to create custom rule-based styling. Rules will be based on SQL expressions.
  • Point Displacement: If you have a point layer with stacked points, this option can be used to displace the points so that they are all visible.
  • Inverted Polygons: This is a new renderer that allows a feature polygon to be converted into a mask. For example, a city boundary polygon that is used with this renderer would become a mask around the city. It also allows the use of Categorized, Graduated, and Rule-based renderers and SQL expressions.
  • Heatmap: This allows you to create a heat map rendering of point data based on an attribute.
  • 2.5 D: This allows you to extrude data into 2.5 D space. A common use case is to extrude building footprints upward, creating an almost 3D rendering.

The following screenshot shows the Style properties available for a vector data layer:

Styling vector data

In the preceding screenshot, the renderer is the layer symbol. For a given symbol, you can work with the first level, which gives you the ability to change the transparency and color. You can also click on the second level, which gives you control over parameters such as fill, border, fill style, border style, join style, border width, and X/Y offsets. These parameters change depending on the geometry of your layer. You can also use this hierarchy to build symbol layers, which are styles built from several symbols that are combined vertically.

Styling raster data

You also have many choices when styling raster data in QGIS Desktop. There is a different choice of renderers for raster datasets, which are as follows:

  • Multiband color: This is for rasters with multiple bands. It allows you to choose the band combination that you prefer.
  • Paletted: This is for singleband rasters with an included color table. It is likely that it will be chosen by QGIS automatically, if this is the case.
  • Singleband gray: This allows a singleband raster or a single band of a multiband raster to be styled with either a black-to-white or white-to-black color ramp. You can control contrast enhancement and how minimum and maximum values are determined.
  • Singleband pseudocolor: This allows a singleband raster to be styled with a variety of color ramps and classification schemes.

The following is a screenshot of the Style tab of a raster file's Layer Properties, showing where the aforementioned style choices are located:

Styling raster data

Enhancing raster display with contrast enhancement

Another important consideration with raster styling is the settings that are used for contrast enhancement when rendering the data. Let's start by loading the Jemez_dem.img image and opening the Style menu under Layer Properties (shown in the following figure). This is an elevation layer and the data is being stretched on a black-to-white color ramp from the Min and Max values listed under Band rendering. By default, these values only include those that are from 2 percent to 98 percent of the estimation of the full range of values in the dataset, and cut out the outlying values. This makes rendering faster, but it is not necessarily the most accurate.

Next, we will change these settings to get a full stretch across all the data values in the raster. To do this, perform the following steps:

  1. Under the Load min/max values section, choose Min / max and under Accuracy, choose Actual (slower).
  2. Click on Load.
  3. You will notice that the minimum and maximum values change. Click on Apply.

As shown in the following figure, by enhancing the contrast, the raster is displayed with much more detail, and is more visually attractive, too:

Enhancing raster display with contrast enhancement

Default singleband contrast enhancement (left) and more accurate contrast enhancement (right)

You can specify the default settings for rendering rasters by navigating to Settings | Options | Rendering. Here, the defaults for the Contrast enhancement, Load min/max values, and Cumulative count cut thresholds, and the standard deviation multiplier, can be set.

Blending modes

The blending modes allow for more sophisticated rendering between GIS layers. Historically, these tools have only been available in graphics programs and they are a fairly new addition to QGIS. Previously, only layer transparency could be controlled. There are now 13 different blending modes that are available: Normal, Lighten, Screen, Dodge, Addition, Darken, Multiply, Burn, Overlay, Soft light, Hard light, Difference, and Subtract. These are much more powerful than simple layer transparency, which can be effective but typically results in the underneath layer being washed out or dulled. With blending modes, you can create effects where the full intensity of the underlying layer is still visible. Blending mode settings can be found at the bottom of the Style menu under Layer Properties in the Layer Rendering section (for vectors) and Color rendering section (for rasters).

As an example of using blending modes, we will show vegetation data (Jemez_vegetation.tif) in combination with a hillshade image (Jemez_hillshade.img). Both datasets are loaded and the vegetation data is dragged to the top of the layer list. Vegetation is then styled with a singleband pseudocolor renderer; you can do this by performing the following steps:

  1. Choose Random colors.
  2. Set Mode to Equal interval.
  3. Set the number of Classes to 13.
  4. Click on Classify.
  5. Click on Apply.

The following screenshot shows what the Style properties should look like after following the preceding steps:

Blending modes

At the bottom of the Style menu, under Layer Properties, set the Blending mode to Multiply and the Contrast to 45, and click on Apply. The blending mode allows all the details of both the datasets to be seen. Experiment with different blending modes to see how they change the appearance of the image. The following screenshot shows an example of how blending and contrast settings can work together to make a raster pop off the screen:

Blending modes

Composing maps

With QGIS, you can compose maps that can be printed or exported to image and graphic files. To get started, click on New Print Composer under Project. Give the new composition a name, click on OK, and the composer window will open.

The composer presents you with a blank sheet of paper upon which you can craft your map. Along the left-hand side, there are a series of tools on the Composer Items toolbar. The lower portion of the toolbar contains buttons for adding map elements to your map. These include the map body, images, text, a legend, a scale bar, graphic shapes, arrows, attribute tables, and HTML frames. Map elements become graphics on the composition canvas. By selecting a map element, graphic handles will appear around the perimeter. These can be used to move and resize the element. The upper portion of the Composer Items toolbar contains tools for panning the map data, moving other graphic content, and zooming and panning on the map composition.

The majority of the map customization options can be found in the composer tabs. To specify the sheet size and orientation, use the Composition tab. Once map elements have been added to the map, they can be customized with the Item properties tab. The options available on the Item properties tab change according to the type of map element that is selected. The Atlas generation tab allows you to generate a map book. For example, a municipality could generate an atlas by using a map sheet GIS layer and specifying which attribute column contains the map sheet number for each polygon. The Items tab allows you to toggle individual map elements on and off.

The toolbars across the top contain tools for aligning graphics (the Composer Items actions toolbar), navigating around the map composition (the Paper Navigation toolbar), and tools for managing, saving, and exporting compositions (the Composer toolbar). Maps can be exported as images, PDFs, and SVG graphic files. To export the map, click on the Composer menu and select one from among Export as image..., Export as SVG..., or Export as PDF... depending on your needs. The following is a screenshot showing parts of the composer window:

Composing maps

Adding functionality with plugins

There are so many potential workflows, analysis settings, and datasets within the broad field of GIS that no out-of-the-box software could contain the tools for every scenario. Fortunately, QGIS has been developed with a plugin architecture. Plugins are add-ons to QGIS that provide additional functionality. Some are written by the core QGIS development team, and others are written by QGIS users.

Tip

You can also browse the QGIS Python Plugins Repository at https://plugins.qgis.org/plugins/.

You can explore the QGIS plugin ecosystem by navigating to Plugins | Manage and Install Plugins. This opens the Plugins Manager window (shown in the following figure) which will allow you to browse all plugins, those that are installed, those that are not installed, and plugins that are newly available, and also adjust the plugin manager settings. If there are installed plugins with available upgrades, there will also be an Upgradable option. The search bar can be used to enter search terms and find available plugins related to the topic. This is the first place to look if there's a tool or extra type of functionality that you need! To install a plugin, simply select it and click on the Install Plugin button. Installed plugins can be toggled on and off by checking the box next to each:

Adding functionality with plugins

You will be notified by a link at the bottom of the QGIS Desktop application if there are updates available for your installed plugins. Clicking on the link will open the Plugins Manager window, where the Upgrades tab will allow you to install all or some of the available updates. Plugins themselves may show up as individual buttons, toolbars, or as items under the appropriate menu, such as Plugins, Vector, Raster, Database, Web, or Processing. The following information box describes a great plugin for adding base maps.

Note

To add a base map to QGIS, enable the Quick Map Services plugin. Once it's installed, it appears as an item on the Web menu. You can configure it to include more map services. From the menu bar, choose Web | QuickMapServices | Settings. Click on the Contributed Services tab and click the Get contributed pack button. At this point, it will allow you to add base maps from OpenStreetMap, Google Maps, Bing Maps, Map Quest, OSM/Stamen, Apple Maps, and several more. This plugin requires an Internet connection.

Custom QGIS variables

A new feature of QGIS since version 2.12 is custom variables. Variables can be set at several different scopes or levels:

  • Global
  • Project
  • Layer

Global variables are available at the application level in any QGIS Desktop instance. These can be managed from Settings | Options | Variables. Project variables are available throughout a given project. These can be set from the Project Properties window on the Variables tab. Layer-level variables are available from Layer Properties on the Variables tab and are available only for that layer. The other important aspect of these variables is that they cascade from most specific scope to least specific scope. In other words, a @my_var set at the Global level will be overwritten by a @my_var set at the Project level.

To begin, we will explore the variables for a project that was just saved. We will click on Project | Project Properties | Variables (see the following figure). Here you can browse both the default Global and Project variables. When a project is saved, three Project-level variables are populated by default: @project_filename, @project_folder, and @project_path. @project_title will also be populated if you have set that on the General tab. Note that when referencing variables, they are preceded by an ampersand to differentiate them from fields or functions. These variables can be used anywhere and expressions can be written such as the Field calculator, Label expressions, or Map Composer labels. With that introduction, we will go through several example use cases:

Custom QGIS variables

Using Project level variables in the Print Composer

One use case for variables is in the Print Composer. Say you want to have variables for the cartographer's name and the project path to be used on each map in a project. You can add a new Project-level variable by clicking on the green plus button and typing in a variable name and the value. In this example, a new variable has been added named @Cartographer and populated with the name. (Note: if you want to add a Global variable, you can do that from Settings | Options | Variables.)

Using Project level variables in the Print Composer

Once the Print Composer is open, a label can be added to a map composition using these variables. To reference a variable in a Print Composer Label, use the following syntax: [%@variable%]. If you have multiple map compositions in a project, these variable can be used in each. Better yet, the composition can be saved as a template for future use, along with the variables. Using custom variables can be a real time saver and can help avoid mistakes. In this example, the path to the project is important to have on a map. If the project is moved, you may forget to update that item. Using a variable causes that information to be updated automatically.

Using Project level variables in the Print Composer

Any text that needs to be used repeatedly can be stored in a custom variable. Remember that Global variables are also available in this context. If you want information to be accessible in any QGIS project, make it a Global variable. Additionally, creating a Project level variable with the same name as a Global variable will overwrite the Global variable. The Global variable can be used as a default setting. If that needs to change in a particular map project, simply create a Project level variable with the same name. In the following example, the Global variable @department has been overwritten by a Project level variable:

Using Project level variables in the Print Composer

Using variables in data defined overrides

Data defined overrides are available for most layer labeling parameters. For example, these can be used to control label placement by linking to attribute columns containing the X/Y coordinates for the label position. Now custom variables can also be used as inputs to Data defined override. If we want use the font Calibri for all the labels on a map, we can set that as a Project variable called @label_font with a value of Calibri. Then when we open Layer Properties | Labels | Text, we can set Data defined override for the font to that variable by choosing the Variable option from the context menu (see the following figure).

Using variables in data defined overrides

We can repeat this step for each labeled layer. If we then decide Calibri is not working, and we are not using a variable for font, we have to open Layer Properties | Labels | Text for each layer and make the change. Using a variable, we can simply change the value of the @label_font variable to Franklin Gothic. All the labels will be updated automatically! This makes seeing the effects of such changes quick and easy. Variables can be used for any Data defined override.

Using Layer level variables

Layer level variables can be used in expressions that are evaluated within a layer. This includes rule-based styling or labeling expressions, diagrams, and the Field calculator. In this example, we frequently need to update the acreage for a set of polygons in a State Plane CRS. We can store the conversion factor from square feet to acres as a Layer level variable called @feet_2 acres. To manage Layer level variables, open Layer Properties | Variables. You will be able to see Global, Project, and Layer level variables:

Using Layer level variables

When we open the Field calculator to update the acreage field, we can use the @ft_2_acres variable to calculate the acreage with the following expression: $area * @ft_2_acres. All the available variables are listed in the Variables section:

Using Layer level variables

Variables are still a very new feature, but have a lot of potential for creating more efficient workflows. You will learn additional use cases for variables in the final section of Chapter 8, The Processing Toolbox, where the Atlas feature is described. Once you begin using them, you will undoubtedly discover many other use cases.

Summary

This chapter provided a refresher in the basics of QGIS Desktop and QGIS Browser. We covered how to install the software on several platforms and described the layout of both QGIS Desktop and QGIS Browser. We then covered how to load vector, raster, and database data layers. Next, you were shown how to work with coordinate reference systems and style data. We covered the basics of working with tables, including how to perform a table join. The chapter concluded with a refresher on composing maps, how to find, install, and manage plugins, and a primer on QGIS custom variables.

The next chapter will cover creating spatial databases. Data is the foundation of any GIS. Now that you have had a refresher on the basics of QGIS, it is time to learn how to expand your work to include spatial databases. In Chapter 2, Creating Spatial Databases, you will learn how to create and manage spatial databases within QGIS.

Left arrow icon Right arrow icon

Key benefits

  • •This book is your one-stop solution to all of your GIS needs using the open source QGIS
  • •Master QGIS by learning about database integration, geoprocessing tools, Python scripts, advanced cartography, and custom plugins
  • •This example-rich, practical guide will help you create sophisticated analyses and maps

Description

QGIS is an open source solution to GIS. It is widely used by GIS professionals all over the world. It is the leading alternative to the 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, this book will take you all the way through to creating your first custom QGIS plugin. From the refresher, we will recap how to create, populate, and manage a spatial database. You’ll also walk through styling GIS data, from creating custom symbols and color ramps to using blending modes. In the next section, you will discover how to prepare vector, heat maps, and create live layer effects, labeling, and raster data for processing. You’ll also discover advanced data creation and editing techniques. The last third of the book covers the more technical aspects of QGIS such as using LAStools and GRASS GIS’s integration with the Processing Toolbox, how to automate workflows with batch processing, and how to create graphical models. Finally, you will see how to create and run Python data processing scripts and write your own QGIS plugin with pyqgis. By the end of the book, you will understand how to work with all the aspects of QGIS, and will be ready to use it for any type of GIS work.

Who is this book 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 you will learn

  • • Create and manage a spatial database
  • • Get 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 plugin

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 30, 2016
Length: 486 pages
Edition : 2nd
Language : English
ISBN-13 : 9781786463623
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 30, 2016
Length: 486 pages
Edition : 2nd
Language : English
ISBN-13 : 9781786463623
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 139.97
QGIS:Becoming a GIS Power User
€63.99
Mastering  QGIS
€45.99
Learning QGIS, Third Edition
€29.99
Total 139.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. A Refreshing Look at QGIS Chevron down icon Chevron up icon
2. Creating Spatial Databases Chevron down icon Chevron up icon
3. Styling Raster and Vector Data Chevron down icon Chevron up icon
4. Preparing Vector Data for Processing Chevron down icon Chevron up icon
5. Preparing Raster Data for Processing Chevron down icon Chevron up icon
6. Advanced Data Creation and Editing Chevron down icon Chevron up icon
7. Advanced Data Visualization Chevron down icon Chevron up icon
8. The Processing Toolbox Chevron down icon Chevron up icon
9. Automating Workflows with the Graphical Modeler Chevron down icon Chevron up icon
10. Creating QGIS Plugins with PyQGIS and Problem Solving Chevron down icon Chevron up icon
11. PyQGIS Scripting Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(4 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Maya Aug 04, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
good book to learn gis
Amazon Verified review Amazon
RAFAEL VÁZQUEZ MÁRQUEZ Nov 03, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A pesar de que es un libro de nivel intermedio, trae un capitulo breve de introducción, los capitulos estan muy bien explicados.
Amazon Verified review Amazon
Grumpy Jun 22, 2019
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Mine said for sale in India on the cover, but it's a decent intro to qgis
Amazon Verified review Amazon
Lance Case Sep 18, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Highly recommend this for anyone serious about learning how to use QGIS. Online tutorials and user forums will only get you so far. This book steps through most, if not all, of the features of the application. It's perfect for a general introduction to the software and provides a nice starting point for your specific application. My only complaint is that the printed book is in black & white with an option to download color pictures from the publisher. The PDF version is in full color. I like having a physical book for reference, but some of the graphic examples don't work in black & white.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.