Book Image

Learning QGIS - Third Edition

By : Anita Graser
Book Image

Learning QGIS - Third Edition

By: Anita Graser

Overview of this book

QGIS is a user-friendly open source geographic information system (GIS) that runs on Linux, Unix, Mac OS X, and Windows. The popularity of open source geographic information systems and QGIS in particular has been growing rapidly over the last few years. Learning QGIS Third Edition is a practical, hands-on guide updated for QGIS 2.14 that provides you with clear, step-by-step exercises to help you apply your GIS knowledge to QGIS. Through clear, practical exercises, this book will introduce you to working with QGIS quickly and painlessly. This book takes you from installing and configuring QGIS to handling spatial data to creating great maps. You will learn how to load and visualize existing spatial data and create data from scratch. You will get to know important plugins, perform common geoprocessing and spatial analysis tasks and automate them with Processing. We will cover how to achieve great cartographic output and print maps. Finally, you will learn how to extend QGIS using Python and even create your own plugin.
Table of Contents (13 chapters)
Learning QGIS Third Edition
About the Author
About the Reviewer


Welcome to the third edition of Learning QGIS. This book aims to introduce you to QGIS 2.14 and show you how to perform core geospatial tasks using this popular open source GIS. It takes you through six chapters from QGIS installation and setup in the first chapter, to the essentials of viewing spatial data in the second chapter. The third chapter covers data creation and editing, followed by the fourth chapter, which offers an introduction to performing spatial analysis in QGIS. In the fifth chapter, you will learn how to create great maps and how to prepare them for print, and the final chapter shows you how you can extend QGIS using the Python scripting language.

What this book covers

Chapter 1, Getting Started with QGIS, covers the installation and configuration of QGIS. We will also see the user interface and how to customize it. By the end of this chapter, you will have QGIS running on your machine and be ready to start with the tutorials.

Chapter 2, Viewing Spatial Data, covers how to view spatial data from different data sources. QGIS supports many file and database formats as well as OGC web services. We will first see how we can load layers from these different data sources. Then, we will look into the basics of styling both vector and raster layers and will create our first map. We will finish this chapter with an example for loading background maps from online services.

Chapter 3, Data Creation and Editing, covers how to create and manipulate spatial datasets. We will cover how to select features and take measurements before we continue with editing feature geometries and attributes. We will then reproject vector and raster data and learn how to convert between different file formats. Furthermore, we will join data from text files and spreadsheets to our spatial data. We will also explore the use of temporary scratch layers, learn how to fix common topological errors, and finally, how to load data into spatial databases.

Chapter 4, Spatial Analysis, covers raster processing and analyses tasks such as clipping and terrain analysis. Then we cover converting between raster and vector formats before we continue with common vector geoprocessing tasks such as generating heatmaps and calculating area shares within a region. Finally, we will finish the chapter with exercises in automating geoprocessing workflows using the QGIS Processing modeler and leveraging the power of spatial databases for analysis.

Chapter 5, Creating Great Maps, covers important features that enable us to create great maps. We will go into advanced vector styling, building on what we learned in Chapter 2, Viewing Spatial Data. Then, we will cover labeling using examples of labeling point locations as well as creating more advanced road labels with road shield graphics. We will also cover how to tweak labels manually. We will get to know the print composer and how to use it to create printable maps and map books. Finally, we will cover solutions to present your maps on the Web.

Chapter 6, Extending QGIS with Python, covers scripting QGIS with Python. We will start with an introduction to actions before we get started with the QGIS Python Console and more advanced development of custom tools for the Processing toolbox. Finally, we will cover how to create our own plugins.

What you need for this book

To follow the exercises in this book, you need QGIS 2.14. QGIS installation is covered in the first chapter and download links for the exercise data are provided in the respective chapters.

Who this book is for

If you are a user, developer, or consultant and want to know how to use QGIS to achieve the results you are used to from other GIS, this is the book for you. This book is not intended to be a GIS textbook. You, the reader, are expected to be comfortable with core GIS concepts.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "use [% $now %] to insert the current time stamp".

A block of code is set as follows:

( landcover@1 > 0 AND landcover@1 <= 6 ) * 100
+ ( landcover@1 >= 7 AND landcover@1 <= 10 ) * 101
+ ( landcover@1 >= 11 ) * 102

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

def initGui(self):
    # create the toolbar icon and menu entry
    icon_path = ':/plugins/MyFirstMapTool/icon.png'
        icon_path,'My 1st Map Tool'),

Any command-line input or output is written as follows:

sudo apt-get install qgis python-qgis qgis-plugin-grass

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "To add text to the map, we can use the Add new label button or go to Layout | Add label".


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

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

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.