I'm writing a Plugin where you build networks with point and line geometries. One Tool should give the User the possibility to make changes to the network by dragging and dropping the points to another location. Since the points are sometimes connected to lines I want the vertex of the connected lines to the new location as well. I managed to write a tool that does exactly that, but if several line features are connected to the same point it fails and only drags one line. I tried looping through all the line features and thought it should work, but it still only moves one line and I don't know why.
Here a few pictures to illustrate my problem:
I wrote a maptool-class passing the QgsMapTool to it.
In the canvasPressEvent I call on two methods one looks for features and the other for vertices. if there are results i enable dragging and start editing. Here are the code parts where I think the problem might be in
def findVertexAt (self, pos): self.lineFeatures= self.vertices =  point = QgsPoint(self.canvas.getCoordinateTransform().toMapCoordinates(pos.x(), pos.y())) tolerance = self.calcTolerance(pos) searchRect = QgsRectangle(point.x() - tolerance, point.y() - tolerance, point.x() + tolerance, point.y() + tolerance) request = QgsFeatureRequest() request.setFilterRect(searchRect) request.setFlags(QgsFeatureRequest.ExactIntersect) for feature in self.netLayer.getFeatures(request): self.lineFeatures.append(feature) i = 0 while i <= len(self.lineFeatures)-1: vertexCoord, vertex, prevVertex, nextVertex, distSquared = self.lineFeatures[i].geometry().closestVertex(QgsPointXY(point)) self.vertices.append(vertex) i = i + 1 return self.vertices def canvasMoveEvent(self, event): point = QgsPoint(self.canvas.getCoordinateTransform().toMapCoordinates(event.pos())) pointXY = QgsPointXY(point) if self.dragging: geometry = QgsGeometry.fromPointXY(pointXY) self.layer.changeGeometry(self.feature.id(),geometry) if self.lineDragging: i = 0 while i <= len(self.lineFeatures)-1: lineGeometry = self.lineFeatures[i].geometry() lineGeometry.moveVertex(point, self.vertices[i]) self.netLayer.changeGeometry(self.lineFeatures[i].id(), lineGeometry) i = i + 1
The canvasRelease event then just disables dragging and commits the changes