Graphics Reference
In-Depth Information
Editing Points
Editing a Point feature is also quite straightforward: since the geometry consists of only
one point, the user can simply click-and-drag to move the point around within the map lay-
er. The following is a map tool that implements this behavior:
class MovePointTool(QgsMapToolIdentify):
def __init__(self, mapCanvas, layer):
QgsMapToolIdentify.__init__(self, mapCanvas)
self.setCursor(Qt.CrossCursor)
self.layer = layer
self.dragging = False
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.dragging = True
self.feature = found_features[0].mFeature
else:
self.dragging = False
self.feature = None
def canvasMoveEvent(self, event):
if self.dragging:
point = self.toLayerCoordinates(self.layer,
event.pos())
geometry = QgsGeometry.fromPoint(point)
self.layer.changeGeometry(self.feature.id(),
geometry)
self.canvas().refresh()
def canvasReleaseEvent(self, event):
Search WWH ::




Custom Search