QGIS Python Programming Cookbook - Second Edition

Master over 170 recipes that will help you turn QGIS from a desktop GIS tool into a powerful automated geospatial framework
Preview in Mapt

QGIS Python Programming Cookbook - Second Edition

Joel Lawhead

Master over 170 recipes that will help you turn QGIS from a desktop GIS tool into a powerful automated geospatial framework

Quick links: > What will you learn?> Table of content

Mapt Subscription
FREE
$29.99/m after trial
eBook
$28.00
RRP $39.99
Save 29%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$28.00
$49.99
$29.99 p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 14 Day Trial

Frequently bought together


QGIS Python Programming Cookbook - Second Edition Book Cover
QGIS Python Programming Cookbook - Second Edition
$ 39.99
$ 28.00
QGIS:Becoming a GIS Power User Book Cover
QGIS:Becoming a GIS Power User
$ 67.99
$ 47.60
Buy 2 for $35.00
Save $72.98
Add to Cart

Book Details

ISBN 139781787124837
Paperback464 pages

Book Description

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

Chapter 1: Automating QGIS
Introduction
Installing QGIS 2.18 for development
Using the QGIS Python console for interactive control
Automatically starting the Python console
Using the Python's Script Runner plugin
Setting up your QGIS IDE
Debugging QGIS Python scripts
Navigating the PyQGIS API
Creating a traditional QGIS plugin
Creating a Processing Toolbox plugin
Distributing a plugin
Building a standalone application
Storing and reading global preferences
Storing and reading project preferences
Accessing the script path from within your script
Chapter 2: Querying Vector Data
Introduction
Loading a vector layer from a file sample
Loading a vector layer from a geodatabase
Examining vector layer features
Examining vector layer attributes
Filtering a layer by geometry
Filtering a layer by attributes
Buffering a feature
Measuring the distance between two points
Measuring distance along a line
Calculating the area of a polygon
Creating a spatial index
Calculating the bearing of a line
Loading data from a spreadsheet
Accessing layer metadata
Chapter 3: Editing Vector Data
Introduction
Creating a vector layer in memory
Adding a point feature to a vector layer
Adding a line feature to a vector layer
Adding a polygon feature to a vector layer
Adding a set of attributes to a vector layer
Adding a field to a vector layer
Joining a shapefile attribute table to a CSV file
Changing vector layer geometry
Changing a vector layer feature's attribute
Removing data from a vector layer
Deleting a vector layer feature's attribute
Reprojecting a vector layer
Converting a shapefile to KML or GeoJSON
Merging shapefiles
Splitting a shapefile
Generalizing a vector layer
Dissolving vector features
Performing a union on vector shapes
Rasterizing a vector layer
Exporting a layer to the GeoPackage format
Chapter 4: Using Raster Data
Introduction
Loading a raster layer
Loading a NetCDF file
Getting the cell size of a raster layer
Obtaining the width and height of a raster
Counting raster bands
Swapping raster bands
Querying the value of a raster at a specified point
Reprojecting a raster
Creating an elevation hillshade
Creating vector contours from elevation data
Sampling a raster dataset using a regular grid
Adding elevation data to a line vertices using a digital elevation model
Creating a common extent for rasters
Resampling raster resolution
Counting the unique values in a raster
Mosaicing rasters
Converting a TIFF image to a JPEG image
Creating pyramids for a raster
Converting a pixel location to a map coordinate
Converting a map coordinate to a pixel location
Creating a KML image overlay for a raster
Classifying a raster
Converting a raster to a vector
Georeferencing a raster from control points
Clipping a raster using a shapefile
Chapter 5: Creating Dynamic Maps
Introduction
Accessing the map canvas
Changing the map units
Iterating over layers
Symbolizing a vector layer
Setting a transparent layer fill
Using a filled marker symbol
Rendering a single band raster using a color ramp algorithm
Setting a feature's color using a column in a CSV file
Creating a complex vector layer symbol
Using icons as vector layer symbols
Using an outline for font markers
Using arrow symbols
Creating a graduated vector layer symbol renderer
Creating a categorized vector layer symbol
Using live layer effects
Creating inverted polygon shapeburst fills
Creating a map bookmark
Navigating to a map bookmark
Setting scale-based visibility for a layer
Using SVG for layer symbols
Using pie charts for symbols
Using the 2.5D renderer
Using XYZ tiled map services
Using Esri ArcGIS map services
Labeling a feature
Using null symbols
Change map layer transparency
Adding standard map tools to the canvas
Using a map tool to draw points on the canvas
Using a map tool to draw polygons or lines on the canvas
Building a custom selection tool
Creating a mouse coordinate tracking tool
Chapter 6: Composing Static Maps
Introduction
Creating the simplest map renderer
Using the Map Composer
Adding labels to a map for printing
Adding a scale bar to a map
Adding a North arrow to the map
Adding a logo to the map
Adding a vertical legend to the map
Adding a horizontal legend
Adding a custom shape to the map
Adding a grid to the map
Adding a table to the map
Adding a world file to a map image
Saving a map to a project
Loading a map from a project
Chapter 7: Interacting with the User
Introduction
Using log files
Creating a simple message dialog
Creating a warning dialog
Creating an error dialog
Displaying a progress bar
Creating a simple text input dialog
Creating a file input dialog
Creating a combobox
Creating radio buttons
Creating checkboxes
Creating a dock widget
Displaying a message in the status bar
Pushing messages to the message bar
Pushing widgets to the message bar
Creating tabs
Stepping the user through a wizard
Keeping dialogs on top
Chapter 8: QGIS Workflows
Introduction
Creating an NDVI
Geocoding addresses
Creating raster footprints
Performing network analysis
Routing along streets
Tracking a GPS
Creating a mapbook
Finding the least cost path
Performing nearest neighbor analysis
Creating a DEM from LIDAR
Creating a heat map
Creating a dot density map
Collecting field data
Computing road slope using elevation data
Geolocating photos on the map
Image change detection
Adjusting imprecise building footprints
Visualizing multitemporal data
Chapter 9: Other Tips and Tricks
Introduction
Creating tiles from a QGIS map
Adding a layer to geojson.io
Rendering map layers based on rules
Creating a layer-definition file
Using NULL values in PyQGIS
Using generators for layer queries
Using alpha values to show data density
Using the __geo_interface__ protocol
Getting the output file names from processing algorithms
Generating points along a line
Using expression-based labels
Creating dynamic forms in QGIS
Calculating length for all selected lines
Using a different status bar CRS than the map
Creating HTML labels in QGIS
Using OpenStreetMap points of interest in QGIS
Changing the QGIS web proxy
Running QGIS scripts as scheduled tasks
Visualizing data in 3D with WebGL
Visualizing data on a globe
Make a globe-like azimuthal orthographic projection
Animating a layer

What You Will Learn

  • Use Python and QGIS to produce captivating GIS visualizations and build complex map layouts
  • Find out how to effectively use the poorly-documented and undocumented features of the QGIS Python API
  • Automate entire geospatial workflows by connecting Python GIS building blocks into comprehensive processes
  • Create, import, and edit geospatial data on disk or in-memory
  • Change QGIS settings programmatically to control default behavior 
  • Automatically generate PDF map books 
  • Build dynamic forms for field input

Authors

Table of Contents

Chapter 1: Automating QGIS
Introduction
Installing QGIS 2.18 for development
Using the QGIS Python console for interactive control
Automatically starting the Python console
Using the Python's Script Runner plugin
Setting up your QGIS IDE
Debugging QGIS Python scripts
Navigating the PyQGIS API
Creating a traditional QGIS plugin
Creating a Processing Toolbox plugin
Distributing a plugin
Building a standalone application
Storing and reading global preferences
Storing and reading project preferences
Accessing the script path from within your script
Chapter 2: Querying Vector Data
Introduction
Loading a vector layer from a file sample
Loading a vector layer from a geodatabase
Examining vector layer features
Examining vector layer attributes
Filtering a layer by geometry
Filtering a layer by attributes
Buffering a feature
Measuring the distance between two points
Measuring distance along a line
Calculating the area of a polygon
Creating a spatial index
Calculating the bearing of a line
Loading data from a spreadsheet
Accessing layer metadata
Chapter 3: Editing Vector Data
Introduction
Creating a vector layer in memory
Adding a point feature to a vector layer
Adding a line feature to a vector layer
Adding a polygon feature to a vector layer
Adding a set of attributes to a vector layer
Adding a field to a vector layer
Joining a shapefile attribute table to a CSV file
Changing vector layer geometry
Changing a vector layer feature's attribute
Removing data from a vector layer
Deleting a vector layer feature's attribute
Reprojecting a vector layer
Converting a shapefile to KML or GeoJSON
Merging shapefiles
Splitting a shapefile
Generalizing a vector layer
Dissolving vector features
Performing a union on vector shapes
Rasterizing a vector layer
Exporting a layer to the GeoPackage format
Chapter 4: Using Raster Data
Introduction
Loading a raster layer
Loading a NetCDF file
Getting the cell size of a raster layer
Obtaining the width and height of a raster
Counting raster bands
Swapping raster bands
Querying the value of a raster at a specified point
Reprojecting a raster
Creating an elevation hillshade
Creating vector contours from elevation data
Sampling a raster dataset using a regular grid
Adding elevation data to a line vertices using a digital elevation model
Creating a common extent for rasters
Resampling raster resolution
Counting the unique values in a raster
Mosaicing rasters
Converting a TIFF image to a JPEG image
Creating pyramids for a raster
Converting a pixel location to a map coordinate
Converting a map coordinate to a pixel location
Creating a KML image overlay for a raster
Classifying a raster
Converting a raster to a vector
Georeferencing a raster from control points
Clipping a raster using a shapefile
Chapter 5: Creating Dynamic Maps
Introduction
Accessing the map canvas
Changing the map units
Iterating over layers
Symbolizing a vector layer
Setting a transparent layer fill
Using a filled marker symbol
Rendering a single band raster using a color ramp algorithm
Setting a feature's color using a column in a CSV file
Creating a complex vector layer symbol
Using icons as vector layer symbols
Using an outline for font markers
Using arrow symbols
Creating a graduated vector layer symbol renderer
Creating a categorized vector layer symbol
Using live layer effects
Creating inverted polygon shapeburst fills
Creating a map bookmark
Navigating to a map bookmark
Setting scale-based visibility for a layer
Using SVG for layer symbols
Using pie charts for symbols
Using the 2.5D renderer
Using XYZ tiled map services
Using Esri ArcGIS map services
Labeling a feature
Using null symbols
Change map layer transparency
Adding standard map tools to the canvas
Using a map tool to draw points on the canvas
Using a map tool to draw polygons or lines on the canvas
Building a custom selection tool
Creating a mouse coordinate tracking tool
Chapter 6: Composing Static Maps
Introduction
Creating the simplest map renderer
Using the Map Composer
Adding labels to a map for printing
Adding a scale bar to a map
Adding a North arrow to the map
Adding a logo to the map
Adding a vertical legend to the map
Adding a horizontal legend
Adding a custom shape to the map
Adding a grid to the map
Adding a table to the map
Adding a world file to a map image
Saving a map to a project
Loading a map from a project
Chapter 7: Interacting with the User
Introduction
Using log files
Creating a simple message dialog
Creating a warning dialog
Creating an error dialog
Displaying a progress bar
Creating a simple text input dialog
Creating a file input dialog
Creating a combobox
Creating radio buttons
Creating checkboxes
Creating a dock widget
Displaying a message in the status bar
Pushing messages to the message bar
Pushing widgets to the message bar
Creating tabs
Stepping the user through a wizard
Keeping dialogs on top
Chapter 8: QGIS Workflows
Introduction
Creating an NDVI
Geocoding addresses
Creating raster footprints
Performing network analysis
Routing along streets
Tracking a GPS
Creating a mapbook
Finding the least cost path
Performing nearest neighbor analysis
Creating a DEM from LIDAR
Creating a heat map
Creating a dot density map
Collecting field data
Computing road slope using elevation data
Geolocating photos on the map
Image change detection
Adjusting imprecise building footprints
Visualizing multitemporal data
Chapter 9: Other Tips and Tricks
Introduction
Creating tiles from a QGIS map
Adding a layer to geojson.io
Rendering map layers based on rules
Creating a layer-definition file
Using NULL values in PyQGIS
Using generators for layer queries
Using alpha values to show data density
Using the __geo_interface__ protocol
Getting the output file names from processing algorithms
Generating points along a line
Using expression-based labels
Creating dynamic forms in QGIS
Calculating length for all selected lines
Using a different status bar CRS than the map
Creating HTML labels in QGIS
Using OpenStreetMap points of interest in QGIS
Changing the QGIS web proxy
Running QGIS scripts as scheduled tasks
Visualizing data in 3D with WebGL
Visualizing data on a globe
Make a globe-like azimuthal orthographic projection
Animating a layer

Book Details

ISBN 139781787124837
Paperback464 pages
Read More

Read More Reviews

Recommended for You

QGIS:Becoming a GIS Power User Book Cover
QGIS:Becoming a GIS Power User
$ 67.99
$ 47.60
Learning Geospatial Analysis with Python Book Cover
Learning Geospatial Analysis with Python
$ 29.99
$ 21.00
QGIS Python Programming Cookbook Book Cover
QGIS Python Programming Cookbook
$ 39.99
$ 28.00
QGIS 2 Cookbook Book Cover
QGIS 2 Cookbook
$ 39.99
$ 28.00
PostGIS Cookbook Book Cover
PostGIS Cookbook
$ 29.99
$ 21.00
ArcPy and ArcGIS - Second Edition Book Cover
ArcPy and ArcGIS - Second Edition
$ 39.99
$ 28.00