Deleting Points and other features
Fortunately, the code required to delete a Point feature will also work for other types of geometries, so we don't need to implement separate DeletePointTool
, DeleteLineTool
, and DeletePolygonTool
classes. Instead, we only need a generic DeleteTool
. The following code implements this map tool:
class DeleteTool(QgsMapToolIdentify): def __init__(self, mapCanvas, layer): QgsMapToolIdentify.__init__(self, mapCanvas) self.setCursor(Qt.CrossCursor) self.layer = layer self.feature = None def canvasPressEvent(self, event): found_features = self.identify(event.x(), event.y(), [self.layer], self.TopDownAll) if len(found_features) > 0: self.feature = found_features[0].mFeature else: self.feature = None def canvasReleaseEvent(self, event): found_features = self.identify(event.x(), event...