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

Editing lines and polygons


The last major functionality we will examine is the ability to edit LineString and Polygon features. Just as the CaptureTool allowed the user to click and drag to create new lines and polygons, we will implement EditTool, which lets the user click and drag to move the existing feature's vertices. The following image shows what the user will see when they use this tool to move a vertex:

Our editing tool will also let the user add new vertices by double-clicking on a line segment, and delete vertices by right-clicking on the same line segment.

Let's define our EditTool class:

class EditTool(QgsMapTool):
    def __init__(self, mapCanvas, layer, onGeometryChanged):
        QgsMapTool.__init__(self, mapCanvas)
        self.setCursor(Qt.CrossCursor)
        self.layer             = layer
        self.onGeometryChanged = onGeometryChanged
        self.dragging          = False
        self.feature           = None
        self.vertex            = None

As you can see, EditTool...