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.

6
  • 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
    Commented Oct 25, 2023 at 5:06
  • Found it: gis.stackexchange.com/a/421142/88814
    – Babel
    Commented Oct 25, 2023 at 5:12
  • 1
    That's great, thank you very much! Nice workaround that seems more simple than the other solution proposed here: gis.stackexchange.com/a/448131/52808. I will post a part of my model with my individual solution later today.
    – winnewoerp
    Commented Oct 25, 2023 at 8:00
  • I did not find a solution yet, as my example is different to the one shown here 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
    Commented Oct 25, 2023 at 19:51
  • I did not find a solution to solve it using this approach 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: gis.stackexchange.com/q/469246/52808.
    – winnewoerp
    Commented Oct 28, 2023 at 5:55

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.