I create a set of regular points with random offset inside a test area polygon using the QGIS Graphical Modeler. This it what the result looks like:
Then I use the following expression (not yet very elegant because of redundancy) to "move" the random points to the nearest point on the network (inspired by this answer from @Babel):
make_point(
x(
closest_point(
geometry(
get_feature_by_id(
'layer_name',
array_to_string(
overlay_nearest (
'layer_name',
"id"
)
)
)
),
$geometry
)
),
y(
closest_point(
geometry(
get_feature_by_id(
'layer_name',
array_to_string(
overlay_nearest (
'layer_name',
"id"
)
)
)
),
$geometry
)
)
)
This is what the result looks like:
The problem is now that I don't manage to integrate the last step into my graphical model, as I don't find a way to reference a layer created in a previous algorithm within the model.
I know that referencing previous algorithm results within expressions in the graphical modeler still is an issue in current QGIS versions. But maybe there is some workaround to elegantly include this part in the model? Of course, I could export the model as a processing script and do some direct Python coding, but it would be a pity to "leave" the graphical modeler only for this.
I am working with QGIS 3.22 Białowieża.


OUTPUTand the preciding@that introduces a variable, thus e.g.@Clip_lines_to_polygons_OUTPUT- see here for details: https://gis.stackexchange.com/a/469253/88814 – Babel Oct 28 '23 at 13:45