I am looking for an easy way or function to split 2 previously selected line features (generate vertex) at intersecting points (or touching points). See the following picture:
I am developing a function/plugin where the user is supposed to manually select 2 line features which intersect and wants them to be splitted at intersection (touching) point.
So something like this:
layer = iface.activeLayer() feats = layer.selectedFeatures() geom1 = feats.geometry() geom2 = feats.geometry() # I need a function like this geom1.splitAtIntersection(geom2)
The line features/layer are loaded from a PostGIS database, so it is important to edit the existing layer and not create a new layer or shapefile. It would be nice if there is a pure pyqgis solution which I overlooked to solve this problem.
I found the
touches() functions of the
QgsGeometry class, but they dont return the intersection points. There has to be a native pyqgis function to retrieve the intersection point or to split lines at a given point, right?
I know there is the split lines with lines tool, but I only want to split manually selected features/lines and not all.
I am aware that there are several similar questions asked already, but none of them seem to solve my particular issue.