Skip to content

Commit

Permalink
[processing] adopt algs to use new API call to retrieve GDAL driver
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Aug 1, 2017
1 parent 0476d4e commit 1443590
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/Aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsAspectFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsRasterFileWriter,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
Expand Down Expand Up @@ -75,7 +75,7 @@ def processAlgorithm(self, parameters, context, feedback):

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)
outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

aspect = QgsAspectFilter(inputFile, outputFile, outputFormat)
aspect.setZFactor(zFactor)
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/qgis/CreateConstantRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

__revision__ = '$Format:%H$'

import os
import math
import struct

Expand All @@ -36,7 +37,6 @@
QgsProcessingParameterCrs,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster


class CreateConstantRaster(QgisAlgorithm):
Expand All @@ -62,7 +62,7 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterNumber(self.PIXEL_SIZE,
self.tr('Pixel size'),
QgsProcessingParameterNumber.Double,
0.1, False, 0.001, 999))
0.1, False, 0.01, 999))
self.addParameter(QgsProcessingParameterNumber(self.NUMBER,
self.tr('Constant value'),
QgsProcessingParameterNumber.Double,
Expand All @@ -82,7 +82,7 @@ def processAlgorithm(self, parameters, context, feedback):
pixelSize = self.parameterAsDouble(parameters, self.PIXEL_SIZE, context)

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
outputFormat = raster.formatShortNameFromFileName(outputFile)
outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

rows = max([math.ceil(extent.height() / pixelSize) + 1, 1.0])
cols = max([math.ceil(extent.width() / pixelSize) + 1, 1.0])
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/Heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsFeatureRequest,
QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterFeatureSource,
Expand All @@ -43,7 +44,6 @@
from qgis.analysis import QgsKernelDensityEstimation

from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster

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

Expand Down Expand Up @@ -175,7 +175,7 @@ def processAlgorithm(self, parameters, context, feedback):
decay = self.parameterAsDouble(parameters, self.DECAY, context)
output_values = self.parameterAsEnum(parameters, self.OUTPUT_VALUE, context)
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
output_format = raster.formatShortNameFromFileName(outputFile)
output_format = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])
weight_field = self.parameterAsString(parameters, self.WEIGHT_FIELD, context)
radius_field = self.parameterAsString(parameters, self.RADIUS_FIELD, context)

Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/Hillshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsHillshadeFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsRasterFileWriter,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
Expand Down Expand Up @@ -84,8 +84,7 @@ def processAlgorithm(self, parameters, context, feedback):
vAngle = self.parameterAsDouble(parameters, self.V_ANGLE, context)

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)
outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

hillshade = QgsHillshadeFilter(inputFile, outputFile, outputFormat, azimuth, vAngle)
hillshade.setZFactor(zFactor)
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/Ruggedness.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsRuggednessFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsRasterFileWriter,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
Expand Down Expand Up @@ -75,8 +75,7 @@ def processAlgorithm(self, parameters, context, feedback):
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)
outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

ruggedness = QgsRuggednessFilter(inputFile, outputFile, outputFormat)
ruggedness.setZFactor(zFactor)
Expand Down
7 changes: 3 additions & 4 deletions python/plugins/processing/algs/qgis/Slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsSlopeFilter
from qgis.core import (QgsProcessingParameterRasterLayer,
from qgis.core import (QgsRasterFileWriter,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer


Expand Down Expand Up @@ -75,8 +75,7 @@ def processAlgorithm(self, parameters, context, feedback):
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

outputFormat = raster.formatShortNameFromFileName(outputFile)
outputFormat = QgsRasterFileWriter.driverForExtension(os.path.splitext(outputFile)[1])

slope = QgsSlopeFilter(inputFile, outputFile, outputFormat)
slope.setZFactor(zFactor)
Expand Down

0 comments on commit 1443590

Please sign in to comment.