I have a line layer in QGIS that I have digitized on the basis of a PNG file. This layer includes main lines and many secondary lines. I would like to remove these secondary lines automatically and not manually, as there are a lot of them. In most cases, these secondary lines only have one vertex and are then connected to the main line. Is there a way to remove the secondary lines? For example, by removing all end vertices of the vector?
1 Answer
One option would be to use an expression to select the features to be deleted (Select by Expression).
overlay_intersects will get the list of features intersecting, and array_length will get the count of these.
num_points will get the total number of points.
If the ratio of these is <=0.5 then it should meet your secondary point criterion (one intersecting point, and other point(s) not intersecting). Any main lines should fail this criterion.
array_length(overlay_intersects(@layer,@feature))/num_points(@geometry)<=0.5
Obviously this assumes that your segments are actually intersecting as the image indicates!
- If I adopt your code in this way, unfortunately only small stand-alone features are selected where no intersections exist. The small features on the main lines unfortunately remain untouched :/Fabi– Fabi2024-05-09 12:43:13 +00:00Commented May 9, 2024 at 12:43
- You'll need to share a sample of your data, or otherwise provide more detail about the main lines/secondary lines.Tom Brennan– Tom Brennan2024-05-10 11:13:26 +00:00Commented May 10, 2024 at 11:13


Shortest path (layer to point)but that doesn't work because I have multiple parallel lines and I want to keep these Lines.v.generalizeonly returns an empty result. I will try the approaches in your second suggestionSettings -> Data Sources, and select Copy Features asPlain Text, WKT Geometry