3

I am building a Python Scripts for Processing Framework

https://docs.qgis.org/2.14/en/docs/pyqgis_developer_cookbook/processing.html

I know how to make default value when the data type is number or boolean:

##Distance=number 50
##carry_test=boolean True

I also know how to make fields in the layer into a drop down table and let user choose from:

##input_layer=vector
##cal_field=field input_layer

Is there a way to populate a default field as well? Say the layer has the following fields:

fid, name, type, color

Normally everytime the user has to check the drop down to choose 'type'. So it is kind of trouble, is there a way to choose the 'type' everytime when the input_layer has the field 'type'?

Joseph
  • 75,746
  • 7
  • 171
  • 282
benchenggis
  • 1,406
  • 2
  • 12
  • 30
  • 1
    Could you be more specific on what you need to populate ? You might need to ask for a new field name, then launch an update on your new field within the code like in here : https://gis.stackexchange.com/questions/236745/updating-field-with-layer-name-on-multiple-layers-with-pyqgis-script/ – gisnside Apr 18 '17 at 22:50
  • I have edited my question – benchenggis Apr 18 '17 at 22:54

1 Answers1

2

I don't think this is currently possible as at the moment, you can only specify:

##Field=[optional] field [number|string] Parentinput

where:

  • Field - Name of the field parameter in the GUI.
  • [optional] - Optional option to make it...optional.
  • field - The parameter used to list the fields in the layer.
  • [number|string] - Optional filter to only list numeric or string fields in the layer.
  • Parentinput - The layer to read the fields from.

In the more recent processing version, you will also be able to filter date fields but there doesn't to be a method (yet) to allow default values for fields. You can always ask this as a feature request though.

Joseph
  • 75,746
  • 7
  • 171
  • 282