Using a map tool to draw polygons or lines on the canvas

In this recipe, we'll create a tool to draw polygons on the canvas. This tool is an important tool because it opens the doors to even more advanced tools. Once you have a polygon on the canvas, you can do all sorts of operations that involve querying and geometry.

Getting ready

We will use the application framework from the Adding standard map tools to the canvas recipe, so complete that recipe. We will extend that application with a new tool. The complete version of this application is available in the code samples provided with this book.

How to do it...

We will add a new tool to the toolbar and also create a class that describes our polygon tool, as follows:

  1. First, we define our polygon tool's ...

Get QGIS Python Programming Cookbook - Second Edition 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.