Chapter 11. PyQGIS Scripting

This chapter is focused on a specific use case or user. QGIS can be used in many different ways, and the GIS user is an eclectic user who has many different ways to interact with data and QGIS tools. The main focus of this chapter is a user who has an algorithm and wants to integrate it with QGIS.

An algorithm can be an external program, such as a water-modeling tool, or a Processing Toolbox's set of instructions.

It's possible to interact with QGIS in many different ways, from experimenting with PyQGIS in the Python console, to creating plugins that control events generated by QGIS. This chapter will give you an overview of the following topics:

  • Learning Python
  • Loading rasters by code
  • Loading vectors by code from files or database
  • Describing vector structure and how to browse and edit features
  • Using Processing Toolbox algorithms by code and executing your custom algorithm
  • Calling external algorithms
  • Interacting with canvas events to draw or pick values from a raster or vector

Where to learn Python basics

This chapter is not intended to give you an introduction to Python programming. There are a lot of free online resources and Massive Open Online Course (MOOC) (http://en.wikipedia.org/wiki/Massive_open_online_course) courses on the Web.

The main resources can be obtained directly from the Python homepage at https://www.python.org/about/gettingstarted/, where there is a big collection of guides, free books, and tutorials.

Tabs or spaces, make your choice!

When programming in Python, it's important to give special attention to editing code with correct indentation. Avoid mixing spaces and tabs because it can generate errors that can be difficult to understand, especially for someone who is a beginner at Python programming. The official PEP8 Python standard recommends using spaces.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.193.172