[processing] added extent as output type and made it available in modeler

This commit is contained in:
Victor Olaya 2013-09-01 11:39:04 +02:00
parent 1655f8efc7
commit d9a9620932
4 changed files with 68 additions and 2 deletions

View File

@ -322,7 +322,7 @@ class GeoAlgorithm:
def setOutputValue(self, outputName, value):
for out in self.outputs:
if out.name == outputName:
out.value = value
out.setValue(value)
def getVisibleOutputsCount(self):
'''returns the number of non-hidden outputs'''

View File

@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.outputs.OutputExtent import OutputExtent
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@ -282,7 +283,23 @@ class ModelerParametersDialog(QtGui.QDialog):
params = self.model.parameters
for param in params:
if isinstance(param, ParameterExtent):
extents.append(AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, param.name, "", param.description))
extents.append(AlgorithmAndParameter(AlgorithmAndParameter.PARENT_MODEL_ALGORITHM, param.name, "", param.description))
if self.algIndex is None:
dependent = []
else:
dependent = self.model.getDependentAlgorithms(self.algIndex)
#dependent.append(self.algIndex)
i=0
for alg in self.model.algs:
if i not in dependent:
for out in alg.outputs:
if isinstance(out, OutputExtent):
extents.append(AlgorithmAndParameter(i, out.name, alg.name, out.description))
i+=1
return extents
def getNumbers(self):

View File

@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from processing.outputs.OutputExtent import OutputExtent
__author__ = 'Victor Olaya'
__date__ = 'January 2013'
__copyright__ = '(C) 2012, Victor Olaya'
@ -34,6 +35,7 @@ class VectorLayerBoundsAlgorithm(GeoAlgorithm):
XMAX = "XMAX"
YMIN = "YMIN"
YMAX = "YMAX"
EXTENT = "EXTENT"
def defineCharacteristics(self):
self.showInModeler = True
@ -45,6 +47,7 @@ class VectorLayerBoundsAlgorithm(GeoAlgorithm):
self.addOutput(OutputNumber(self.XMAX, "max X"))
self.addOutput(OutputNumber(self.YMIN, "min Y"))
self.addOutput(OutputNumber(self.YMAX, "max Y"))
self.addOutput(OutputExtent(self.EXTENT, "Extent"))
def processAlgorithm(self, progress):
uri = self.getParameterValue(self.LAYER)
@ -53,4 +56,6 @@ class VectorLayerBoundsAlgorithm(GeoAlgorithm):
self.setOutputValue(self.XMAX, layer.extent().xMaximum())
self.setOutputValue(self.YMIN, layer.extent().yMinimum())
self.setOutputValue(self.YMAX, layer.extent().yMaximum())
self.setOutputValue(self.EXTENT,
(layer.extent().xMinimum(), layer.extent().xMaximum(), layer.extent().yMinimum(), layer.extent().yMaximum()))

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
OutputNumber.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from processing.outputs.Output import Output
class OutputExtent(Output):
def __init__(self, name="", description=""):
self.name = name
self.description = description
self.value = None
self.hidden = True
def setValue(self, value):
try:
if value != None and isinstance(value, basestring):
value = value.strip()
else:
self.value = ",".join([str(v) for v in value])
return True
except:
return False