2

I'm trying to write a QGIS processing script using the new API (3.4), but I hardly find any documentation. Based on this excellent resource by Anita Graser (https://anitagraser.com/2018/03/25/processing-script-template-for-qgis3/), I could manage to set up a basic script that mostly fits my needs.

But I have some fixed-value (eg: ['walking', 'car']) options for which I'd like to include drop-down menus. I assume that I have to use a QgsProcessingParameterString but using the available documentation, I could'nt figure out how to do it.

underdark
84.9k22 gold badges237 silver badges418 bronze badges
asked Feb 22, 2019 at 8:27

1 Answer 1

8

The PyQGIS documentation can be searched for all potential QgsProcessingParameter classes: https://qgis.org/pyqgis/master/search.html?q=QgsProcessingParameter&check_keywords=yes

For your use case, QgsProcessingParameterEnum seems fitting.

Here's a usage example from qgis-latlontools-plugin:

self.addParameter(
 QgsProcessingParameterEnum(
 self.PrmCoordinateOrder,
 tr('Coordinate order when using 1 field'),
 options=[tr('Lat,Lon (Y,X) - Google map order'),tr('Lon,Lat (X,Y) order')],
 defaultValue=0,
 optional=True)
 )
answered Feb 22, 2019 at 9:34
2
  • 1
    'QgsProcessingParameterEnum' gives value as Integer i.e. the index. Can you tell me how to access the value from it in processing script Commented Dec 16, 2020 at 4:31
  • Open the plugin in Github, find PrmCoordinateOrder and do a check for where it is used (click on it, select references). There is also an example with more than 2 options further down Commented Apr 17, 2023 at 2:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.