Chapter 3. QGIS: Exploring PyQGIS and Native Algorithms for Spatial Analytics

In this chapter, we will continue to focus on QGIS as you level up your skills with Python and QGIS. These are foundational concepts, and learning them will be critical to future geospatial analysis skills, including spatial algorithms, data engineering, prediction modeling and forecasting, and machine learning.

The QGIS integration of Python is called PyQGIS, a Python API that uses defined protocols and customization to automate workflows. Automation is important when running large scripts or building applications. The integration with an API allows you access to a large variety of datasets for exploration and analysis. You can create, modify, and query digital objects of interest that represent features in the real world.

PyQGIS is a wrapper around the underlying C++ library. All the methods and class variables implemented by the C++ version of QgisInterface are made available through the Python wrapper. PyQGIS classes target functionality within QGIS. You do not need a separate installation of Python because it is installed with QGIS directly into your system.

Python is an object-oriented programming language. You can think of objects as chunks of data (attributes) and behaviors (methods). In Python, objects also include functions. Attributes can be either data or functions. Methods are also attributes, which means you can store them in variables, just like any other attribute. A Python class describes ...

Get Python for Geospatial Data Analysis now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.