To get an array withCalculate the length of the border the current polygon shares with all bordering polygons, use this expression that creates an array:
Convert it to a string with array_to_string()
, add the $id
to identify tothe polygons etcand add other modifications (see below).
A polygon layer with an expression-generated label, based on the expression from above, that generates a text-string list of length with all neighboring polygons (see below for the exact expression used here):
- The expression used to generate the red line in the screenshot, using Geometry generator:
The expression used to generate the red line in the screenshot, using Geometry generator:
if ($id = 1, intersection ( $geometry, overlay_touches (@layer, $geometry)[0]),'')
if ($id = 1, intersection ( $geometry, overlay_touches (@layer, $geometry)[0]),'')
To generate the length of the common boundary line of polygons
b
andc
, stored in the field namedname
, use this expression (change layer name and value in lines 2 and 6):if ( name = 'b', length( intersection ( $geometry, geometry (get_feature (@layer, 'name', 'c')) ) ), '' )
- The expression used to generate the label in the screenshot - can be used without changes on any polygon layer:
The expression used to generate the label in the screenshot - can be used without changes on any polygon layer:
'Length border of polygon ' || $id || ' with: ' || '\n' || array_to_string ( array_foreach ( overlay_touches (@layer, $id), ' - polygon' || @element || ': ' || round ( length ( intersection ( $geometry, geometry ( get_feature_by_id ( @layer, @element ) ) ) ), 3 ) ) )
'Length border of polygon ' ||
$id || ' with: ' || '\n' ||
array_to_string (
array_foreach (
overlay_touches (@layer, $id),
' - polygon' ||
@element || ': ' ||
round (
length (
intersection (
$geometry,
geometry (
get_feature_by_id (
@layer,
@element
)
)
)
),
3
)
)
)