Skip to content
Permalink
Browse files

Port define projection to new API

  • Loading branch information
nyalldawson committed Aug 20, 2017
1 parent cfb926a commit 2a6847e03080e7f11fd2180b34a064baeb2db184
@@ -28,15 +28,12 @@
import os
import re

from qgis.core import (QgsCoordinateReferenceSystem,
QgsApplication,
QgsProcessingUtils)
from qgis.utils import iface
from qgis.core import (QgsProcessing,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterCrs,
QgsProcessingOutputVectorLayer)

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputVector

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

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

INPUT = 'INPUT'
CRS = 'CRS'
OUTPUT = 'OUTPUT'

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

def initAlgorithm(self, config=None):
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input Layer')))
self.addParameter(ParameterCrs(self.CRS, 'Output CRS'))
self.addOutput(OutputVector(self.OUTPUT,
self.tr('Layer with projection'), True))
self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT,
self.tr('Input Layer'), types=[QgsProcessing.TypeVectorAnyGeometry]))
self.addParameter(QgsProcessingParameterCrs(self.CRS, 'Output CRS'))
self.addOutput(QgsProcessingOutputVectorLayer(self.INPUT,
self.tr('Layer with projection')))

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

def processAlgorithm(self, parameters, context, feedback):
fileName = self.getParameterValue(self.INPUT)
layer = QgsProcessingUtils.mapLayerFromString(fileName, context)
crs = QgsCoordinateReferenceSystem(self.getParameterValue(self.CRS))
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
crs = self.parameterAsCrs(parameters, self.CRS, context)

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

layer.setCrs(crs)
iface.mapCanvas().refresh()
layer.triggerRepaint()

self.setOutputValue(self.OUTPUT, fileName)
return {self.INPUT: layer}
@@ -53,6 +53,7 @@
from .CreateAttributeIndex import CreateAttributeIndex
from .CreateConstantRaster import CreateConstantRaster
from .Datasources2Vrt import Datasources2Vrt
from .DefineProjection import DefineProjection
from .Delaunay import Delaunay
from .DeleteColumn import DeleteColumn
from .DeleteDuplicateGeometries import DeleteDuplicateGeometries
@@ -170,7 +171,6 @@
# from .SpatialJoin import SpatialJoin
# from .GeometryConvert import GeometryConvert
# from .SelectByAttributeSum import SelectByAttributeSum
# from .DefineProjection import DefineProjection
# from .RasterCalculator import RasterCalculator
# from .ExecuteSQL import ExecuteSQL

@@ -192,7 +192,6 @@ def getAlgs(self):
# SpatialJoin(),
# GeometryConvert(),
# SelectByAttributeSum()
# DefineProjection(),
# RasterCalculator(),
# ExecuteSQL(),
# ]
@@ -209,6 +208,7 @@ def getAlgs(self):
CreateAttributeIndex(),
CreateConstantRaster(),
Datasources2Vrt(),
DefineProjection(),
Delaunay(),
DeleteColumn(),
DeleteDuplicateGeometries(),

0 comments on commit 2a6847e

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