[Qgis-user] Get QgsProcessingParameterFeatureSource's parent layer

andre at nammail.net andre at nammail.net
Tue Dec 3 07:47:22 PST 2024


Dear all,

I have a processing algorithm that names its output based on the input 
layer's name, e.g. if buffering a layer called 'powerlines_110kW' with 
40m the output layer would be called 'powerlines_110kW+40m'. For the 
input I use QgsProcessingParameterFeatureSource (instead of 
VectorLayer), so that the "Selected features only" option is available.

My problem is, when "Selected features" is unchecked, I can get the 
input layer's name with the 'parameterAsVectorLayer(parameters, 'INPUT', 
context).name()' method. However, when "Selected features" is checked, 
'parameterAsVectorLayer()' returns None. This makes sense, as I believe 
the input becomes wrapped in a QgsProcessingFeatureSourceDefinition. Is 
there any way to get the layer's name before the selected features are 
extracted/filtered from the selected vector layer (the one given by the 
user in the ComboBox)?

Many thanks
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20241203/add80b72/attachment.htm>


More information about the QGIS-User mailing list