Chapter 1 Setting-up QGIS Environment
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.
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.
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.
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.
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.)
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.
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.
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.)
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
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.
- 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
- 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.
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.
- 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
- 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.
- Now you should update the apt package repository cache of Ubuntu 18.04 Bionic Beaver with the following command:
$ sudo apt-get update
- 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.
- 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.
1.1.3 Installing QGIS on Mac OS X
The general steps to install QGIS on a Mac are as follow:
As an initial step, it is often necessary to change your Mac security preferences to Allow apps downloaded from: Anywhere.
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.
220.127.116.11 QGIS LR installation on Mac OS X
The steps to install QGIS LR (QGIS 3) on Mac OS X are as follows:
- Download Python 3.6.5 from https://www.python.org/ftp/python/3.6.5/python-3.6.5-macosx10.6.pkg
- 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 :
- Install QGIS 3
QGIS 3 disk image installation file consists of numbered files for showing the sequence of the installation.
The first file is a text file that contain the instruction to install Python 3.6, it was already explained in the previous section.
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:
The next step is QGIS installation. Like the previous installation, follow the sequence of installation and accept the default options to install QGIS.
QGIS 3 for Mac can be started by double-clicking the icon in /Applications/QGIS3
18.104.22.168 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 for Mac can be started by double-clicking the icon in /Applications/QGIS
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.
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:
22.214.171.124 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:
126.96.36.199 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:
- Click on Project Properties under Project.
- Choose the CRS tab and Enable ‘on the fly’ CRS transformation.
- 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:
Open the layer’s properties by either navigating to Layer | Properties or by right-clicking on the layer in the Layers panel.
Choose Properties from the context menu and then choose the General tab.
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:
Right-click on the layer in the Layers panel and then choose Save As from the context menu.
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:
Click on Custom CRS under Settings to open the Custom Coordinate Reference System Definition window.
Click on the Add new CRS button to add a new entry to the CRS list.
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
188.8.131.52 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.
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.
184.108.40.206 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
220.127.116.11 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
Open the Raster menu. You should see a Terrain analysis submenu.
Click on Terrain analysis -> Relief and input the following options
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:
- 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.
18.104.22.168 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
- Test the plugin by selecting Web -> OpenLayers plugin -> OpenStreetMap -> OpenStreetMap
22.214.171.124 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
- Add more services to the plugin by clicking Web -> QuickMapServices -> Settings. Open tab More services and click Get contributed pack
- Test the plugin by adding ESRI Satellite layer
126.96.36.199 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.