Skip to content
Permalink
Browse files

[processing] support for output geometry types (work in progress)

  • Loading branch information
alexbruy committed Sep 2, 2016
1 parent 8c3537b commit 7e26124c2be75276e1c7a4361e6626dbebaaa251
@@ -256,13 +256,23 @@ def getTableWriter(self, fields):

class OutputVector(Output):

VECTOR_TYPE_POINT = 0
VECTOR_TYPE_LINE = 1
VECTOR_TYPE_POLYGON = 2
VECTOR_TYPE_ANY = -1

encoding = None
compatible = None

def __init__(self, name='', description='', hidden=False, base_input=None):
def __init__(self, name='', description='', hidden=False, base_input=None, datatype=[-1]):
Output.__init__(self, name, description, hidden)
self.base_input = base_input
self.base_layer = None
if isinstance(datatype, int):
datatype = [datatype]
elif isinstance(datatype, basestring):
datatype = [int(t) for t in datatype.split(',')]
self.datatype = datatype

def hasGeometry(self):
if self.base_layer is None:
@@ -336,3 +346,17 @@ def getVectorWriter(self, fields, geomType, crs, options=None):
self.layer = w.layer
self.value = w.destination
return w

def dataType(self):
types = ''
for t in self.datatype:
if t == self.VECTOR_TYPE_POINT:
types += 'point, '
elif t == self.VECTOR_TYPE_LINE:
types += 'line, '
elif t == self.VECTOR_TYPE_POLYGON:
types += 'polygon, '
else:
types += 'any, '

return types[:-2]
@@ -972,14 +972,14 @@ class ParameterVector(ParameterDataObject):
VECTOR_TYPE_POLYGON = 2
VECTOR_TYPE_ANY = -1

def __init__(self, name='', description='', shapetype=[-1],
def __init__(self, name='', description='', datatype=[-1],
optional=False):
ParameterDataObject.__init__(self, name, description, None, optional)
if isinstance(shapetype, int):
shapetype = [shapetype]
elif isinstance(shapetype, basestring):
shapetype = [int(t) for t in shapetype.split(',')]
self.shapetype = shapetype
if isinstance(datatype, int):
datatype = [datatype]
elif isinstance(datatype, basestring):
datatype = [int(t) for t in datatype.split(',')]
self.datatype = datatype
self.exported = None

def setValue(self, obj):
@@ -1037,12 +1037,12 @@ def getFileFilter(self):

def dataType(self):
types = ''
for shp in self.shapetype:
if shp == self.VECTOR_TYPE_POINT:
for t in self.datatype:
if t == self.VECTOR_TYPE_POINT:
types += 'point, '
elif shp == self.VECTOR_TYPE_LINE:
elif t == self.VECTOR_TYPE_LINE:
types += 'line, '
elif shp == self.VECTOR_TYPE_POLYGON:
elif t == self.VECTOR_TYPE_POLYGON:
types += 'polygon, '
else:
types += 'any, '
@@ -91,7 +91,7 @@ def showLayerSelectionDialog(self):
layers = dataobjects.getTables()
else:
if isinstance(self.param, ParameterVector):
datatype = self.param.shapetype
datatype = self.param.datatype
else:
datatype = [self.param.datatype]
layers = dataobjects.getVectorLayers(datatype)
@@ -114,7 +114,7 @@ def layerAdded(self, layer):
if param.hidden:
continue
if isinstance(param, ParameterVector):
if dataobjects.canUseVectorLayer(layer, param.shapetype):
if dataobjects.canUseVectorLayer(layer, param.datatype):
widget = self.valueItems[param.name]
if isinstance(widget, InputLayerSelectorPanel):
widget = widget.cmbText
@@ -265,7 +265,7 @@ def initWidgets(self):

base_input = self.alg.getParameterFromName(output.base_input)
if isinstance(base_input, ParameterVector):
layers = dataobjects.getVectorLayers(base_input.shapetype)
layers = dataobjects.getVectorLayers(base_input.datatype)
else:
layers = dataobjects.getTables()
if len(layers) > 0:
@@ -300,7 +300,7 @@ def getWidgetFromParameter(self, param):
elif isinstance(param, ParameterVector):
if self.somethingDependsOnThisParameter(param) or self.alg.allowOnlyOpenedLayers:
item = QComboBox()
layers = dataobjects.getVectorLayers(param.shapetype)
layers = dataobjects.getVectorLayers(param.datatype)
layers.sort(key=lambda lay: lay.name())
if param.optional:
item.addItem(self.NOT_SELECTED, None)
@@ -309,7 +309,7 @@ def getWidgetFromParameter(self, param):
item.currentIndexChanged.connect(self.updateDependentFields)
item.name = param.name
else:
layers = dataobjects.getVectorLayers(param.shapetype)
layers = dataobjects.getVectorLayers(param.datatype)
items = []
if param.optional:
items.append((self.NOT_SELECTED, None))
@@ -361,7 +361,7 @@ def getWidgetFromParameter(self, param):
items.append(param)
parent = self.alg.getParameterFromName(param.parent)
if isinstance(parent, ParameterVector):
layers = dataobjects.getVectorLayers(parent.shapetype)
layers = dataobjects.getVectorLayers(parent.datatype)
else:
layers = dataobjects.getTables()
if len(layers) > 0:
@@ -182,7 +182,7 @@ def setupUi(self):
self.shapetypeCombo.addItem(self.tr('Line'))
self.shapetypeCombo.addItem(self.tr('Polygon'))
if self.param is not None:
self.shapetypeCombo.setCurrentIndex(self.param.shapetype[0] + 1)
self.shapetypeCombo.setCurrentIndex(self.param.datatype[0] + 1)
self.horizontalLayoutParent.addWidget(self.shapetypeCombo)
self.verticalLayout.addLayout(self.horizontalLayoutParent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_MULTIPLE or \
@@ -271,13 +271,16 @@ def showAdvancedParametersClicked(self):
self.labels[param.name].setVisible(self.showAdvanced)
self.widgets[param.name].setVisible(self.showAdvanced)

def getAvailableValuesOfType(self, paramType, outType=None):
def getAvailableValuesOfType(self, paramType, outType=None, dataType=None):
values = []
inputs = self.model.inputs
for i in inputs.values():
param = i.param
if isinstance(param, paramType):
values.append(ValueFromInput(param.name))
if subType is not None and param.datatype in dataType:
values.append(ValueFromInput(param.name))
else:
values.append(ValueFromInput(param.name))
if outType is None:
return values
if self._algName is None:
@@ -346,7 +349,13 @@ def getWidgetFromParameter(self, param):
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = self.getAvailableValuesOfType(ParameterVector, OutputVector)
elif aram.datatype == ParameterMultipleInput.TYPE_RASTER:
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POINT:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_POINT])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_LINE:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_LINE])
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_POLYGON:
options = self.getAvailableValuesOfType(ParameterVector, None, [ParameterVector.TYPE_VECTOR_POLYGON])
elif param.datatype == ParameterMultipleInput.TYPE_RASTER:
options = self.getAvailableValuesOfType(ParameterRaster, OutputRaster)
else:
options = self.getAvailableValuesOfType(ParameterFile, OutputFile)

0 comments on commit 7e26124

Please sign in to comment.
You can’t perform that action at this time.