Graphics Reference
In-Depth Information
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 associ-
ated 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 geo-
metryInfo , put it somewhere convenient, and create an __init__.py file within that
directory. In that file, place the following code:
def classFactory(iface):
from geometryInfo import GeometryInfoPlugin
return GeometryInfoPlugin(iface)
Next, we need to define the metadata for our plugin. Create the metadata.txt file and
add the following to this file:
[general]
name=Geometry Info
email= your email address
author= your name
qgisMinimumVersion=2.0
description=Displays information about the clicked-on
geometry.
about=Plugin used as an example in Chapter 4 of Building
Mapping
Applications with QGIS.
version=version 0.1
Next, we need an icon for our plugin. We're going to use the following icon:
Search WWH ::




Custom Search