Book Image

QGIS Python Programming Cookbook, Second Edition - Second Edition

By : Joel Lawhead
Book Image

QGIS Python Programming Cookbook, Second Edition - Second Edition

By: Joel Lawhead

Overview of this book

QGIS is a desktop geographic information system that facilitates data viewing, editing, and analysis. Paired with the most efficient scripting language—Python, we can 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 geoprocessing tasks in QGIS. It will cover 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, reproject 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.
Table of Contents (16 chapters)
QGIS Python Programming Cookbook - Second Edition
About the Author
About the Reviewer
Customer Feedback

Accessing layer metadata

Layer metadata is, by definition, data about the layer. Metadata includes information such as the extents of the layer, the coordinate reference system (CRS), the number of features, the data source, and much more. Metadata is an important tool for GIS analysts to understand a dataset. QGIS also uses metadata to properly configure the map, run queries, and perform other management functions. Metadata such as the extents and number of features can be extracted automatically from the data. Other metadata such as the CRS, source, and production methods must be added by the person or software that generates the data. PyQGIS has a method to return layer metadata as an HTML document. To programmatically extract a single metadata attribute, you must parse the HTML. In this recipe, you'll extract the layer capabilities from a layer, which tell you if the layer can be edited within PyQGIS. Although there are dozens of ways to parse HTML in Python, you will use some simple...