1

I'm using the "Intersect" tool in QGIS 3.10.3 on two line layers 'A' and 'B' to create the intersecting layer 'C'. I can then use the "Difference" tool to subtract 'A'-'C' and to subtract 'B'-'C', resulting in three mutually exclusive layers.

The problem is that each of the features in layer 'C' has two copies of the intersecting line segment (one from each input layer?) so that when the feature is drawn the line appears heavier or thicker than the lines in the other two layers. How can I resolve this? Can I make an intersecting layer with just one copy of each intersecting line? I have tried using the Remove Duplicate Vertices tool without effect, maybe I don't know how to use it.

I guess I should clarify. I'm looking for line segments that overlay each other, so I'm using the Geoprocessing tool called Intersection. I'm not interested in lines that simply cross each other at a point.

7
  • Can you add a screenshot showing the problem?
    – Bera
    Commented Mar 6, 2020 at 19:03
  • 1
    Have you tried the Delete duplicate geometries tool on layer C?
    – Gabriel
    Commented Mar 6, 2020 at 20:17
  • Thanks for the suggestion, but Delete duplicate geometries doesn't help. It deletes duplicate geometries between different features. In my case, each individual feature contains two copies of the same line; that is, each individual feature has two copies of every vertex.
    – Eric
    Commented Mar 6, 2020 at 21:37
  • The intersection result should be just one line. You can isolate the problem: create two layers with the same line; intersect them; the result should be just one line. Not two.
    – jgrocha
    Commented Mar 7, 2020 at 10:39
  • Yes, the result should be just one line, but it's not. It's one feature but not just one line. Try it with a line that has 5 vertices. Examine the vertex table of the intersected feature (layer C) and you will see that there are now 8 vertices! There's one instance of each end vertex and 2 instances of every vertex in between. That's what I mean by two lines. If v is the number of vertices in the layer A line, then the intersected line C always has 2v-2 vertices.
    – Eric
    Commented Mar 7, 2020 at 14:56

2 Answers 2

1

One possible solution to your problem is to use the Field Calculator to create a new line that represents the segment of intersection between two lines (A and B for you).

In the Processing Toolbox select the tool Vector Geometry > Geometry By expression.

enter image description here

Here select "line_b" as Input Layer, "Line" as Geometry Type and had this expression to the Geometry Expression

intersection($geometry, (geometry(get_feature_by_id('line_b',$id))))

This will create a new layer with a line that is the result of the intersection of line a and line b.

enter image description here

2
  • Layer A and layer B each contain hundreds of line features and the intersecting layer might also contain hundreds of intersecting lines.. This looks like a lot of labor to create them one by one. In addition I want an intersecting layer that contains the attributes from both A and B. Can this be automated?
    – Eric
    Commented Mar 7, 2020 at 1:44
  • I have edited my answer to suit your request. Now you can create x new lines C , by expression, for any intersection of line A and B.
    – Val P
    Commented Mar 7, 2020 at 11:37
0

This happen because the result of the intersect tool is a multipart line where each segment between two vertices is one part. So you don't get two superposed line but at each inner vertices position (meaning all vertices but the first and last) you have the end vertices of one part and the first vertices of the next part that superpose.

To verify that you can use the vertex tool to displace the duplicate position vertices, you will see that you have only one line separated in several segment.

As these two superposed vertices belong to two different part of the same geometry they are not removed by the "Remove Duplicate Vertices" tool.

To remove these apparently duplicated vertices you need to run the "Merge lines" tool on the result of the "Intersection" tool. this will transform the multiline to single line geometry and give you a result that match your expectation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.