Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jul 13, 2017
1 parent b01ffa5 commit 8285712
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions python/plugins/processing/algs/qgis/Heatmap.py
Expand Up @@ -33,12 +33,12 @@
from qgis.core import (QgsFeatureRequest,
QgsProcessing,
QgsProcessingException,
QgsProcessingUtils,
QgsProcessingParameterVectorLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterField,
QgsProcessingParameterEnum,
QgsProcessingParameterDefinition)
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterDestination)

from qgis.analysis import QgsKernelDensityEstimation

Expand Down Expand Up @@ -164,6 +164,8 @@ 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')))

def processAlgorithm(self, parameters, context, feedback):
layer = self.parameterAsVectorLayer(parameters, self.INPUT_LAYER, context)

Expand All @@ -172,8 +174,8 @@ def processAlgorithm(self, parameters, context, feedback):
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)
output = self.parameterAsOutputLayer(parameters, self.OUTPUT_LAYER, context)
output_format = raster.formatShortNameFromFileName(output)
outputFile = self.parameterAsOutputLayer(parameters, self.OUTPUT_LAYER, 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 All @@ -196,15 +198,15 @@ def processAlgorithm(self, parameters, context, feedback):
kde_params.decayRatio = decay
kde_params.outputValues = output_values

kde = QgsKernelDensityEstimation(kde_params, output, output_format)
kde = QgsKernelDensityEstimation(kde_params, outputFile, output_format)

if kde.prepare() != QgsKernelDensityEstimation.Success:
raise QgsProcessingException(
self.tr('Could not create destination layer'))

request = QgsFeatureRequest()
request.setSubsetOfAttributes(attrs)
features = QgsProcessingUtils.getFeatures(layer, context, request)
features = layer.getFeatures(request)
total = 100.0 / layer.featureCount() if layer.featureCount() else 0
for current, f in enumerate(features):
if feedback.isCanceled():
Expand All @@ -219,4 +221,4 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(
self.tr('Could not save destination layer'))

return {self.OUTPUT_LAYER: output}
return {self.OUTPUT_LAYER: outputFile}

0 comments on commit 8285712

Please sign in to comment.