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 defineCharacteristics(self): self.addParameter(ParameterVector(self.INPUT_LAYER, self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE, dataobjects.TYPE_VECTOR_POLYGON])) self.addParameter(ParameterNumber(self.ANGLE_TOLERANCE, self.tr('Maximum angle tolerance (degrees)'), 0.0, 45.0, 15.0)) max_iterations = ParameterNumber(self.MAX_ITERATIONS, self.tr('Maximum algorithm iterations'), 1, 10000, 1000) max_iterations.isAdvanced = True self.addParameter(max_iterations) self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthogonalized')))
def defineCharacteristics(self): self.name, self.i18n_name = self.trAlgorithm('Orthogonalize') self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools') self.tags = self.tr('rectangle,perpendicular,right,angles,square,quadrilateralise') self.addParameter(ParameterVector(self.INPUT_LAYER, self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE, dataobjects.TYPE_VECTOR_POLYGON])) self.addParameter(ParameterNumber(self.ANGLE_TOLERANCE, self.tr('Maximum angle tolerance (degrees)'), 0.0, 45.0, 15.0)) max_iterations = ParameterNumber(self.MAX_ITERATIONS, self.tr('Maximum algorithm iterations'), 1, 10000, 1000) max_iterations.isAdvanced = True self.addParameter(max_iterations) self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Orthogonalized')))
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Parameter'): parameter = getParameterFromString(line) self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True elif line.startswith('*Parameter'): param = getParameterFromString(line[1:]) param.isAdvanced = True self.addParameter(param) else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 line = lines.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line))) raise e lines.close() self.addParameter(ParameterExtent( self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent')) ) if hasRasterOutput: self.addParameter(ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr('GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
def defineCharacteristicsFromFile(self): with open(self.descriptionFile) as lines: line = lines.readline().strip("\n").strip() self.grass7Name = line line = lines.readline().strip("\n").strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip("\n").strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip("\n").strip() while line != "": try: line = line.strip("\n").strip() if line.startswith("Hardcoded"): self.hardcodedStrings.append(line[len("Hardcoded|") :]) parameter = getParameterFromString(line) if parameter is not None: self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) and parameter.datatype < 3: hasVectorInput = True else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput(OutputFile("rawoutput", output.description + " (raw output)", "txt")) line = lines.readline().strip("\n").strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr("Could not open GRASS GIS 7 algorithm: %s\n%s" % (self.descriptionFile, line)), ) raise e self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, self.tr("GRASS GIS 7 region extent"))) if hasRasterOutput: self.addParameter( ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr("GRASS GIS 7 region cellsize (leave 0 for default)"), 0, None, 0.0, ) ) if hasVectorInput: param = ParameterNumber( self.GRASS_SNAP_TOLERANCE_PARAMETER, "v.in.ogr snap tolerance (-1 = no snap)", -1, None, -1.0 ) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, "v.in.ogr min area", 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, "v.out.ogr output type", self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
def defineCharacteristicsFromFile(self): lines = open(self.descriptionFile) line = lines.readline().strip('\n').strip() self.grass7Name = line line = lines.readline().strip('\n').strip() self.name = line self.i18n_name = QCoreApplication.translate("GrassAlgorithm", line) if " - " not in self.name: self.name = self.grass7Name + " - " + self.name self.i18n_name = self.grass7Name + " - " + self.i18n_name line = lines.readline().strip('\n').strip() self.group = line self.i18n_group = QCoreApplication.translate("GrassAlgorithm", line) hasRasterOutput = False hasVectorInput = False vectorOutputs = 0 line = lines.readline().strip('\n').strip() while line != '': try: line = line.strip('\n').strip() if line.startswith('Hardcoded'): self.hardcodedStrings.append(line[len('Hardcoded|'):]) parameter = getParameterFromString(line) if parameter is not None: self.addParameter(parameter) if isinstance(parameter, ParameterVector): hasVectorInput = True if isinstance(parameter, ParameterMultipleInput) \ and parameter.datatype < 3: hasVectorInput = True else: output = getOutputFromString(line) self.addOutput(output) if isinstance(output, OutputRaster): hasRasterOutput = True elif isinstance(output, OutputVector): vectorOutputs += 1 if isinstance(output, OutputHTML): self.addOutput( OutputFile("rawoutput", output.description + " (raw output)", "txt")) line = lines.readline().strip('\n').strip() except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not open GRASS GIS 7 algorithm: %s\n%s' % (self.descriptionFile, line))) raise e lines.close() self.addParameter( ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, self.tr('GRASS GIS 7 region extent'))) if hasRasterOutput: self.addParameter( ParameterNumber( self.GRASS_REGION_CELLSIZE_PARAMETER, self.tr( 'GRASS GIS 7 region cellsize (leave 0 for default)'), 0, None, 0.0)) if hasVectorInput: param = ParameterNumber(self.GRASS_SNAP_TOLERANCE_PARAMETER, 'v.in.ogr snap tolerance (-1 = no snap)', -1, None, -1.0) param.isAdvanced = True self.addParameter(param) param = ParameterNumber(self.GRASS_MIN_AREA_PARAMETER, 'v.in.ogr min area', 0, None, 0.0001) param.isAdvanced = True self.addParameter(param) if vectorOutputs == 1: param = ParameterSelection(self.GRASS_OUTPUT_TYPE_PARAMETER, 'v.out.ogr output type', self.OUTPUT_TYPES) param.isAdvanced = True self.addParameter(param)
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')))