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:

enter image description here

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[0].geometry()
geom2 = feats[1].geometry()

# I need a function like this

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 intersects() and 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.

For example:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.