3

In QGIS 3.16 I've inherited a sloppy dataset of regional roads.

My problem is this:

enter image description here

Roads have been drawn over for updates and not deleted, leaving behind hundreds to thousands of overlapping segments representing the same street, but with slightly differing vertices.

I'd love to find a tool or write a python code that can iterate through each overlapping segment and combine nodes, keeping the total length of the two and averaging the displacement in between. Because of the number of these instances, manual editing is out of the question.

I have tried:

  • Snap Nodes in QGIS - no apparent change
  • Merge Linestrings in QGIS (summary = mean) - no apparent change

I don't think tools such as union, dissolve, merge, etc. will work for incongruous lines.

I've been trying to find a Python package with a function that might help, but am having trouble with the language needed to search for my needs. Most results are for lines that are displaced but otherwise identical.

Taras
  • 32,823
  • 4
  • 66
  • 137
Olive
  • 133
  • 5
  • If you change the geomtry of the line, the lenght will change automatically. An idea would be buffering both lines, dissolve the buffer and get the central axis from the buffer, see: https://gis.stackexchange.com/questions/319412/simplifying-multiple-lines-to-create-central-axis – Babel Aug 27 '21 at 21:47

2 Answers2

1

Solution described for QGIS, should work the same way with other software packages:

  1. Extract the vertices from line1.

  2. For each vertex, find the closest point on line 2 and connect it with a line. Get the centroid of that line. To do so, use Geometry by expression, the vertices layer as input and output geometry type set to point. See below for the expression to use.

  3. Connect these points using Points to path to create the new, average line.

Expression to use for step 2 with Geometry by expression:

centroid (
    make_line (
        $geometry, 
        closest_point( 
            collect_geometries ( 
                aggregate( 
                    'line2', 
                    'collect', 
                    $geometry
            )),
            $geometry
)))

Screenshot: black and blue dotted = initial lines. Red solid line = resulting line. Blue dots: vertices of line1, light blue: line to the nearest point on line2; red dots: centroid of this line and verties of the red, resulting line:

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • I got only red dots without any line? Point to path, make the exact the same line like line1 – Frodo Oct 28 '21 at 05:46
  • Can you share your data or a screenshot? Otherwise its difficult to help – Babel Oct 28 '21 at 05:51
  • I uploaded screenshot? – Frodo Oct 28 '21 at 20:25
  • You posted an answer with a screenshot. Please be aware that you should not do that, but rather post a new question (you can link to this one here). Your problem: you must create the red points with Geometry by expression (step 2, the expression) and then connect these points with points to path: you probably used the Vertices layer as input for point to path. – Babel Oct 28 '21 at 20:30
  • Ok, how can I upload screenshot to comment message? I cant se any of point layer to convert point to line. Your answer is very imprecise. On right side You have 3 generated simbol, point, line point – Frodo Oct 29 '21 at 05:16
  • Use geometry by expression with the expression above, the verices layer as input and output geometry type set to point. You get a new point layer - use point to path on this layer. To post an ommage to comments, cooy the link to the image from your deleted answer and padte it. – Babel Oct 29 '21 at 06:10
1

Step by step: enter image description here

enter image description here

enter image description here

enter image description here

There is only one problem, the interpolation is not very precise? enter image description here

Frodo
  • 2,407
  • 1
  • 18
  • 36