Skip to content

Commit

Permalink
Port gdal assign projection to new api
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 13, 2017
1 parent 19e5886 commit ab2886d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
21 changes: 11 additions & 10 deletions python/plugins/processing/algs/gdal/AssignProjection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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')
Expand Down
10 changes: 9 additions & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GdalAlgorithm(QgsProcessingAlgorithm):

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

def icon(self):
return QgsApplication.getThemeIcon("/providerGdal.svg")
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

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

0 comments on commit ab2886d

Please sign in to comment.