Skip to content

Commit

Permalink
Merge pull request #4859 from alexbruy/processing-restore
Browse files Browse the repository at this point in the history
[processing] restore most of terrain analysis tools
  • Loading branch information
alexbruy authored Jul 15, 2017
2 parents bbe466f + 671f024 commit 1cb2728
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 107 deletions.
20 changes: 10 additions & 10 deletions python/plugins/processing/algs/qgis/Heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@

class Heatmap(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
RADIUS = 'RADIUS'
RADIUS_FIELD = 'RADIUS_FIELD'
WEIGHT_FIELD = 'WEIGHT_FIELD'
PIXEL_SIZE = 'PIXEL_SIZE'
KERNEL = 'KERNEL'
DECAY = 'DECAY'
OUTPUT_VALUE = 'OUTPUT_VALUE'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'heatmap.png'))
Expand Down Expand Up @@ -88,7 +88,7 @@ def initAlgorithm(self, config=None):
self.OUTPUT_VALUES = OrderedDict([(self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
(self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)])

self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT_LAYER,
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Point layer'),
[QgsProcessing.TypeVectorPoint]))

Expand All @@ -100,7 +100,7 @@ def initAlgorithm(self, config=None):
radius_field_param = QgsProcessingParameterField(self.RADIUS_FIELD,
self.tr('Radius from field'),
None,
self.INPUT_LAYER,
self.INPUT,
QgsProcessingParameterField.Numeric,
optional=True
)
Expand All @@ -118,7 +118,7 @@ def __init__(self, name='', description='', parent_layer=None, radius_param=None

pixel_size_param = ParameterHeatmapPixelSize(self.PIXEL_SIZE,
self.tr('Output raster size'),
parent_layer=self.INPUT_LAYER,
parent_layer=self.INPUT,
radius_param=self.RADIUS,
radius_field_param=self.RADIUS_FIELD,
minValue=0.0,
Expand All @@ -132,7 +132,7 @@ def __init__(self, name='', description='', parent_layer=None, radius_param=None
weight_field_param = QgsProcessingParameterField(self.WEIGHT_FIELD,
self.tr('Weight from field'),
None,
self.INPUT_LAYER,
self.INPUT,
QgsProcessingParameterField.Numeric,
optional=True
)
Expand Down Expand Up @@ -164,17 +164,17 @@ def __init__(self, name='', description='', parent_layer=None, radius_param=None
output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(output_scaling)

self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT_LAYER, self.tr('Heatmap')))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Heatmap')))

def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.INPUT_LAYER, context)
source = self.parameterAsSource(parameters, self.INPUT, context)

radius = self.parameterAsDouble(parameters, self.RADIUS, context)
kernel_shape = self.parameterAsEnum(parameters, self.KERNEL, context)
pixel_size = self.parameterAsDouble(parameters, self.PIXEL_SIZE, context)
decay = self.parameterAsDouble(parameters, self.DECAY, context)
output_values = self.parameterAsEnum(parameters, self.OUTPUT_VALUE, context)
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT_LAYER, context)
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
output_format = raster.formatShortNameFromFileName(outputFile)
weight_field = self.parameterAsString(parameters, self.WEIGHT_FIELD, context)
radius_field = self.parameterAsString(parameters, self.RADIUS_FIELD, context)
Expand Down Expand Up @@ -221,4 +221,4 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(
self.tr('Could not save destination layer'))

return {self.OUTPUT_LAYER: outputFile}
return {self.OUTPUT: outputFile}
49 changes: 27 additions & 22 deletions python/plugins/processing/algs/qgis/Hillshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsHillshadeFilter

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

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


class Hillshade(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
Z_FACTOR = 'Z_FACTOR'
AZIMUTH = 'AZIMUTH'
V_ANGLE = 'V_ANGLE'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
Expand All @@ -58,16 +58,18 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT_LAYER,
self.tr('Elevation layer')))
self.addParameter(ParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), 1.0, 999999.99, 1.0))
self.addParameter(ParameterNumber(self.AZIMUTH,
self.tr('Azimuth (horizontal angle)'), 0.00, 360.00, 300.00))
self.addParameter(ParameterNumber(self.V_ANGLE,
self.tr('Vertical angle'), 1.00, 90.00, 40.00))
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Hillshade')))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterNumber(self.AZIMUTH,
self.tr('Azimuth (horizontal angle)'), QgsProcessingParameterNumber.Double,
300, False, 0, 360))
self.addParameter(QgsProcessingParameterNumber(self.V_ANGLE,
self.tr('Vertical angle'), QgsProcessingParameterNumber.Double,
40, False, 1, 90))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Hillshade')))

def name(self):
return 'hillshade'
Expand All @@ -76,14 +78,17 @@ def displayName(self):
return self.tr('Hillshade')

def processAlgorithm(self, parameters, context, feedback):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
azimuth = self.getParameterValue(self.AZIMUTH)
vAngle = self.getParameterValue(self.V_ANGLE)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)
azimuth = self.parameterAsDouble(parameters, self.AZIMUTH, context)
vAngle = self.parameterAsDouble(parameters, self.V_ANGLE, context)

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

outputFormat = raster.formatShortNameFromFileName(outputFile)

hillshade = QgsHillshadeFilter(inputFile, outputFile, outputFormat, azimuth, vAngle)
hillshade.setZFactor(zFactor)
hillshade.processRaster(None)
hillshade.processRaster(feedback)

return {self.OUTPUT: outputFile}
9 changes: 6 additions & 3 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from .FixGeometry import FixGeometry
from .GridPolygon import GridPolygon
from .Heatmap import Heatmap
from .Hillshade import Hillshade
from .ImportIntoPostGIS import ImportIntoPostGIS
from .ImportIntoSpatialite import ImportIntoSpatialite
from .Intersection import Intersection
Expand All @@ -72,10 +73,12 @@
from .RandomExtract import RandomExtract
from .RandomExtractWithinSubsets import RandomExtractWithinSubsets
from .RegularPoints import RegularPoints
from .Ruggedness import Ruggedness
from .SaveSelectedFeatures import SaveSelectedFeatures
from .SelectByAttribute import SelectByAttribute
from .SelectByExpression import SelectByExpression
from .SimplifyGeometries import SimplifyGeometries
from .Slope import Slope
from .Smooth import Smooth
from .SnapGeometries import SnapGeometriesToLayer
from .SpatialiteExecuteSQL import SpatialiteExecuteSQL
Expand Down Expand Up @@ -146,9 +149,6 @@
# from .Translate import Translate
# from .SingleSidedBuffer import SingleSidedBuffer
# from .PointsAlongGeometry import PointsAlongGeometry
# from .Slope import Slope
# from .Ruggedness import Ruggedness
# from .Hillshade import Hillshade
# from .Relief import Relief
# from .IdwInterpolation import IdwInterpolation
# from .TinInterpolation import TinInterpolation
Expand Down Expand Up @@ -254,6 +254,7 @@ def getAlgs(self):
FixGeometry(),
GridPolygon(),
Heatmap(),
Hillshade(),
ImportIntoPostGIS(),
ImportIntoSpatialite(),
Intersection(),
Expand All @@ -266,10 +267,12 @@ def getAlgs(self):
RandomExtract(),
RandomExtractWithinSubsets(),
RegularPoints(),
Ruggedness(),
SaveSelectedFeatures(),
SelectByAttribute(),
SelectByExpression(),
SimplifyGeometries(),
Slope(),
Smooth(),
SnapGeometriesToLayer(),
SpatialiteExecuteSQL(),
Expand Down
36 changes: 20 additions & 16 deletions python/plugins/processing/algs/qgis/Ruggedness.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsRuggednessFilter

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer

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


class Ruggedness(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
Z_FACTOR = 'Z_FACTOR'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
Expand All @@ -56,12 +56,13 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT_LAYER,
self.tr('Elevation layer')))
self.addParameter(ParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), 1.0, 999999.99, 1.0))
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Ruggedness index')))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'),
QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Ruggedness')))

def name(self):
return 'ruggednessindex'
Expand All @@ -70,12 +71,15 @@ def displayName(self):
return self.tr('Ruggedness index')

def processAlgorithm(self, parameters, context, feedback):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

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

outputFormat = raster.formatShortNameFromFileName(outputFile)

ruggedness = QgsRuggednessFilter(inputFile, outputFile, outputFormat)
ruggedness.setZFactor(zFactor)
ruggedness.processRaster(None)
ruggedness.processRaster(feedback)

return {self.OUTPUT: outputFile}
36 changes: 20 additions & 16 deletions python/plugins/processing/algs/qgis/Slope.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@
from qgis.PyQt.QtGui import QIcon

from qgis.analysis import QgsSlopeFilter

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterNumber
from processing.core.outputs import OutputRaster
from processing.tools import raster
from processing.tools.dataobjects import exportRasterLayer


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


class Slope(QgisAlgorithm):

INPUT_LAYER = 'INPUT_LAYER'
INPUT = 'INPUT'
Z_FACTOR = 'Z_FACTOR'
OUTPUT_LAYER = 'OUTPUT_LAYER'
OUTPUT = 'OUTPUT'

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'dem.png'))
Expand All @@ -56,12 +57,12 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT_LAYER,
self.tr('Elevation layer')))
self.addParameter(ParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), 1.0, 999999.99, 1.0))
self.addOutput(OutputRaster(self.OUTPUT_LAYER,
self.tr('Slope')))
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Elevation layer')))
self.addParameter(QgsProcessingParameterNumber(self.Z_FACTOR,
self.tr('Z factor'), QgsProcessingParameterNumber.Double,
1, False, 1, 999999.99))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Slope')))

def name(self):
return 'slope'
Expand All @@ -70,12 +71,15 @@ def displayName(self):
return self.tr('Slope')

def processAlgorithm(self, parameters, context, feedback):
inputFile = self.getParameterValue(self.INPUT_LAYER)
zFactor = self.getParameterValue(self.Z_FACTOR)
outputFile = self.getOutputValue(self.OUTPUT_LAYER)
inputFile = exportRasterLayer(self.parameterAsRasterLayer(parameters, self.INPUT, context))
zFactor = self.parameterAsDouble(parameters, self.Z_FACTOR, context)

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

outputFormat = raster.formatShortNameFromFileName(outputFile)

slope = QgsSlopeFilter(inputFile, outputFile, outputFormat)
slope.setZFactor(zFactor)
slope.processRaster(None)
slope.processRaster(feedback)

return {self.OUTPUT: outputFile}
Loading

0 comments on commit 1cb2728

Please sign in to comment.