You can create this effect using Geomtry Genrator with this expression to create a separate line for each shared path between two polygons (to create actual lines with Geometry by Expression, see below):
collect_geometries(
with_variable( 'my_id', @id,
array_foreach(
eval ('overlay_intersects (@layer, @id, filter:=@id<' || @my_id || ')'),
line_merge(
intersection(
boundary(geometry(get_feature_by_id(@layer, @element))),
boundary($geometry)
)
)
))
)
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/3KnBQydl.png)
To visually represent all in different colors, I used data driver override for the color -> Assistant...
-> and inserted the following expression in Source
:
@geometry_part_num ||
array_find (array_sort (array_agg($id)), $id)+1
Select a color ramp, tweak values from/to and and maybe apply a transformation curve to really get clearly discernable, distinct color values as in the screenshot above.
To create actual lines with Geometry by Expression, use this expression (replace Layername
with the name of the polygon layer), then run Multipart to single parts to get a separate feature for each part of the border:
collect_geometries(
with_variable( 'my_id', @id,
array_filter (
array_foreach(
eval ('overlay_intersects (''Layername'', @id, filter:=@id<' || @my_id || ')'),
line_merge(
intersection(
boundary (geometry (get_feature_by_id ('Layername', @element))),
boundary($geometry)
)
)
),
@element is not NULL
)
))
Now, to get different colors for neighboring lines, proceed as follows:
- Create a (very tiny) buffer around the lines.
- Use Topological coloring for the buffer.
- Use Join attributes by location (lines form step 1 ->
are within
-> buffer from step 2) and selct the field color_id
.
- Then use Categorized layer style based on the attribute created in step 3 and you're done.
Based on topological coloring with only 4 colors to get clearly distinguishabel colors:
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/JYjspu2C.png)