QGIS is a desktop geographic information system that facilitates data viewing, editing, and analysis. QGIS, paired with the most efficient scripting language, Python, enables us to write effective scripts that extend the core functionality of QGIS. Based on version QGIS 2.18, this book will teach you how to write Python code that works with spatial data to automate geo-processing tasks in QGIS. It covers topics such as querying and editing vector data and using raster data. You will also learn to create, edit, and optimize a vector layer for faster queries, re-project a vector layer, reduce the number of vertices in a vector layer without losing critical data, and convert a raster to a vector. Following this, you will work through recipes that will help you compose static maps, create heavily customized maps, and add specialized labels and annotations. As well as this, we’ll also share a few tips and tricks based on different aspects of QGIS.
About the Author
Joel Lawhead is a PMI-certified Project Management Professional (PMP), a certified Geographic Information Systems Professional, and the Chief Information Officer (CIO) for , an award-winning firm specializing in geospatial technology integration and harsh-environment engineering. Joel builds geospatial systems for US government agencies, including NASA, NOAA, the US Department of Homeland Security, and the military. He also works with private organizations, including the National Oceans and Applications Research Center (NOARC) and The Ocean Cleanup. He has authored other books with Packt Publishing, including Learning Geospatial Analysis with Python, QGIS Python Programming Cookbook, and Learning Geospatial Analysis with Python, Second Edition. His cookbook recipes have been featured in two editions of the O’Reilly Python Cookbook.
Joel began using Python in 1997 and combined it with geospatial software development in 2000. He is also the developer of the widely used open source Python Shapefile Library (PyShp) and maintains the geospatial technical blog, and Twitter feed, @SpatialPython, discussing the use of Python within the geospatial industry.
In 2011, Joel reverse-engineered and published the undocumented shapefile spatial indexing format and assisted fellow geospatial Python developer, Marc Pfister, in reversing the compression algorithm, allowing developers around the world to create better integrated and more robust geospatial applications involving shapefiles.
In 2002, Joel received the international Esri Special Achievement in GIS award for his work on the Real-Time Emergency Action Coordination Tool (REACT) for emergency management using geospatial analysis.
QGIS needs to be installed properly for working on it. This video will help you do that.
The Python console is an interactive platform used for automation.
In order to have the Python console always available, we will go through this video.
The QGIS Python Script Runner plugin provides a middle ground for QGIS automation between the interactive console and the overhead of plugins.
QGIS IDE has advanced debugging tools and is very useful.
Debugging programs that have processes in the foreground and background can be extremely difficult. This interactive debugging approach of QGIS makes the development of complex applications efficient.
PyQGIS allows you to control virtually every aspect of QGIS. This video helps you to do that.
Plugins are the best way to extend QGIS, as they can be easily updated and reused by other people. We will create a plugin in this video.
The QGIS Processing Toolbox provides a powerful set of algorithms for QGIS Python Programming. Creating a plugin will help in easing the process.
PyQGIS allows you to store application-level preferences and retrieve them. QGIS also has project-level preferences, which can override the application-level preferences in some cases. We will learn how to work with them in this video.
Sometimes, you need to know exactly where the current working directory is so that you can access external resources. Accessing the script will enable that.
Vector data stored in a local file is one of the most common geospatial data formats. We need to learn how to load the vector sample from a file.
The geodatabase provides powerful geospatial data management and operations. Hence it is important to learn about how to load a layer from a geodatabase.
Once a vector layer is loaded, you may want to investigate the data. A true GIS layer contains both spatial geometry and non-spatial attributes. So we are going to examine vector layer attributes and features in this video.
In this video, we'll perform a spatial operation to select the subset of a point layer based on the points contained in an overlapping polygon layer.
In addition to the spatial queries outlined previously, we can also subset a layer by its attributes. You will do that in this video.
Buffering a feature creates a polygon around a feature as a selection geometry or just a simple visualization.
In the QgsDistanceArea object, PyQGIS has excellent capabilities for measuring the distance. We'll use this object measuring the distance between two points and along a line with multiple vertices.
Area calculation can be an end in itself to measure the size of a plot of land or a building. It can also be the input to other calculations such as land use maps. This video measures the area of a polygon.
A spatial index optimizes a layer for spatial queries by creating additional simpler geometries that can be used to narrow down the field of possibilities within the complex geometry. So let’s use that instead of geometry.
Sometimes, you need to know the compass bearing of a line to create specialized symbology or to use as input in a spatial calculation. In this video, we'll calculate the bearing of the end points of a line.
Spreadsheets are one of the most common methods used to collect and store simple geographic data. So, it is very important to know how to load data from a spreadsheet.
Metadata is an important tool for GIS analysts to understand a dataset. In this video, you'll extract the layer capabilities from a layer.
Sometimes you need to create a temporary dataset for a quick output, or as an intermediate step in a more complex operation without the overhead of actually writing a file to disk. You will learn just that in this video.
The simplest editing that can be done to a vector is adding a point feature. You will learn that in this video.
Previously we added a point feature to a vector layer. Taking this a step further, adding a line feature is adding more points.
A polygon is the most complex kind of geometry; however, in QGIS the API is very similar to a line. When you add a new attribute, the attribute value for all existing features are set to NULL for that field index. We will add polygon, field and other attributes.
Joining attribute tables to other database tables allows you to use a spatial data set to reference a dataset without any geometry, using a common key between the data tables. Hence we will learn to do that in this video.
To change the location and attribute of a feature PyQGIS provides a simple way. Learning that is important
In this video we will remove features, attributes with features and reproject a vector layer using the Processign toolbox.
Files in the KML or GeoJSON format are better to work with than shapefiles. Therefore, it is a good practice to convert them to these file formats.
Merging datafiles with similar attributes and features leads to efficient use of memory. Alao sometimes it is necessary to split large datasets for ease of operation. Thus we will learn merging and splitting in this video.
Generalization removes points from vector layer and reduces space.
Dissolving helps in creating a single layer with common attributes.
A union combines two overlapping vector shapes into one.
A raster dataset is sometimes more efficient way of displaying data in the backdrop.
The GeoPackage format has the properties of both the file format and a geodatabase. It overcomes all the limitations of the shapefile format, such as file size limits, attribute name length limits, and many other inconveniences. Thus, we can use it in our videos.
To use QGSRasterLayer API, we need to load a layer into QGIS. In this way we can work on the layer without adding it to the map.
NetCDF stands for Network Common Data Form and is an open geospatial and scientific data format. Features of the format include machine-independent data storage, the ability to store vector, raster, and statistical data, as well as multi-dimensional data, and widespread software read and write support.
The first key element of a geospatial raster is the width and height in pixels. The second key element is the ground distance of each pixel, also called the pixel size. We need to find both these values to work with a raster.
Bands represent layers of information within a raster. Hence it is important to count them and also sometimes necessary to swap them to recombine bands to change RGB values.
A common remote sensing operation is to get a raster value at a specified co-ordinate. In this video, we will calculate that.
You can change the map projection of data to allow different layers to be displayed on the same map. Reprojection is required for that.
A hillshade, or shaded relief, is a technique to visualize elevation data in order to make it Photo-realistic for presentation as a map. In this video, we will create an elevation hillshade.
Contours provide an effective visualization of terrain data by tracing isolines along the same elevation to form a loop at set intervals in the dataset. So we will use the elevation data to create contours.
Sometimes, you need to sample a raster dataset at regular intervals in order to provide summary statistics or for quality assurance purposes on the raster data. A common way to accomplish this regular sampling is to create a point grid over the dataset, query the grid at each point, and assign the results as attributes to those points.
If you have a transportation route through some terrain, it is useful to know the elevation profile of that route. This operation is accomplished in this video.
If you are trying to compare two raster images, it is important that they have the same extent and resolution. We are going to create a common extent for rasters in this video.
Resampling an image allows you to change the current resolution of an image to a different resolution.
The ability to run statistical algorithms on a dataset is the key to remote sensing. Mosaicking rasters is the process of fusing multiple geospatial images with the same resolution and map projection into one raster. In this video, we will count the number of unique combinations of pixels across multiple bands. And combine two overlapping images into a single dataset.
Image format conversion is a part of nearly every geospatial project. Hence it is important to learn how to do it.
Pyramids, or overview images, sacrifice the disk space for map rendering speed by storing resampled, lower-resolution versions of images in the file alongside the full-resolution image. Thus it is essential to know how to create a pyramid.
The ability to view rasters in a geospatial context relies on the conversion of pixel locations to coordinates on the ground. Similarly, when you receive a map coordinate as user input or from some other source, you must be able to convert it back to the appropriate pixel location on a raster. This video will enable you to do both things.
The XML data format used by Google Earth for geospatial data is called KML. Converting rasters into a KML overlay compressed in a KMZ archive file is a very popular way to make data available to end users who know how to use Google Earth.
Raster datasets represent real-world features efficiently, but can have limited usage for geospatial analysis. Once you have classified an image into a manageable data set, you can convert those raster classes into a vector data set.
Sometimes, a raster that represents features on the earth is just an image with no georeferencing information. Each change to an image holds the possibility of losing data, so georeferencing an image on demand is often the best approach.
Sometimes, you need to use a subset of an image which covers an area of interest for a project. Clipping a raster to a vector boundary allows you to only use the portions of the raster you need.
Packt has been committed to developer learning since 2004. A lot has changed in software since then - but Packt has remained responsive to these changes, continuing to look forward at the trends and tools defining the way we work and live. And how to put them to work.
With an extensive library of content - more than 4000 books and video courses -Packt's mission is to help developers stay relevant in a rapidly changing world. From new web frameworks and programming languages, to cutting edge data analytics, and DevOps, Packt takes software professionals in every field to what's important to them now.
From skills that will help you to develop and future proof your career to immediate solutions to every day tech challenges, Packt is a go-to resource to make you a better, smarter developer.
Packt Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.