Skip to content
Permalink
Browse files

Port gdal assign projection to new api

  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent 19e5886 commit ab2886dc6323822c0262e61d4340d74c231443c6
@@ -29,10 +29,10 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterCrs,
QgsProcessingOutputRasterLayer)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterCrs
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils

from processing.tools.system import isWindows
@@ -50,11 +50,11 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
self.addParameter(ParameterCrs(self.CRS,
self.tr('Desired CRS'), ''))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer'), optional=False))
self.addParameter(QgsProcessingParameterCrs(self.CRS,
self.tr('Desired CRS')))

self.addOutput(OutputRaster(self.OUTPUT, self.tr('Layer with projection'), True))
self.addOutput(QgsProcessingOutputRasterLayer(self.OUTPUT, self.tr('Layer with projection')))

def name(self):
return 'assignprojection'
@@ -69,9 +69,10 @@ def group(self):
return self.tr('Raster projections')

def getConsoleCommands(self, parameters, context, feedback):
fileName = self.getParameterValue(self.INPUT)
crs = self.getParameterValue(self.CRS)
output = self.getOutputValue(self.OUTPUT) # NOQA
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fileName = inLayer.source()

crs = self.parameterAsCrs(parameters, self.CRS, context).authid()

arguments = []
arguments.append('-a_srs')
@@ -45,6 +45,7 @@ class GdalAlgorithm(QgsProcessingAlgorithm):

def __init__(self):
super().__init__()
self.output_values = {}

def icon(self):
return QgsApplication.getThemeIcon("/providerGdal.svg")
@@ -89,14 +90,21 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback):
ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
return ogr_data_path, ogr_layer_name

def setOutputValue(self, name, value):
self.output_values[name] = value

def processAlgorithm(self, parameters, context, feedback):
commands = self.getConsoleCommands(parameters, context, feedback)
GdalUtils.runGdal(commands, feedback)

# auto generate outputs
results = {}
for o in self.outputDefinitions():
results[o.name()] = parameters[o.name()]
if o.name() in parameters:
results[o.name()] = parameters[o.name()]
for k, v in self.output_values.items():
results[k]=v

return results

def helpUrl(self):
@@ -33,6 +33,7 @@
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from .GdalUtils import GdalUtils

from .AssignProjection import AssignProjection
from .aspect import aspect
from .warp import warp
# from .nearblack import nearblack
@@ -69,8 +70,7 @@
# from .rasterize_over import rasterize_over
# from .retile import retile
# from .gdal2tiles import gdal2tiles
# from .AssignProjection import AssignProjection
#

from .ogr2ogrpointsonlines import Ogr2OgrPointsOnLines
from .ogr2ogrtopostgis import Ogr2OgrToPostGis

@@ -143,6 +143,7 @@ def loadAlgorithms(self):
self.algs = [
# nearblack(),
# information(),
AssignProjection(),
aspect(),
warp(),
# translate(),
@@ -176,7 +177,6 @@ def loadAlgorithms(self):
# rasterize_over(),
# retile(),
# gdal2tiles(),
# AssignProjection(),
# ----- OGR tools -----
Ogr2OgrPointsOnLines(),
Ogr2OgrToPostGis(),

0 comments on commit ab2886d

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