def defineCharacteristics(self): self.name, self.i18n_name = self.trAlgorithm('Heatmap (Kernel Density Estimation)') self.group, self.i18n_group = self.trAlgorithm('Interpolation') self.tags = self.tr('heatmap,kde,hotspot') self.addParameter(ParameterVector(self.INPUT_LAYER, self.tr('Point layer'), [dataobjects.TYPE_VECTOR_POINT])) self.addParameter(ParameterNumber(self.RADIUS, self.tr('Radius (layer units)'), 0.0, 9999999999, 100.0)) radius_field_param = ParameterTableField(self.RADIUS_FIELD, self.tr('Radius from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER) radius_field_param.isAdvanced = True self.addParameter(radius_field_param) class ParameterHeatmapPixelSize(ParameterNumber): def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None, maxValue=None, default=None, optional=False, metadata={}): ParameterNumber.__init__(self, name, description, minValue, maxValue, default, optional, metadata) self.parent_layer = parent_layer self.radius_param = radius_param self.radius_field_param = radius_field_param self.addParameter(ParameterHeatmapPixelSize(self.PIXEL_SIZE, self.tr('Output raster size'), parent_layer=self.INPUT_LAYER, radius_param=self.RADIUS, radius_field_param=self.RADIUS_FIELD, minValue=0.0, maxValue=9999999999, default=0.1, metadata={'widget_wrapper': HeatmapPixelSizeWidgetWrapper})) weight_field_param = ParameterTableField(self.WEIGHT_FIELD, self.tr('Weight from field'), self.INPUT_LAYER, optional=True, datatype=ParameterTableField.DATA_TYPE_NUMBER) weight_field_param.isAdvanced = True self.addParameter(weight_field_param) kernel_shape_param = ParameterSelection(self.KERNEL, self.tr('Kernel shape'), self.KERNELS) kernel_shape_param.isAdvanced = True self.addParameter(kernel_shape_param) decay_ratio = ParameterNumber(self.DECAY, self.tr('Decay ratio (Triangular kernels only)'), -100.0, 100.0, 0.0) decay_ratio.isAdvanced = True self.addParameter(decay_ratio) output_scaling = ParameterSelection(self.OUTPUT_VALUE, self.tr('Output value scaling'), self.OUTPUT_VALUES) output_scaling.isAdvanced = True self.addParameter(output_scaling) self.addOutput(OutputRaster(self.OUTPUT_LAYER, self.tr('Heatmap')))
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip('\n').strip() self.name = line if '|' in self.name: tokens = self.name.split('|') self.name = tokens[0] #cmdname is the name of the algorithm in SAGA, that is, the name to use to call it in the console self.cmdname = tokens[1] else: self.cmdname = self.name self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name)) #_commandLineName is the name used in processing to call the algorithm #Most of the time will be equal to the cmdname, but in same cases, several processing algorithms #call the same SAGA one self._commandLineName = self.createCommandLineName(self.name) self.name = decoratedAlgorithmName(self.name) self.i18n_name = QCoreApplication.translate("SAGAAlgorithm", str(self.name)) line = lines.readline().strip('\n').strip() self.undecoratedGroup = line self.group = decoratedGroupName(self.undecoratedGroup) self.i18n_group = QCoreApplication.translate("SAGAAlgorithm", self.group) line = lines.readline().strip('\n').strip() while line != '': if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) elif line.startswith('Parameter'): self.addParameter(getParameterFromString(line)) elif line.startswith('AllowUnmatching'): self.allowUnmatchingGridExtents = True elif line.startswith('NoResamplingChoice'): self.noResamplingChoice = True elif line.startswith('Extent'): # An extent parameter that wraps 4 SAGA numerical parameters self.extentParamNames = line[6:].strip().split(' ') self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, 'Output extent')) else: self.addOutput(getOutputFromString(line)) line = lines.readline().strip('\n').strip() hasRaster = False for param in self.parameters: if (isinstance(param, ParameterRaster) or (isinstance(param, ParameterMultipleInput) and param.datatype == ParameterMultipleInput.TYPE_RASTER)): hasRaster = True break if (not self.noResamplingChoice and hasRaster): param = ParameterSelection(self.RESAMPLING, "Resampling method", ["Nearest Neighbour", "Bilinear Interpolation", "Bicubic Spline Interpolation", "B-Spline Interpolation"], 3) param.isAdvanced = True self.addParameter(param)