Book Image

Mastering Geospatial Development with QGIS 3.x - Third Edition

By : Shammunul Islam, Simon Miles, Kurt Menke, GISP, Richard Smith Jr., GISP, Luigi Pirelli, John Van Hoesen, GISP
Book Image

Mastering Geospatial Development with QGIS 3.x - Third Edition

By: Shammunul Islam, Simon Miles, Kurt Menke, GISP, Richard Smith Jr., GISP, Luigi Pirelli, John Van Hoesen, GISP

Overview of this book

QGIS is an open source solution to GIS and widely used by GIS professionals all over the world. It is the leading alternative to 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 and getting you acquainted with the latest QGIS 3.6 updates, this book will take you all the way through to teaching you how to create a spatial database and a GeoPackage. Next, you will learn how to style raster and vector data by choosing and managing different colors. The book will then focus on processing raster and vector data. You will be then taught advanced applications, such as creating and editing vector data. Along with that, you will also learn about the newly updated Processing Toolbox, which will help you develop the advanced data visualizations. The book will then explain to you the graphic modeler, how to create QGIS plugins with PyQGIS, and how to integrate Python analysis scripts with QGIS. By the end of the book, you will understand how to work with all aspects of QGIS and will be ready to use it for any type of GIS work.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

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 edit mode, the digitizing toolbar (shown in the following screenshot) can be used to add, delete, and modify features:

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 Vertex 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.
  • Modify the attributes of all selected features simultaneously, which allows you to set a value for all the selected features:
  • Features can be deleted, cut, copied, and pasted using the Delete Selected, Cut Features, Copy Features, and Paste Features tools.

Snapping

As of version 3 of QGIS, how snapping is carried out has changed. Snapping is a specified distance (tolerance) within which vertices of one feature will automatically align with vertices of another feature. Once enabled, users can set which layers are to be used to snap against; if vertex, vertex and segments, or just segments, are to be snapped against; and the distance from which snapping will occur. Additional topological and tracing functions have been added to further enhance the snapping toolset:

 

Styling vector data

When you load spatial data layers into QGIS Desktop, they are styled with a random single symbol rendering. To change this, right-mouse click on the layer and choose properties, and, in the context menu, click on Symbology.

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.
  • Point Cluster: This option groups clusters of points together at a specified distance. This will be covered more in later chapters.
  • 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.5D: This allows you to extrude data into a 2.5D space. A common use case is to extrude building footprints upward, creating an almost 3D rendering.

The following screenshot shows the symbology properties available for a vector line layer:

 

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 / Unique values: 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.
  • Hillshade: Used mainly against Digital Terrain Data, this function allows to you add hillshade relief to the layer by changing the angles/direction of sunlight.

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

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 which 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 in the Symbology menu under Layer Properties in the Layer Rendering section (for vectors) and Color rendering section (for rasters).