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
35.8k5 gold badges77 silver badges151 bronze badges
asked Aug 27, 2021 at 17:59
1
  • 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: gis.stackexchange.com/questions/319412/… Commented Aug 27, 2021 at 21:47

2 Answers 2

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

answered Aug 27, 2021 at 21:58
6
  • I got only red dots without any line? Point to path, make the exact the same line like line1 Commented Oct 28, 2021 at 5:46
  • Can you share your data or a screenshot? Otherwise its difficult to help Commented Oct 28, 2021 at 5:51
  • I uploaded screenshot? Commented Oct 28, 2021 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. Commented Oct 28, 2021 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 Commented Oct 29, 2021 at 5:16
1
answered Nov 1, 2021 at 6:46
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.