Book description
Master over 170 recipes that will help you turn QGIS from a desktop GIS tool into a powerful automated geospatial framework
About This Book
Delve into the undocumented features of the QGIS API
Get a set of user-friendly recipes that can automate entire geospatial workflows by connecting Python GIS building blocks into comprehensive processes
This book has a complete code upgrade to QGIS 2.18 and 30 new, valuable recipes
Who This Book Is For
This book is for geospatial analysts who want to learn more about automating everyday GIS tasks as well as programmers responsible for building GIS applications. The short, reusable recipes make concepts easy to understand and combine so you can build larger applications that are easy to maintain.
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
In Detail
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.
Style and approach
This book follows a recipe-based problem-solution approach to address and dispel challenges faced when implementing and using QGIS on a regular basis.
Table of contents
-
QGIS Python Programming Cookbook - Second Edition
- QGIS Python Programming Cookbook - Second Edition
- Credits
- About the Author
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Preface
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
Product information
- Title: QGIS Python Programming Cookbook - Second Edition
- Author(s):
- Release date: March 2017
- Publisher(s): Packt Publishing
- ISBN: 9781787124837
You might also like
book
Qt5 Python GUI Programming Cookbook
Over 60 recipes to help you design interactive, smart, and cross-platform GUI applications Key Features Get …
book
Python Geospatial Analysis Cookbook
Over 60 recipes to work with topology, overlays, indoor routing, and web application analysis with Python …
book
Python Image Processing Cookbook
Explore Keras, scikit-image, open source computer vision (OpenCV), Matplotlib, and a wide range of other Python …
book
Learning Geospatial Analysis with Python - Second Edition
An effective guide to geographic information systems and remote sensing analysis using Python 3 About This …