Skip to content

Commit 4c39bd1

Browse files
committed
[processing] introduce OutputCrs output and add algorithms to get layer CRS in modeler
1 parent 40de15c commit 4c39bd1

6 files changed

+120
-4
lines changed

python/plugins/processing/core/outputs.py

+9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ def setValue(self, value):
115115
return False
116116

117117

118+
class OutputCrs(Output):
119+
120+
def __init__(self, name='', description=''):
121+
self.name = name
122+
self.description = description
123+
self.value = None
124+
self.hidden = True
125+
126+
118127
class OutputFile(Output):
119128

120129
def __init__(self, name='', description='', ext=None):

python/plugins/processing/modeler/ModelerOnlyAlgorithmProvider.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from processing.modeler.CalculatorModelerAlgorithm import CalculatorModelerAlgorithm
3232
from processing.modeler.RasterLayerBoundsAlgorithm import RasterLayerBoundsAlgorithm
3333
from processing.modeler.VectorLayerBoundsAlgorithm import VectorLayerBoundsAlgorithm
34+
from processing.modeler.RasterLayerCrsAlgorithm import RasterLayerCrsAlgorithm
35+
from processing.modeler.VectorLayerCrsAlgorithm import VectorLayerCrsAlgorithm
3436

3537
pluginPath = os.path.split(os.path.dirname(__file__))[0]
3638

@@ -52,6 +54,8 @@ def getIcon(self):
5254
def _loadAlgorithms(self):
5355
self.algs = [CalculatorModelerAlgorithm(),
5456
RasterLayerBoundsAlgorithm(),
55-
VectorLayerBoundsAlgorithm()]
57+
VectorLayerBoundsAlgorithm(),
58+
RasterLayerCrsAlgorithm(),
59+
VectorLayerCrsAlgorithm()]
5660
for alg in self.algs:
5761
alg.provider = self

python/plugins/processing/modeler/ModelerParametersDialog.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
OutputDirectory,
7070
OutputNumber,
7171
OutputString,
72-
OutputExtent)
72+
OutputExtent,
73+
OutputCrs)
7374

7475
from processing.modeler.ModelerAlgorithm import (ValueFromInput,
7576
ValueFromOutput,
@@ -384,7 +385,7 @@ def getWidgetFromParameter(self, param):
384385
item.setEditText(unicode(param.default))
385386
elif isinstance(param, ParameterCrs):
386387
item = QComboBox()
387-
values = self.getAvailableValuesOfType(ParameterCrs)
388+
values = self.getAvailableValuesOfType(ParameterCrs, OutputCrs)
388389
for v in values:
389390
item.addItem(self.resolveValueDescription(v), v)
390391
elif isinstance(param, ParameterExtent):

python/plugins/processing/modeler/RasterLayerBoundsAlgorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from processing.core.GeoAlgorithm import GeoAlgorithm
2929
from processing.core.parameters import ParameterRaster
3030
from processing.core.outputs import OutputNumber
31-
from processing.tools import dataobjects
3231
from processing.core.outputs import OutputExtent
32+
from processing.tools import dataobjects
3333

3434

3535
class RasterLayerBoundsAlgorithm(GeoAlgorithm):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
RasterLayerCrsAlgorithm.py
6+
---------------------
7+
Date : August 2016
8+
Copyright : (C) 2016 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'August 2016'
22+
__copyright__ = '(C) 2016, Alexander Bruy'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from processing.core.GeoAlgorithm import GeoAlgorithm
29+
from processing.core.parameters import ParameterRaster
30+
from processing.core.outputs import OutputCrs
31+
from processing.tools import dataobjects
32+
33+
34+
class RasterLayerCrsAlgorithm(GeoAlgorithm):
35+
36+
LAYER = 'LAYER'
37+
CRS = 'CRS'
38+
39+
def defineCharacteristics(self):
40+
self.showInModeler = True
41+
self.showInToolbox = False
42+
43+
self.name = self.tr('Raster layer CRS', 'RasterLayerCrsAlgorithm')
44+
self.group = self.tr('Modeler-only tools', 'RasterLayerCrsAlgorithm')
45+
46+
self.addParameter(ParameterRaster(self.LAYER, self.tr('Layer', 'RasterLayerCrsAlgorithm')))
47+
self.addOutput(OutputCrs(self.CRS, self.tr('CRS', 'RasterLayerCrsAlgorithm')))
48+
49+
def processAlgorithm(self, progress):
50+
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.LAYER))
51+
self.setOutputValue(self.CRS, layer.crs().authid())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
VectorLayerCrsAlgorithm.py
6+
---------------------
7+
Date : August 2016
8+
Copyright : (C) 2016 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'August 2016'
22+
__copyright__ = '(C) 2016, Alexander Bruy'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
from processing.core.GeoAlgorithm import GeoAlgorithm
29+
from processing.core.parameters import ParameterVector
30+
from processing.core.outputs import OutputCrs
31+
from processing.tools import dataobjects
32+
33+
34+
class VectorLayerCrsAlgorithm(GeoAlgorithm):
35+
36+
LAYER = 'LAYER'
37+
CRS = 'CRS'
38+
39+
def defineCharacteristics(self):
40+
self.showInModeler = True
41+
self.showInToolbox = False
42+
43+
self.name = self.tr('Vector layer CRS', 'VectorLayerCrsAlgorithm')
44+
self.group = self.tr('Modeler-only tools', 'VectorLayerCrsAlgorithm')
45+
46+
self.addParameter(ParameterVector(self.LAYER, self.tr('Layer', 'VectorLayerCrsAlgorithm'), ))
47+
self.addOutput(OutputCrs(self.CRS, self.tr('CRS', 'VectorLayerCrsAlgorithm')))
48+
49+
def processAlgorithm(self, progress):
50+
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.LAYER))
51+
self.setOutputValue(self.CRS, layer.crs().authid())

0 commit comments

Comments
 (0)