0

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?

enter image description here

6
  • Is it somehow possible to share data in this forum? Commented May 9, 2024 at 17:19
  • I've updated the question with my data Commented May 11, 2024 at 12:16
  • Maybe try using network tools to identify the main line. Something similar like here: gis.stackexchange.com/a/418644/88814 or gis.stackexchange.com/a/444603/88814 Commented May 11, 2024 at 12:32
  • I tried Shortest path (layer to point) but that doesn't work because I have multiple parallel lines and I want to keep these Lines. v.generalize only returns an empty result. I will try the approaches in your second suggestion Commented May 11, 2024 at 12:59
  • Not sure what format your data is in - check Settings -> Data Sources, and select Copy Features as Plain Text, WKT Geometry Commented May 12, 2024 at 0:11

1 Answer 1

4

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

enter image description here

Obviously this assumes that your segments are actually intersecting as the image indicates!

2
  • 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 :/ Commented 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. Commented May 10, 2024 at 11:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.