Chapter 1 Setting-up QGIS Environment

1.1 Installation

QGIS runs on Windows, various Linux distributions, Unix, Mac OS X, and Android. The QGIS project provides ready-to-use packages as well as instructions to build from the source code at https://qgis.org/en/site/forusers/download.html.

In this section, we will explain on how to install QGIS on Windows, Ubuntu and Mac OS X, as well as how to avoid the most common pitfalls.

Further installation instructions for other supported operating systems are available at http://www.qgis.org/en/site/forusers/alldownloads.html.

One of the good things of open source projects is that you have a choice between different releases. It is the same with QGIS. The following options are available, you can choose only one or you can choose all versions if you believe that you are categorized as one in 13.5 percent of population as an early adopter :D:

  • Latest release (LR): It is the version that includes newly developed and tested features. It is currently released every four months (except when an LTR version is released instead). If you want to stay up to date with the latest development but not comfortable with using development version, you can use this version.

  • Long-term release (LTR): The LTR version is recommended for corporate and academic use. It is currently released once per year in the end of February. It receives bug fix updates for at least a year, and the features and user interface remain unchanged. This makes it the best choice for training material that should not become outdated after a few months.

  • Developer version (DEV, master, or testing): The cutting-edge DEV version contains the latest and greatest developments, but be warned that on some days, it might not work as reliably as you want it to.

For this training, we will cover the steps on how to install the LR (QGIS 3) and the LTR version (QGIS 2.18).

You can have more information about the releases as well as the schedule for future releases at http://www.qgis.org/en/site/getinvolved/development/roadmap.html#release-schedule.

For an overview of the changes between releases, check out the visual change logs at http://www.qgis.org/en/site/forusers/visualchangelogs.html.

1.1.1 Installing QGIS on Windows

On Windows, there are two different options to install QGIS, the standalone installer and the OSGeo4W installer:

  • The standalone installer is one big file to download (approximately 280 MB); it contains a QGIS release, the Geographic Resources Analysis Support System (GRASS) GIS, as well as the System for Automated Geoscientific Analyses (SAGA) GIS in one package.

  • The OSGeo4W installer is a small, flexible installation tool that makes it possible to download and install QGIS and many more OSGeo tools with all their dependencies. The main advantage of this installer over the standalone installer is that it makes updating QGIS and its dependencies very easy. You can always have access to both the current release and the developer versions if you choose to, but, of course, you are never forced to update. That is why I recommend that you use OSGeo4W.

You can download the 32-bit and 64-bit OSGeo4W installers from http://osgeo4w.osgeo.org (or directly from http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86.exe for the 32-bit version or http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe if you have a 64-bit version of Windows). Download the version that matches your operating system and keep it! In the future, whenever you want to change or update your system, just run it again.

We have prepared the installation files for the training. You can download the softwares from our local server in this link http://ims.geoinfo.ait.ac.th/qgis-doc/softwares/

Regardless of the installer you choose, make sure that you avoid special characters such as German umlauts or letters from alphabets other than the default Latin ones (for details, refer to https://en.wikipedia.org/wiki/ISO_basic_Latin_ alphabet) in the installation path, as they can cause problems later on, for example, during plugin installation.

When the OSGeo4W installer starts, we get to choose between Express Desktop Install, Express Web-GIS Install, and Advanced Install.

To install the QGIS LR version, we can simply select the Express Desktop Install option, and the next dialog will list the available desktop applications, such as QGIS, uDig, and GRASS GIS. We can simply select QGIS, click on Next, and confirm the necessary dependencies by clicking on Next again. Then the download and installation will start automatically. When the installation is complete, there will be desktop shortcuts and start menu entries for OSGeo4W and QGIS.

To install QGIS LTR (or DEV), we need to go through the Advanced Install option, as shown in Figure 1.1.

Installation using OSGeo4W64

Figure 1.1: Installation using OSGeo4W64

This installation path offers many options, such as Download Without Installing and Install from Local Directory, which can be used to download all the necessary packages on one machine and later install them on machines without Internet access. We just select Install from Internet, as shown in Figure 1.2.

Install from Internet

Figure 1.2: Install from Internet

When selecting the installation Root Directory, as shown in the following screenshot, avoid special characters such as German umlauts or letters from alphabets other than the default Latin ones in the installation path (as mentioned before), as they can cause problems later on, for example, during plugin installation, as shown in Figure 1.3.

Selecting Root Directory

Figure 1.3: Selecting Root Directory

Then you can specify the folder (Local Package Directory) where the setup process will store the installation les as well as customize Start menu name. I recommend that you leave the default settings similar to what you can see in Figure 1.4.

Select Local Package Directory

Figure 1.4: Select Local Package Directory

In the Internet connection settings, it is usually not necessary to change the default settings, but if your machine is, for example, hidden behind a proxy, you will be able to specify it here (Figure 1.5.)

Selecting Your Internet Connection

Figure 1.5: Selecting Your Internet Connection

Then we can pick the download site. At the time of writing this book, there are three download server available, as you can see in Figure 1.6. In this tutorial, you can choose http://download.osgeo.org.

Choose a Download Site

Figure 1.6: Choose a Download Site

After the installer fetches the latest package information from OSGeo’s servers, we get to pick the packages for installation. QGIS LTR is listed in the desktop category as qgis-ltr (and the DEV version is listed as qgis-dev). To select the LTR version for installation, click on the text that reads Skip, and it will change and display the version number, as shown in Figure 1.7.

Selecting Packages

Figure 1.7: Selecting Packages

As you can see in the following screenshot, the installer will automatically select all the necessary dependencies (such as GDAL, SAGA, OTB, and GRASS), so we don’t have to worry about this (Figure 1.8.)

Automatic Installation of Dependent Packages

Figure 1.8: Automatic Installation of Dependent Packages

After you’ve clicked on Next, the download and installation starts automatically, just as in the Express version. You have probably noticed other available QGIS packages called qgis-ltr-dev and qgis-rel-dev. These contain the latest changes (to the LTR and LR versions, respectively), which will be released as bug fix versions according to the release schedule. This makes these packages a good option if you run into an issue with a release that has been fixed recently but the bug fix version release is not out yet.

If you try to run QGIS and get a popup that says, The procedure entry point could not be located in the dynamic link library .dll, it means that you are facing a common issue on Windows systems—a DLL conflict. This error is easy to fix; just copy the DLL file mentioned in the error message from C:/OSGeo4W/bin/ to C:/OSGeo4W/apps/qgis/bin (adjust the paths if necessary).

1.1.2 Installing QGIS on Ubuntu

On Ubuntu, the QGIS project provides packages for the LTR, LR, and DEV versions. At the time of writing this book, the Ubuntu versions Bionic, Artful, Xenial, and Trusty are supported, but you can find the latest information at http://www.qgis.org/en/site/forusers/alldownloads.html#debian-ubuntu. Be aware, however, that you can install only one version at a time.

In this section, the process to install QGIS 3 (LR) on Ubuntu 18.04 Bionic Beaver will be explained. You can refer to the previous link if you want to install QGIS LTR or DEV versions.

  1. First you have to add the repository of QGIS 3 on the sources.list file of your Ubuntu 18.04 Bionic Beaver machine.

You can directly edit the /etc/apt/sources.list file with the following command:

$ sudo nano /etc/apt/sources.list
  1. As you’re using Ubuntu 18.04 Bionic Beaver, you will have to add Ubuntu 18.04 specific repository of QGIS 3. The codename of Ubuntu Bionic Beaver is bionic.

Add the following line to the top or bottom of the /etc/apt/sources.list file:

deb https://qgis.org/debian bionic main

Figure 1.9 shows how it looks like once the apt line of QGIS 3 is added to the /etc/apt/sources.list file.

Adding QGIS repository

Figure 1.9: Adding QGIS repository

If you’re using nano just press Ctrl + o once to save the apt line of QGIS 3 to the /etc/apt/sources.list file. You should be prompted to save the file. Just press Enter.

  1. Now you have to import the GPG key of QGIS 3 with the following command:
$ wget -O - https://qgis.org/downloads/qgis-2017.gpg.key | gpg --import

The GPG key should be added to your Ubuntu 18.04 Bionic Beaver machine.

Now you can verify whether the GPG key was imported correctly with the following command:

$ gpg --fingerprint CAEB3DC3BDF7FB45
GPG Fingerprint

Figure 1.10: GPG Fingerprint

  1. Unless you have successfully add the GPG key of QGIS 3 to apt package manager, you won’t be able to update the apt package repository cache of QGIS 3 repository. It means you won’t be able to download and install QGIS 3 on Ubuntu 18.04.

To add GPG key to apt package manager, run the following command:

$ gpg --export --armor CAEB3DC3BDF7FB45 | sudo apt-key add -

The GPG key should be added to the apt package manager.

GPG key added to apt package manager

Figure 1.11: GPG key added to apt package manager

  1. Now you should update the apt package repository cache of Ubuntu 18.04 Bionic Beaver with the following command:
$ sudo apt-get update
  1. Now you can install QGIS 3 with the following command:
$ sudo apt-get install qgis python-qgis qgis-plugin-grass

The download and installation process of QGIS 3 should start. It should take a while.

  1. Now you can go to Activities of GNOME 3 desktop environment or Application Menu of other desktop environments and look for qgis and you should be able to find the logo of QGIS Desktop as shown in the screenshot below. Click on the QGIS Desktop logo.
QGIS installed in Ubuntu 18.04

Figure 1.12: QGIS installed in Ubuntu 18.04

1.1.3 Installing QGIS on Mac OS X

The general steps to install QGIS on a Mac are as follow:

  1. As an initial step, it is often necessary to change your Mac security preferences to Allow apps downloaded from: Anywhere.

  2. The Mac OS X QGIS installation files are available from https://www.qgis.org/en/site/forusers/download.html.

There are two versions of QGIS for Mac OS X, (1) Latest Release (LR) and (2) Long Term Release (LTR). LR version depends on Python 3.6 from python.org, and LTR version depends on Python 2.7 which is included in the disk image. For both versions, Read Me file is included.

QGIS Download for MacOS

Figure 1.13: QGIS Download for MacOS

1.1.3.1 QGIS LR installation on Mac OS X

The steps to install QGIS LR (QGIS 3) on Mac OS X are as follows:

  1. Download Python 3.6.5 from https://www.python.org/ftp/python/3.6.5/python-3.6.5-macosx10.6.pkg
Python 3.6.5 for MacOS from python.org

Figure 1.14: Python 3.6.5 for MacOS from python.org

  1. Install Python 3.6.5.

Installing Python 3.6.5 from the disk image is straight-forward, just follow the steps from the installer file and choose the default option. The first and the last step of the installation will be as followed figures :

First step of Python 3 installation

Figure 1.15: First step of Python 3 installation

Last step of the installation

Figure 1.16: Last step of the installation

  1. Install QGIS 3

QGIS 3 disk image installation file consists of numbered files for showing the sequence of the installation.

QGIS 3 disk image installation file

Figure 1.17: QGIS 3 disk image installation file

The first file is a text file that contain the instruction to install Python 3.6, it was already explained in the previous section.

Python 3.6 installation instruction

Figure 1.18: Python 3.6 installation instruction

The second step is to install GDAL Complete package. The steps are also easy to follow with the first and the last step shown in the following images:

First step of GDAL installation

Figure 1.19: First step of GDAL installation

Last step of GDAL installation

Figure 1.20: Last step of GDAL installation

The next step is QGIS installation. Like the previous installation, follow the sequence of installation and accept the default options to install QGIS.

First step of QGIS installation

Figure 1.21: First step of QGIS installation

Last step of QGIS installation

Figure 1.22: Last step of QGIS installation

QGIS 3 for Mac can be started by double-clicking the icon in /Applications/QGIS3

QGIS 3 in Mac OS X

Figure 1.23: QGIS 3 in Mac OS X

1.1.3.2 QGIS LTR installation on Mac OS X

QGIS LTR version can be installed on Mac OS X Mountain Lion (10.8) and newer.

Installation instructions are in the Read Me on the disk image. This package uses the system Python 2.7 - other distributions are not supported. It also requires the NumPy and Matplotlib packages on the disk image. Install packages in the numbered order. If an older major version is being upgraded (2.16 or older), delete QGIS.app from your Applications folder before installing this version.

QGIS 2.18 installation disk image

Figure 1.24: QGIS 2.18 installation disk image

QGIS 2.18 Read Me file

Figure 1.25: QGIS 2.18 Read Me file

First step in GDAL Complete installation

Figure 1.26: First step in GDAL Complete installation

First step in NumPy installation

Figure 1.27: First step in NumPy installation

First step in matplotlib installation

Figure 1.28: First step in matplotlib installation

First step in QGIS installation

Figure 1.29: First step in QGIS installation

QGIS 2.18 for Mac can be started by double-clicking the icon in /Applications/QGIS

QGIS 2.18 in Mac OS X

Figure 1.30: QGIS 2.18 in Mac OS X

1.2 Setting-up the environment

1.2.1 Running QGIS for the first time

When you install QGIS, you will get two applications: QGIS Desktop and QGIS Browser. If you are familiar with ArcGIS, QGIS Browser is something similar with ArcCatalog. It is a small application used to preview spatial data and related metadata. For the remainder of this book, we will focus on QGIS Desktop.

By default, QGIS will use the operating system’s default language. To follow the tutorials in this book, I advise you to change the language to English by going to Settings | Options | Locale.

On the first run, the way the toolbars are arranged can hide some buttons. To be able to work efficiently, I suggest that you rearrange the toolbars (for the sake of completeness, I have enabled all toolbars in Toolbars, which is in the View menu). I like to place some toolbars on the left and right screen borders to save vertical screen estate, especially on wide-screen displays.

Additionally, we will activate the file browser by navigating to View | Panels | Browser Panel. It will make a quick access to our spatial data. At the end, the QGIS window on your screen should look similar to the following screenshot:

1.2.2 Introducing the QGIS user interface

Now that we have set up QGIS, let’s get accustomed to the interface. Figure 1.31 shows the QGIS Graphical User Interface (GUI) elements.The biggest area is reserved for the map (Map Display). To the left of the map, there are the Layers and Browser panels. In the image, you can see how the Layers Panel looks once we have loaded some layers. To the left of each layer entry, you can see a preview of the layer style. Additionally, we can use layer group to structure the layer list. The Browser Panel provides us with quick access to our spatial data.

QGIS Graphical User Interface

Figure 1.31: QGIS Graphical User Interface

Below the map, we find important information such as (from left to right) the current map Coordinate, map Scale, and the (currently inactive) project coordinate reference system (CRS), for example, EPSG:4326.

Next, there are multiple toolbars to explore. If you arrange them as shown in the previous section, the top row contains the following toolbars:

  • File: This toolbar contains the tools needed to Create, Open, Save, and Print projects

  • Map Navigation: This toolbar contains the pan and zoom tools

  • Attributes: These tools are used to identify, select, open attribute tables, measure, and so on, and looks like this:

The second row contains the following toolbars:

  • Label: These tools are used to add, configure, and modify labels

  • Plugins: This currently only contains the Python Console tool, but will be filled in by additional Python plugins

  • Database: Currently, this toolbar only contains DB Manager, but other database-related tools (for example, the OfflineEditing plugin, which allows us to edit offline and synchronize with databases) will appear here when they are installed

  • Raster: This toolbar includes histogram stretch, brightness, and contrast control

  • Vector: This currently only contains the Coordinate Capture tool, but it will be filled in by additional Python plugins

  • Web: This is currently empty, but it will also be filled in by additional Python plugins

  • Help: This toolbar points to the option for downloading the user manual and looks like this:

On the left screen border, we place the Manage Layers toolbar. This toolbar contains the tools for adding layers from the vector or raster files, databases, web services, and text files or create new layers:

Finally, on the right screen border, there are two more toolbars:

  • Digitizing: The tools in this toolbar enable editing, basic feature creation, and editing
  • Advanced Digitizing: This toolbar contains the Undo/Redo option, advanced editing tools, the geometry-simplification tool, and so on, which look like this:

1.2.3 Settings

1.2.3.1 Toolbars and panels

Toolbars and panels can be activated and deactivated via the View menu’s Panels and Toolbars entries, as well as by right-clicking on a menu or toolbar, which will open a context menu with all the available toolbars and panels. All the tools on the toolbars can also be accessed via the menu. If you deactivate the Manage Layers Toolbar, for example, you will still be able to add layers using the Layer menu.

As you might have guessed by now, QGIS is highly customizable. You can increase your productivity by assigning shortcuts to the tools you use regularly, which you can do by going to Settings | Configure Shortcuts. Similarly, if you realize that you never use a certain toolbar button or menu entry, you can hide it by going to Settings | Customization. For example, if you don’t have access to an Oracle Spatial database, you might want to hide the associated buttons to remove clutter and save screen estate, as shown in the following screenshot:

1.2.3.2 Projection and Coordinate Reference System (CRS)

Projections define how real-world objects on the curved surface of the earth will be flattened and projected on a map-like planar surface. Different data sources are usually created and distributed in different projections, depending on acquisition techniques and the scope of application. To be able to manipulate and analyze them properly in QGIS, it is important to understand how it interprets and manages information about projections.

QGIS supports about 2,700 CRS. They constitute a database, each item of which is described by an ESPG identifier, and a description line in the format of the PROJ.4 projection library. To store and read information about projection, QGIS uses its own format stored in .qpj files. There are two important points to keep in mind while working with projections: a data source projection and project projection—which are not always the same.

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.

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.
Enabling on-the-fly CRS projection

Figure 1.32: Enabling on-the-fly CRS projection

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

1.3 QGIS Plugins

To begin using plugins, you need to know how to download, install and activate them. To do this, you will learn how to use the Plugin Installer and Plugin Manager.

The goal for this lesson: To understand and use QGIS’ plugin system.

1.3.1 Installing and managing Plugins

1.3.1.1 Follow along: Managing Plugins

  • To open the Plugin Manager, click on the menu item Plugins → Manage and Install Plugins.

  • In the dialog that opens, find the Processing plugin:

  • Click in the box next to this plugin and uncheck it to uninstall it.

Processing plugin

Figure 1.33: Processing plugin

  • Click Close.

  • Looking at the menu, you will notice that the Processing menu is now gone. This means that many of the processing functions you have been using before have disappeared! This is because they are part of the Processing plugin, which needs to be activated for you to use them.

  • Open the Plugin Manager again and reactivate the Processing plugin by clicking in the checkbox next to it and clicking Close..

  • The Processing menu should be available again.

1.3.1.2 Follow along: Installing new plugins

The list of plugins that you can activate and deactivate draws from the plugins that you currently have installed.

  • To install new plugins, select the Not Installed option in the Plugin Manager dialog. The plugins available for you to install will be listed here. This list will vary depending on your existing system setup.

  • You can find information about each plugin by selecting it in the list of plugins displayed.

  • A plugin can be installed by clicking the Install Plugin button below the plugin information panel.

1.3.2 Useful plugins

1.3.2.1 The Raster Terrain Analyses Plugin

Raster Terrain Analyses Plugin is not yet available in QGIS 3. Therefore, please use QGIS 2.18 for practice.

  • Start a new map with only srtm_58_09.tif (look in folder Laos/TIFF/SRTM). You used GDAL tools (accessible via Raster –> Analysis) for this. However, you should also know about the Raster Terrain Analysis plugin. This ships standard with newer versions of QGIS, and so you don’t need to install it separately.

  • Open the Plugin Manager and check that the Raster Terrain Analysis plugin is enabled

Checking Raster Terrain Analysis plugin

Figure 1.34: Checking Raster Terrain Analysis plugin

  • Open the Raster menu. You should see a Terrain analysis submenu.

  • Click on Terrain analysis -> Relief and input the following options

Relief analysis

Figure 1.35: Relief analysis

  • Save the new file under Laos/plugins/relief.tif (create a new folder if necessary).

  • Leave the Output format and Z factor unchanged.

  • Make sure the Add result to project box is checked.

  • Click the Create automatically button. The list below will be populated:

Relief colors

Figure 1.36: Relief colors

  • These are the colors that the plugin will use to create the relief.
  • If you like, you can change these colors by double-clicking on each row’s color bar.

1.3.2.2 The OpenLayers Plugin

OpenLayers Plugin is not yet available in QGIS 3, use QGIS 2.18 instead to try the plugin.

  • Open the Plugin Manager

  • Search __OpenLayers_ plugin

  • Click Install to begin

Installing OpenLayers plugin

Figure 1.37: Installing OpenLayers plugin

  • Test the plugin by selecting Web -> OpenLayers plugin -> OpenStreetMap -> OpenStreetMap
Selecting OpenLayers plugin

Figure 1.38: Selecting OpenLayers plugin

OpenStreetMap layer

Figure 1.39: OpenStreetMap layer

1.3.2.3 The QuickMapService Plugin

QuickMapService plugin has similar functionalities with OpenLayers plugin. The difference is that this plugin is available in QGIS 3 and has more services than OpenLayers plugin.

  • Open the Plugin Manager

  • Search QuickMapService plugin

  • Click Install to begin

Installing QuickMapService plugin

Figure 1.40: Installing QuickMapService plugin

  • Add more services to the plugin by clicking Web -> QuickMapServices -> Settings. Open tab More services and click Get contributed pack
Adding more services to the plugin

Figure 1.41: Adding more services to the plugin

More services installed

Figure 1.42: More services installed

  • Test the plugin by adding ESRI Satellite layer
Adding ESRI Satellite to the display

Figure 1.43: Adding ESRI Satellite to the display

ESRI Satellite in QGIS display

Figure 1.44: ESRI Satellite in QGIS display

1.3.2.4 Other useful plugin

There are more than 700 plugins available for QGIS 2. You can search at the Repository, any plugin that maybe useful for your project. Try to select and install it. If the installed plugin doesn’t suit your needs, you can easily uninstall it.