Some time ago I made a post about creating a field in a polygon layer that get its value from length of line intersecting them. The answer I got at the time helped me for a specific purpose, but now I need it to be a little more complex.
The image below represents what I'm trying to achieve:

This is the answer I got:
with_variable (
'measure',
length (
make_line (
start_point (
collect_geometries (
overlay_nearest (
'line',
$geometry
)
)
),
closest_point (
intersection(
$geometry,
collect_geometries (
overlay_nearest (
'line',
$geometry
)
)
),
end_point (
collect_geometries (
overlay_nearest (
'line',
$geometry
)
)
)
)
)
),
if (
round ( @measure) %2 =0,
round ( @measure),
if (
@measure - floor( @measure) < 0.5,
ceil( @measure),
floor( @measure)
)
)
)
The problem with this answer now is that it does not recognize any change of directions in the line layer, computing only the straight length from start point to end point, thus not working in a ensemble of land lots that have a slight or accentuated curves. So it is only useful in straight formations.
So my question now is, is there a way to modify this code so that it can also perform the task in irregular shaped set of land lots?
