Book Image

Mastering QGIS - Second Edition

By : Kurt Menke, GISP, Paolo Corti, Richard Smith Jr., GISP, Luigi Pirelli, John Van Hoesen, GISP
Book Image

Mastering QGIS - Second Edition

By: Kurt Menke, GISP, Paolo Corti, Richard Smith Jr., GISP, Luigi Pirelli, John Van Hoesen, GISP

Overview of this book

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.
Table of Contents (19 chapters)
Mastering QGIS - Second Edition
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

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:

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.

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.