Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

Writing a useful plugin


Let's now apply the knowledge we've gained to build a plugin that does something useful and interesting. While there are built-in tools in QGIS to query a feature and identify the feature's attributes, there is no easy way of getting information about the geometry associated with a feature. So let's write a plugin that lets the user click on a feature and display various statistics about that feature's geometry.

We're going to call our new plugin Geometry Info. When the user clicks on our plugin's toolbar icon, we will activate a map tool that listens for mouse clicks on the map canvas. When the user clicks on the map canvas, we'll find the feature that the user clicked on, and calculate and display statistics about that feature's geometry.

Let's start by setting up the basic template for our plugin. Create a directory named geometryInfo, put it somewhere convenient, and create an __init__.py file within that directory. In that file, place the following code:

def classFactory...