Skip to content

Commit 2a6847e

Browse files
committedAug 20, 2017
Port define projection to new API
1 parent cfb926a commit 2a6847e

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed
 

‎python/plugins/processing/algs/qgis/DefineProjection.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828
import os
2929
import re
3030

31-
from qgis.core import (QgsCoordinateReferenceSystem,
32-
QgsApplication,
33-
QgsProcessingUtils)
34-
from qgis.utils import iface
31+
from qgis.core import (QgsProcessing,
32+
QgsProcessingParameterVectorLayer,
33+
QgsProcessingParameterCrs,
34+
QgsProcessingOutputVectorLayer)
3535

3636
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
37-
from processing.core.parameters import ParameterVector
38-
from processing.core.parameters import ParameterCrs
39-
from processing.core.outputs import OutputVector
4037

4138
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
4239

@@ -45,7 +42,6 @@ class DefineProjection(QgisAlgorithm):
4542

4643
INPUT = 'INPUT'
4744
CRS = 'CRS'
48-
OUTPUT = 'OUTPUT'
4945

5046
def group(self):
5147
return self.tr('Vector general tools')
@@ -54,11 +50,11 @@ def __init__(self):
5450
super().__init__()
5551

5652
def initAlgorithm(self, config=None):
57-
self.addParameter(ParameterVector(self.INPUT,
58-
self.tr('Input Layer')))
59-
self.addParameter(ParameterCrs(self.CRS, 'Output CRS'))
60-
self.addOutput(OutputVector(self.OUTPUT,
61-
self.tr('Layer with projection'), True))
53+
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
54+
self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry]))
55+
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS'))
56+
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
57+
self.tr('Layer with projection')))
6258

6359
def name(self):
6460
return 'definecurrentprojection'
@@ -67,9 +63,8 @@ def displayName(self):
6763
return self.tr('Define current projection')
6864

6965
def processAlgorithm(self, parameters, context, feedback):
70-
fileName = self.getParameterValue(self.INPUT)
71-
layer = QgsProcessingUtils.mapLayerFromString(fileName, context)
72-
crs = QgsCoordinateReferenceSystem(self.getParameterValue(self.CRS))
66+
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
67+
crs = self.parameterAsCrs(parameters, self.CRS, context)
7368

7469
provider = layer.dataProvider()
7570
ds = provider.dataSourceUri()
@@ -89,6 +84,6 @@ def processAlgorithm(self, parameters, context, feedback):
8984
f.write(wkt)
9085

9186
layer.setCrs(crs)
92-
iface.mapCanvas().refresh()
87+
layer.triggerRepaint()
9388

94-
self.setOutputValue(self.OUTPUT, fileName)
89+
return {self.INPUT: layer}

‎python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from .CreateAttributeIndex import CreateAttributeIndex
5454
from .CreateConstantRaster import CreateConstantRaster
5555
from .Datasources2Vrt import Datasources2Vrt
56+
from .DefineProjection import DefineProjection
5657
from .Delaunay import Delaunay
5758
from .DeleteColumn import DeleteColumn
5859
from .DeleteDuplicateGeometries import DeleteDuplicateGeometries
@@ -170,7 +171,6 @@
170171
# from .SpatialJoin import SpatialJoin
171172
# from .GeometryConvert import GeometryConvert
172173
# from .SelectByAttributeSum import SelectByAttributeSum
173-
# from .DefineProjection import DefineProjection
174174
# from .RasterCalculator import RasterCalculator
175175
# from .ExecuteSQL import ExecuteSQL
176176

@@ -192,7 +192,6 @@ def getAlgs(self):
192192
# SpatialJoin(),
193193
# GeometryConvert(),
194194
# SelectByAttributeSum()
195-
# DefineProjection(),
196195
# RasterCalculator(),
197196
# ExecuteSQL(),
198197
# ]
@@ -209,6 +208,7 @@ def getAlgs(self):
209208
CreateAttributeIndex(),
210209
CreateConstantRaster(),
211210
Datasources2Vrt(),
211+
DefineProjection(),
212212
Delaunay(),
213213
DeleteColumn(),
214214
DeleteDuplicateGeometries(),

0 commit comments

Comments
 (0)
Please sign in to comment.