diff --git a/python/plugins/processing/core/outputs.py b/python/plugins/processing/core/outputs.py index e70d0cc8fac..02957322d9c 100644 --- a/python/plugins/processing/core/outputs.py +++ b/python/plugins/processing/core/outputs.py @@ -115,6 +115,15 @@ class OutputExtent(Output): return False +class OutputCrs(Output): + + def __init__(self, name='', description=''): + self.name = name + self.description = description + self.value = None + self.hidden = True + + class OutputFile(Output): def __init__(self, name='', description='', ext=None): diff --git a/python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py b/python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py index 35a3c85944e..479099d10bd 100644 --- a/python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py +++ b/python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py @@ -31,6 +31,8 @@ from processing.core.AlgorithmProvider import AlgorithmProvider from processing.modeler.CalculatorModelerAlgorithm import CalculatorModelerAlgorithm from processing.modeler.RasterLayerBoundsAlgorithm import RasterLayerBoundsAlgorithm from processing.modeler.VectorLayerBoundsAlgorithm import VectorLayerBoundsAlgorithm +from processing.modeler.RasterLayerCrsAlgorithm import RasterLayerCrsAlgorithm +from processing.modeler.VectorLayerCrsAlgorithm import VectorLayerCrsAlgorithm pluginPath = os.path.split(os.path.dirname(__file__))[0] @@ -52,6 +54,8 @@ class ModelerOnlyAlgorithmProvider(AlgorithmProvider): def _loadAlgorithms(self): self.algs = [CalculatorModelerAlgorithm(), RasterLayerBoundsAlgorithm(), - VectorLayerBoundsAlgorithm()] + VectorLayerBoundsAlgorithm(), + RasterLayerCrsAlgorithm(), + VectorLayerCrsAlgorithm()] for alg in self.algs: alg.provider = self diff --git a/python/plugins/processing/modeler/ModelerParametersDialog.py b/python/plugins/processing/modeler/ModelerParametersDialog.py index dab939c51c8..985cb63daf3 100644 --- a/python/plugins/processing/modeler/ModelerParametersDialog.py +++ b/python/plugins/processing/modeler/ModelerParametersDialog.py @@ -69,7 +69,8 @@ from processing.core.outputs import (OutputRaster, OutputDirectory, OutputNumber, OutputString, - OutputExtent) + OutputExtent, + OutputCrs) from processing.modeler.ModelerAlgorithm import (ValueFromInput, ValueFromOutput, @@ -384,7 +385,7 @@ class ModelerParametersDialog(QDialog): item.setEditText(unicode(param.default)) elif isinstance(param, ParameterCrs): item = QComboBox() - values = self.getAvailableValuesOfType(ParameterCrs) + values = self.getAvailableValuesOfType(ParameterCrs, OutputCrs) for v in values: item.addItem(self.resolveValueDescription(v), v) elif isinstance(param, ParameterExtent): diff --git a/python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py b/python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py index ec88f7f2ebd..98ecb3908dd 100644 --- a/python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py +++ b/python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py @@ -28,8 +28,8 @@ __revision__ = '$Format:%H$' from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.parameters import ParameterRaster from processing.core.outputs import OutputNumber -from processing.tools import dataobjects from processing.core.outputs import OutputExtent +from processing.tools import dataobjects class RasterLayerBoundsAlgorithm(GeoAlgorithm): diff --git a/python/plugins/processing/modeler/RasterLayerCrsAlgorithm.py b/python/plugins/processing/modeler/RasterLayerCrsAlgorithm.py new file mode 100644 index 00000000000..c5e2136d634 --- /dev/null +++ b/python/plugins/processing/modeler/RasterLayerCrsAlgorithm.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + RasterLayerCrsAlgorithm.py + --------------------- + Date : August 2016 + Copyright : (C) 2016 by Alexander Bruy + Email : alexander dot bruy 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__ = 'Alexander Bruy' +__date__ = 'August 2016' +__copyright__ = '(C) 2016, Alexander Bruy' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from processing.core.GeoAlgorithm import GeoAlgorithm +from processing.core.parameters import ParameterRaster +from processing.core.outputs import OutputCrs +from processing.tools import dataobjects + + +class RasterLayerCrsAlgorithm(GeoAlgorithm): + + LAYER = 'LAYER' + CRS = 'CRS' + + def defineCharacteristics(self): + self.showInModeler = True + self.showInToolbox = False + + self.name = self.tr('Raster layer CRS', 'RasterLayerCrsAlgorithm') + self.group = self.tr('Modeler-only tools', 'RasterLayerCrsAlgorithm') + + self.addParameter(ParameterRaster(self.LAYER, self.tr('Layer', 'RasterLayerCrsAlgorithm'))) + self.addOutput(OutputCrs(self.CRS, self.tr('CRS', 'RasterLayerCrsAlgorithm'))) + + def processAlgorithm(self, progress): + layer = dataobjects.getObjectFromUri(self.getParameterValue(self.LAYER)) + self.setOutputValue(self.CRS, layer.crs().authid()) diff --git a/python/plugins/processing/modeler/VectorLayerCrsAlgorithm.py b/python/plugins/processing/modeler/VectorLayerCrsAlgorithm.py new file mode 100644 index 00000000000..56922021a27 --- /dev/null +++ b/python/plugins/processing/modeler/VectorLayerCrsAlgorithm.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + VectorLayerCrsAlgorithm.py + --------------------- + Date : August 2016 + Copyright : (C) 2016 by Alexander Bruy + Email : alexander dot bruy 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__ = 'Alexander Bruy' +__date__ = 'August 2016' +__copyright__ = '(C) 2016, Alexander Bruy' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from processing.core.GeoAlgorithm import GeoAlgorithm +from processing.core.parameters import ParameterVector +from processing.core.outputs import OutputCrs +from processing.tools import dataobjects + + +class VectorLayerCrsAlgorithm(GeoAlgorithm): + + LAYER = 'LAYER' + CRS = 'CRS' + + def defineCharacteristics(self): + self.showInModeler = True + self.showInToolbox = False + + self.name = self.tr('Vector layer CRS', 'VectorLayerCrsAlgorithm') + self.group = self.tr('Modeler-only tools', 'VectorLayerCrsAlgorithm') + + self.addParameter(ParameterVector(self.LAYER, self.tr('Layer', 'VectorLayerCrsAlgorithm'), )) + self.addOutput(OutputCrs(self.CRS, self.tr('CRS', 'VectorLayerCrsAlgorithm'))) + + def processAlgorithm(self, progress): + layer = dataobjects.getObjectFromUri(self.getParameterValue(self.LAYER)) + self.setOutputValue(self.CRS, layer.crs().authid())