This is the first QGIS Process Model I have ever attempted to build (and I am still on a learning curve with QGIS generally).
THE ASSIGNMENT:
I need to build a model that will take an input vector and (1) rename it (the name must come from an attribute value stored within the layer), (2) clip it against another polygon, (3) and finally add a pre-defined style.
THE CATCH:
The input layers will always have the same name i.e. "2D Zones" there is no way around this as they are outputs from another piece of software and this cannot be changed. The fields for these input layers will always have the same names and will be arranged in the same order, the attribute values will differ.
There is a field within each "2D Zones" table called "retperiod" the value appearing in that column will be the same throughout the whole column but will differ from layer to layer, so this is the attribute I want to use as a name.
BACKGROUND READING:
After reading the solutions to similar problems posted here:
- Create dynamic filename, based on attribute value, for output of QGIS model
- Create dynamic filename, based on attribute value, for output of QGIS model
- Accessing input layer properties from QGIS Modeler?
I have managed to come up with a model that performs the task I wish it to do (see link).
https://drive.google.com/drive/folders/1y0RnrLsOQIHaiDn74U8Qsana1iBUyoM8?usp=sharing
I have also read all this lot (although probably haven't understood it all):
- QGIS graphical modeller naming layer output based on attribute
- Loading rasters from a GeoPackage into QGIS modeler based on attribute information?
- QGIS Modeler: Layer Rename does not output
- Rename layer in model builder with almost original name
- https://github.com/qgis/QGIS/issues/39874
- Is it possible to have dynamic layer names in QGIS project?
THE PROBLEM
However, one shortcoming of my model is that I have to specify the input layers as both a "Vector Features" and a "Vector Layer" input. This seems to be because I can only the Modeller won't allow the "get_feature_by_id" function to work on the "vector layer" input but it will work on the "vector feature" input..... Essentially, this model will only complete the renaming routine, i.e. this bit:
attribute(get_feature_by_id(@vectorfeature,1),'retperiod')
If I get it to look in the "vector feature" input for the attribute that can be used as a name but then it must be applied to the input from "vector layer" in order for the subsequent processes (i.e. clipping and styling) to work.
All very unintuitive.
THE QUESTION:
Is there a more elegant solution to all this whereby I don't have to specify the same inputs twice in two different ways?
This is still problematic as the original files all have exactly the same name and there is every chance I will match the two inputs incorrectly when using the "batch process" option.