I am working on a processing script in QGIS 3, which does the following:
- Take a few inputs
- Run a native algorithm on these inputs, saving the resulting new layer in memory
- Set up the symbology for the layer (specifically, setting the renderer via
- Return the layer, retaining its symbology, as the primary algorithm output
The key here is that I want to return a layer after setting up its symbology.
This is problematic because I'd like to use the common input parameter
QgsProcessingParameterFeatureSink, since this lets the user choose how to output the results (memory layer, temporary file, saved in a format of their choice, etc).
However, as far as I can tell, the
...ParameterFeatureSink parameter is primarily used with
parameterAsFeatureSink method, which returns an interface to a new layer, which does not allow setting up symbology. Also, it appears that this layer is what the algorithm expects to be
returned at the end, and that returning another layer (like the one described in the list above) in its place causes an error.
My question is this: how do I utilize the strengths of
QgsProcessingParameterFeatureSink, while still being able to return a layer with its symbology set up as described?
The ideal solution here would be to use another of the
parameterAs methods to get a place or name for the layer I'll eventually return. I could feed that name to the internal algorithm as its
OUTPUT parameter, making it return a layer that my algorithm could subsequently return without generating an error.