4

I have a circular hiking trail. It was digitized in a way that I cannot reproduce. It is apparently a circular path, but it consists of many individual parts that overlap completely or partially. Also, all parts have different directions. In total, I have 1000 such paths, and I want to modify them as automatically and reliably as possible so that only one line geometry remains. I have attached a sample file. If you style the line with transparency, you can see the overlaps.

enter image description here

This line to download: https://e.pcloud.link/publink/show?code=XZTvkSZtRy14c1VSXfobx4MoMV2CyRk6aay

1
  • If I understand correctly, for your dataset, how about using the tools: 1) build polygons "nativepolygonize"; 2) Convert polygons to lines? Mar 27, 2023 at 18:26

2 Answers 2

4

Quick and dirty, but efficient:

  1. Buffer/dissolve lines with a very small distance (like 1 m) and set End cap Style to Square
  2. Get the Boundary of the buffer
  3. Run Multipart to single parts
  4. Delete the inner line

Variant:

Instead of step 4, get the center line of the two boundaries of the buffer, using this expression with Geometry by Expression:

case
when $id = 1
then
    close_line( 
        make_line (
            array_foreach (
                generate_series (1, num_points( $geometry)),
                    with_variable(
                    'vertex',
                    point_n (nodes_to_points ($geometry), @element),
                    centroid (
                        make_line (
                            @vertex,
                            closest_point (
                                geometry ( get_feature_by_id ('Single parts', 2)),  -- Replace Single parts by the name of your layer from step 3
                                @vertex
                            )
                        )
                    )
                )
            )
        )
    )
end

Initial red line with overlaps, blue result without overlaps:

enter image description here

Zooming close, you see that the initial red lines had double lines; the blue result just has one line; see measurement tool for distances: enter image description here

3

Use network tools to use the already existing lines for the result, but get rid of parallel, almost but not exactly same lines:

  1. Create a few (like 4) more or less evenly distributed points on your line (see screenshot).

  2. Run Shortest Path (layer to point) in Batch mode. Fill in the End points automatically by expanding Autofill > Add Values by Expression... with this expression (replace 4 with the number of points created in step 1):

     array_foreach (
         generate_series (1,4),
         geometry (get_feature_by_id ('points', @element))
     )
    

    Then set the other values/use Autofill to automatically copy the values to all rows.

  3. Explode/Delete duplicate geometries on the resulting layers, then use merge vector layers to combine them to one layer.

You might have to create a multipart layer to be able to merge all features to one single feature.

enter image description here

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.