9

My version of QGIS is 2.8.3

I have a tool which takes parameters like this:

##Input_Vector_Layer=vector
##Input_Raster_Layer=raster
##Distance=number 1.0
##Height=field Input_Vector_Layer

# Do Something...

Is it possible to make the fourth parameter optional?

4
  • 2
    Have you tried ##Height=optional field Input_Vector_Layer?
    – Joseph
    Dec 7, 2016 at 10:02
  • Just tried but did not work, it gives me this : 'Problem with line: %d', 'ScriptAlgorithm') % (self.descriptionFile, line)) TypeError: %d format: a number is required, not str Dec 7, 2016 at 10:15
  • @user80597, did my solution work for you?
    – mgri
    Dec 7, 2016 at 11:29
  • @HowToInQGIS It does work, though it is not the exact thing I am look for, I think this might be the best I can do in v2.8... Dec 7, 2016 at 20:08

1 Answer 1

5

If it's not a problem for you, my idea is to add a Boolean:

##Input_Vector_Layer=vector
##Input_Raster_Layer=raster
##Distance=number 1.0
##Height=field Input_Vector_Layer
##Use_Optional_Field=Boolean True

and the directly check for its value:

check = Use_Optional_Field
if check:
    # Do something...
else:
    # Do something else
2
  • This is probably the best method to emply using QGIS 2.8 =)
    – Joseph
    Dec 7, 2016 at 13:28
  • 3
    As suggested by @Joseph , the optional field parameter only works for more recent versions.
    – mgri
    Dec 7, 2016 at 13:39

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.