2

In QGIS geoprocessing scripts, I know how to connect an input parameter to a layer's attribute list. It would be like this:

##Input_layer=vector    
##Input_field_name=field Input_layer

But, is there any way to connect an input parameter to an attribute's unique value list? Maybe something like this:

##Input_field_value=value Input_field_name
  • What about my solution? Did it work for you? – mgri Dec 14 '16 at 11:58
  • Unfortunately it didn't. Thank you anyway. – DMS02 Dec 14 '16 at 12:36
  • I thinked that could be helpful... Out of curiosity, which was your task? – mgri Dec 14 '16 at 13:37
  • I need to do some geoprocessing based on a field value from a layer loaded in the qgis project. The layers may have different names and fields, and the values will be different every time (so I can't use a selection parameter with a list of values). – DMS02 Dec 14 '16 at 14:50
  • My answer was correct with reference to your question because it permits to you doing some operations on the basis of a specific value stored in a field. Your explanation, instead, makes your question not clearer anymore. If you want more help, please edit your question adding more information and reporting what do you want to do with the parameters; otherwise, I can't help you anymore. – mgri Dec 14 '16 at 15:07
1

I think you could only set a number parameter and then directly connect it to you field:

##Input_layer=vector    
##Input_field_name=field Input_layer
##Value_for_the_field=number 10

from qgis.core import *
import processing
# Load the layer
layer = processing.getObject(Input_layer)

# Write the filter expression and set it
query = '%s = %s' % (Input_field_name, Value_for_the_field)
selection = layer.getFeatures(QgsFeatureRequest().setFilterExpression(query))
for item in selection:
    # Do something

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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