1

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:

Regular points with random offset inside regular network, background map: OpenStreetMap contributors

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:

Regular points with random offset moved to nearest point on regular network, background map: OpenStreetMap contributors

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.

winnewoerp
  • 1,504
  • 11
  • 21
  • I had an answer somewhere here on GIS SE for a similar problem. Use rename algorithm to give the the previous output layer a new name so that you can use it to reference it – Babel Oct 25 '23 at 05:06
  • Found it: https://gis.stackexchange.com/a/421142/88814 – Babel Oct 25 '23 at 05:12
  • 1
    That's great, thank you very much! Nice workaround that seems more simple than the other solution proposed here: https://gis.stackexchange.com/a/448131/52808. I will post a part of my model with my individual solution later today. – winnewoerp Oct 25 '23 at 08:00
  • I did not find a solution yet, as my example is different to the one shown here https://gis.stackexchange.com/a/421142/52808. I can't just rename a model input layer and then use it, but I need to include a layer in the expression that has run through different processing tools. At the moment I don't see any possibility to include a modified layer (result of different processing tasks run on the original layer) in the expression. Or am I wrong? @Babel: Does your approach also work for such a case? – winnewoerp Oct 25 '23 at 19:51
  • I did not find a solution to solve it using this approach https://gis.stackexchange.com/a/421142/88814, as only (renamed) input layers can be handled. The approach does not allow the usage of previous algorithm results (modified input layers) inside the expression (if I'm not wrong). So here's a follow-up question: https://gis.stackexchange.com/q/469246/52808. – winnewoerp Oct 28 '23 at 05:55
  • To reference a layer created in a previous algorithm in QGIS modeler, you can use the variable that QGIS creates automatically - they are called after the algorithm you used with suffix OUTPUT and 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

1 Answers1

0

The problem is that QGIS versions prior to 3.24 offer the possibility to select the desired @layer_name_OUTPUT in the expression builder, but due to an unsolved issue in these versions referencing does not work.

An update to at least QGIS version 3.24 Tisler is necessary to reference outputs of previous algorithms in the Model Designer.

winnewoerp
  • 1,504
  • 11
  • 21