Writing a QgsMapTool in Python

For my project I need to give the user three ways to define a rectangular area: it can be the bounding box of a layer, it can be the current view area, or it can be defined by the user drawing a rectangle. My main dialog covers the first two options with a dropdown and a push button, but the third option meant writing a map tool - in Python of course!

The code and details are downloadable from my site.

In short, you create a new class that inherits from QgsMapTool, set the tool on the canvas to be your tool, and then just sit back as the user interacts with the tool via the events generated. It all worked pretty well first time in Python.

So, here's hoping people will build lots of useful map tools!

Barry

Reply