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...