Skip to content
Permalink
Browse files
[processing] allow selection parameters with option populated from da…
…ta source
  • Loading branch information
volaya committed May 21, 2015
1 parent 8c8a123 commit a58085bf4ebaeab7fc5d8f5734a91f8e3152160e
Showing with 17 additions and 2 deletions.
  1. +14 −2 python/plugins/processing/core/parameters.py
  2. +3 −0 python/plugins/processing/script/ScriptAlgorithm.py
@@ -17,6 +17,7 @@
* *
***************************************************************************
"""
from processing.tools.vector import resolveFieldIndex, features

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -536,10 +537,21 @@ def getFileFilter(self):

class ParameterSelection(Parameter):

def __init__(self, name='', description='', options=[], default=0):
def __init__(self, name='', description='', options=[], default=0, isSource = False):
Parameter.__init__(self, name, description)
self.options = options
if isinstance(self.options, basestring):
if isSource:
self.options = []
layer = QgsVectorLayer(options[0], "layer", "ogr")
if layer.isValid():
try:
index = resolveFieldIndex(layer, options[1])
feats = features(layer)
for feature in feats:
self.options.append(unicode(feature.attributes()[index]))
except ValueError:
pass
elif isinstance(self.options, basestring):
self.options = self.options.split(";")
self.value = None
self.default = int(default)
@@ -169,6 +169,9 @@ def processParameterLine(self, line):
param = ParameterMultipleInput(tokens[0], desc,
ParameterMultipleInput.TYPE_VECTOR_ANY)
param.optional = False
elif tokens[1].lower().strip().startswith('selectionfromfile'):
options = tokens[1].strip()[len('selectionfromfile '):].split(';')
param = ParameterSelection(tokens[0], desc, options, isSource=True)
elif tokens[1].lower().strip().startswith('selection'):
options = tokens[1].strip()[len('selection '):].split(';')
param = ParameterSelection(tokens[0], desc, options)

0 comments on commit a58085b

Please sign in to comment.