Learning resources for PyQGIS?
The following documentation resources should ease your PyQGIS development experience:
A diagram of the main PyQGIS relationships (by Thomas Gratier): https://raw.githubusercontent.com/webgeodatavore/qgis-class-diagram/master/diagramme_principal.png
Searchable documentation of PyQGIS classes (by SourcePole): http://geoapis.sourcepole.com
For example, the addFeature
method you had problems with is described here:
http://geoapis.sourcepole.com/qgispyapi/qgsvectorlayer#QgsVectorLayer.addFeature
As a second example, the setAttribute
method is described here:
http://geoapis.sourcepole.com/qgispyapi/qgsfeature#QgsFeature.setAttribute
The following resources give a general guidance for learning or using PyQGIS and generally assume a minimum proficiency of working with Python.
QGIS 3.x versions
PyQGIS 3 API Documentation: official documentation of the Python API. Documentation for each major release since v3.0 as well as the nightly version is provided;
PyQGIS Developer Cookbook: written for QGIS 2.x it is gradually updated to 3.x. It still may be helpful as a tutorial and a reference guide and gives a good overview of the principal functionalities.
QGIS 2.x versions
PyQGIS Documentation:
PyQGIS Developer Cookbook: official introduction to PyQGIS programming. It is intended to work both as a tutorial and a reference guide and gives a good overview of the principal functionalities;
PyQGIS API Documentation: inofficial documentation of the Python API by SourcePole. It provides a searchable interface, but was not updated since QGIS 2.8;
QGIS C++ API Documentation: official C++ API documentation. While describing the C++ API, it can be useful for pyqgis development.
Online books:
Sherman G. (2014). The PyQGIS Programmer's Guide: extending QGIS 2.x with Python;
Westra E. (2014). Building Mapping Applications with QGIS: for both beginners and experienced Python developers, this book covers a lot of topics about the using of PyQGIS, including the creation of QGIS plugins and the using of QGIS in an external application;
Lawhead J. (2015). QGIS Python Programming Cookbook: 140 recipes for learning and automating geospatial workflows;
Menke K., Richard S., Pirelli L. (2015). Mastering QGIS: some sections provide practical, step-by-step examples for familiarizing with PyQGIS;
Graser A. (2016). Learning QGIS - Third Edition: one section is entirely dedicated to scripting QGIS with Python, starting from the basis to a more advanced using of the several available tools;
Lawhead J. (2017). QGIS Python Programming Cookbook - Second Edition: this book has a complete code upgrade to QGIS 2.18 and 30 new recipes.
Tutorials / Blogs / Web resources:
Nathan Woodrow: a blog mostly about QGIS stuff that also treats specific topics about the using of PyQGIS. The author is one of the most active QGIS developers;
nyalldawson.net: a blog with several posts about the using of PyQGIS. The author is one of the most active QGIS developers;
"How To" in QGIS: the site provides some suggestions for solving problems using PyQGIS. When possible, these tips are offered through simple code samples. I'm the author of this blog;
QGIS Tutorials and Tips: a section of this blog provides a series of tutorials for learning PyQGIS scripting. The author is a very experienced GIS specialist;
Lutra Consulting: a list of posts, having the PyQGIS tag, that cover some topics about PyQGIS.