I am trying to dissolve the grey line layer where the field "dis" ( "anzahl" || '-' || "heizlast") has the same value and the segments are touching ( end_point touches the next segments start_point).
The dissolve function ( with keep disjoint features separate) is not working for this specific example becuse the orange segment and the blue one touch in the end_point. For this kind of solution I thought of geometry by expression:
collect_geometries(
aggregate(
layer:='Aggregated',
aggregate:='array_agg', --or 'collect' I am not quite sure
expression:=$geometry,
filter:=intersects(end_point(@geometry), start_point(geometry(@parent)))
AND "dis" = attribute( @feature , 'dis')
))
However the result is not what I am expecting. I think I read it somewhere that the aggregate function is not working well with the geometry by expression. I am not quite sure that my function is good enough , maybe I need some kind of iteration where more than two segments are compared ? like array_foreach ? I am stuck ....
I just found quite the same question here and tried the expression: Merging line segments using length rules in QGIS
union (
$geometry,
eval (
'overlay_touches (''line'', $geometry, filter:=id= ' || id || ' and $id <> ' || $id || ' )[0]'
)
)
The problem is that the expression is combining two segments at a time and also generates NULL geometries and duplicates. The expression needs a finishing touch for iterating and collecting all the touching lines where the end_point match the start_point and has the same value. Also the expression that I copied is referencing to "id" ( int) and my field for dissolving "dis" is of type string wich is not working in this context.Here is the part where I need some help.
Retrospectively Dissolving line segments in QGIS if they touch and fall within same class?
I also found the exact the same question ( 8 years old) but the solution by the author himself can not be applicable in this case. I need a more general function otherwise it complicate the situation with the so called "higher" order and splitting by lines.
I tried something similar by myself:
Dissolve ( field: "dis" and keep disjoint feature separate )
In this case the 3 segments ( blue marked ) are being merged because they are touching. I can then generate the vertices of the segments and categorize this by the next expression:
count('Vertices', group_by:=geom_to_wkt($geometry))
Afterwards I would split the undesired merged segments from before with the vertices that are different then 1 and get what I need. BUT choosing this path it has again an undesirable effect for the remaining splitted lines which will changed the direction.
st_lineMerge
could be usedSELECT t1.dis, ST_LineMerge(ST_Collect(t1.geometry, t2.geometry)) as geometry FROM layer AS t1 JOIN layer AS t2 ON t1.start_point = t2.end_point AND t1.id <> t2.id GROUP BY t1.dis
? maybe the group by needs to be separate - won't be in front of a PC for a while to test