Solution, created as ready to use model
I created a model (see details below) that gets rid of all overlapping parts in the output of the service area algorithm. I successfully tested it with your data (using the model 6 to create the service area). se the model here to clean any overlapping parts from an input line layer:
https://drive.switch.ch/index.php/s/iMfAyHWLzHZYDAT
Your layer must be in a projected CRS which is appropriate for measurements, e.g. local UTM zones.
See also this Geopackage which contains two layers: service area created with your input and the output of my model with resulting cleaned line layer.
Based on this, I expanded the model so that you have as input the initial network layer and the start point and you can enter a travel cost (distance for service area) and you get a cleaned up service area line layer without any overlaps + point layer for dangles at the end of the service area (adapting this solution). Download this model from here.
The second model with output service area (yellow) + dangles (red) with initial network (black dotted line):
The basic idea behind it
The algorithmic approach is: extract all vertices and split all lines at the vertices. Like this, overlapping lines will have the same vertices and are considered duplicates that you can delete.
The problem is how to get the same vertices for all overlapping lines. You get such overlappings as part of the service area output. Consider an Equilateral triangle defined by points A,B,C and with each side of a length of 2 (screenshot below). Run service area from start point A with:
travel cost of 2: Result is two lines: A to B
and A to C
.
travel cost of 3: both lines will be extended on the connection B/C and their ends meet exactly in the middel between B and C.
travel cost of 4: first line runs from A to B to C
, second line from A to C to B
. So C to B and B to C will be covered twice.
travel cost of 5: 1st line (blue): A to B to C to the middle between C and A; second line (red): A to C to B to middle between B and A, see image:
You see that the white dots are the end-points of the red and blue lines. However, where one line has an end-point, the other one has no vertex. So to begin with, you must add vertices to the lines where other (overlapping) lines have vertices.
Initial service area with some segments as duplicates, visible when you set a thik line style with transparent color: where lines are darker, you have two or more overlapping lines:
Solution explained step by step
Image of the model, described step by step in what follows:
Extract vertices.
Delete duplicate geometries (vertices)
Convert the remaining vertices to small, auxiliary lines using this solution (skip step 1: dissolve; in the expression in step 2, replace Dissolved by the name of your service area layer)
Split the lines: split the service area with the auxiliary lines from step 3.
Delete duplicate geometries.
By now, most duplicates will be deleted. There remain some lines with (almost) identical geometries that differ only in line direction: start- and end point are switched (line 1 is A to B, line 2 is B to A). The tricky part is now to identify these pairs and to select only one of them to be deleted. To do so, use Select by Expression with this expression (explanation below), then delete the selected features:
$id >
array_sum(
array_foreach (
overlay_nearest (@layer, $id,limit:=8),
if (
intersects (
buffer (
centroid(
geometry (
get_feature_by_id (@layer, @element)
)
),
0.000000001
),
$geometry
),
@element,
''
)
)
)
How the expression works: for each line get the centroid of the nearest few neighboring lines and create a very small buffer around these centroids. Then check if any of these buffers intersects with the current line: if so, get the id of the line with the intersecting buffer and check if this id is smaller then the id of the current line. Like this, you identify identical lines that differ only in line direction, but select just one of them.
Optional
- You may want to dissolve the result and convert multipart to single parts to get get a cleaner result with less features/one feature per "branch".