I want to place a regular random distribution points inside a polygon and move these points to the respective closest point on a line layer afterwards. I use regular points algorithm with random offset for the creation of the random points.
The goal is to create a graphical model for this process. I have the problem that I can't access the output of a previous part of the model inside an expression within the "Geometry by expression" tool, as described in this question. So for the moment I had to split it into two different models, which is not a large problem, but seems pretty "unelegant".
Here are images of the two parts of the model:
In the second part I use the approach described here to access an input layer inside an expression. (The productive case uses input layers without any ID attributes. This is why I add the "checkid" field needed inside the expression.)
With my Hamburg test case, the result after running the first part of the model looks like this:
The second part looks like this (with hidden resulting layers from part 1):
(background map: © OpenStreetMap contributors)
This is the current version of the expression inside "Geometry by expression" to move the random points to the next line (new_line_layer is the layer renamed using "Rename layer" algorithm):
make_point(
x(
closest_point(
geometry(
get_feature_by_id(
'new_line_layer',
array_to_string(
overlay_nearest (
'new_line_layer',
"checkid"
)
)
)
),
$geometry
)
),
y(
closest_point(
geometry(
get_feature_by_id(
'new_line_layer',
array_to_string(
overlay_nearest (
'new_line_layer',
"checkid"
)
)
)
),
$geometry
)
)
)
My question is now: Is there either a way to combine everything to one graphical model using my approach (or alternatively another approach leading to the same result)?