I want to run the calculation based on what the user chooses from the drop-down menu. For Example, if the user chooses the second option, then the calculation will be using the second formula. I can run my code but the calculation only uses the first formula. How to make use the other formula?
self.addParameter(QgsProcessingParameterEnum(
self.RAD_PERCENTAGE,"Age",
options = ['More than 10 years','5 to 9 years','Below than 5 years']
))
for options in self.RAD_PERCENTAGE:
if 'options == 0':
field = processing.run("qgis:fieldcalculator",
{'INPUT':parameters[self.INPUT_VECTOR],
'FIELD_NAME':'NewRadius',
'FIELD_TYPE':0,
'FIELD_LENGTH':10,
'FIELD_PRECISION':4,
'NEW_FIELD':True,
'FORMULA':'Radius-(Radius * 20/100)',
'OUTPUT': 'memory:'
},context=context, feedback=feedback, is_child_algorithm=True)
newradius = field['OUTPUT']
elif 'options == 1':
field = processing.run("qgis:fieldcalculator",
{'INPUT':parameters[self.INPUT_VECTOR],
'FIELD_NAME':'NewRadius',
'FIELD_TYPE':0,
'FIELD_LENGTH':10,
'FIELD_PRECISION':4,
'NEW_FIELD':True,
'FORMULA':'Radius-(Radius * 10/100)',
'OUTPUT': 'memory:'
},context=context, feedback=feedback, is_child_algorithm=True)
newradius = field['OUTPUT']
else:
field = processing.run("qgis:fieldcalculator",
{'INPUT':parameters[self.INPUT_VECTOR],
'FIELD_NAME':'NewRadius',
'FIELD_TYPE':0,
'FIELD_LENGTH':10,
'FIELD_PRECISION':4,
'NEW_FIELD':True,
'FORMULA':'Radius-(Radius * 0/100)',
'OUTPUT': 'memory:'
},context=context, feedback=feedback, is_child_algorithm=True)
newradius = field['OUTPUT']
options == 1
. Also there is no need to iterate overself.RAD_PERCENTAGE
.