def defineCharacteristics(self): self.name = "Basic statistics for numeric fields" self.group = "Vector table tools" self.addParameter( ParameterVector(self.INPUT_LAYER, "Input vector layer", ParameterVector.VECTOR_TYPE_ANY, False)) self.addParameter( ParameterTableField(self.FIELD_NAME, "Field to calculate statistics on", self.INPUT_LAYER, ParameterTableField.DATA_TYPE_NUMBER)) self.addOutput( OutputHTML(self.OUTPUT_HTML_FILE, "Statistics for numeric field")) self.addOutput(OutputNumber(self.CV, "Coefficient of Variation")) self.addOutput(OutputNumber(self.MIN, "Minimum value")) self.addOutput(OutputNumber(self.MAX, "Maximum value")) self.addOutput(OutputNumber(self.SUM, "Sum")) self.addOutput(OutputNumber(self.MEAN, "Mean value")) self.addOutput(OutputNumber(self.COUNT, "Count")) self.addOutput(OutputNumber(self.RANGE, "Range")) self.addOutput(OutputNumber(self.MEDIAN, "Median")) self.addOutput(OutputNumber(self.UNIQUE, "Number of unique values")) self.addOutput(OutputNumber(self.STD_DEV, "Standard deviation"))
def defineCharacteristics(self): self.showInModeler = True self.showInToolbox = False self.name = "Raster layer bounds" self.group = "Modeler-only tools" self.addParameter(ParameterRaster(self.LAYER, "Layer")) self.addOutput(OutputNumber(self.XMIN, "min X")) self.addOutput(OutputNumber(self.XMAX, "max X")) self.addOutput(OutputNumber(self.YMIN, "min Y")) self.addOutput(OutputNumber(self.YMAX, "max Y"))
def defineCharacteristics(self): self.name = "Nearest neighbour analysis" self.group = "Analysis tools" self.addParameter(ParameterVector(self.POINTS, "Points", ParameterVector.VECTOR_TYPE_POINT)) self.addOutput(OutputHTML(self.OUTPUT, "Result")) self.addOutput(OutputNumber(self.OBSERVED_MD, "Observed mean distance")) self.addOutput(OutputNumber(self.EXPECTED_MD, "Expected mean distance")) self.addOutput(OutputNumber(self.NN_INDEX, "Nearest neighbour index")) self.addOutput(OutputNumber(self.POINT_COUNT, "Number of points")) self.addOutput(OutputNumber(self.Z_SCORE, "Z-Score"))
def defineCharacteristics(self): self.name = "List unique values" self.group = "Vector table tools" self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY)) self.addParameter(ParameterTableField(self.FIELD_NAME, "Target field", self.INPUT_LAYER, ParameterTableField.DATA_TYPE_ANY)) self.addOutput(OutputHTML(self.OUTPUT, "Unique values")) self.addOutput(OutputNumber(self.TOTAL_VALUES, "Total unique values")) self.addOutput(OutputString(self.UNIQUE_VALUES, "Unique values"))
def defineCharacteristics(self): self.name = "Basic statistics for text fields" self.group = "Analysis tools" self.addParameter( ParameterVector(self.INPUT_LAYER, "Input vector layer", ParameterVector.VECTOR_TYPE_ANY, False)) self.addParameter( ParameterTableField(self.FIELD_NAME, "Field to calculate statistics on", self.INPUT_LAYER, ParameterTableField.DATA_TYPE_STRING)) self.addParameter( ParameterBoolean(self.USE_SELECTION, "Use selection", False)) self.addOutput( OutputHTML(self.OUTPUT_HTML_FILE, "Statistics for text field")) self.addOutput(OutputNumber(self.MIN_LEN, "Minimum length")) self.addOutput(OutputNumber(self.MAX_LEN, "Maximum length")) self.addOutput(OutputNumber(self.MEAN_LEN, "Mean length")) self.addOutput(OutputNumber(self.COUNT, "Count")) self.addOutput(OutputNumber(self.EMPTY, "Number of empty values")) self.addOutput(OutputNumber(self.FILLED, "Number of non-empty values")) self.addOutput(OutputNumber(self.UNIQUE, "Number of unique values"))
def defineCharacteristics(self): self.showInModeler = True self.showInToolbox = False self.name = "Calculator" self.group = "Modeler-only tools" self.addParameter(ParameterString(self.FORMULA, "Formula", "")) for i in range(self.AVAILABLE_VARIABLES): self.addParameter( ParameterNumber(CalculatorModelerAlgorithm.NUMBER + str(i), "dummy")) self.addOutput(OutputNumber(self.RESULT, "Result"))
def defineCharacteristics(self): self.name = "List unique values" self.group = "Analysis tools" self.addParameter( ParameterVector(UniqueValues.INPUT_LAYER, "Input layer", ParameterVector.VECTOR_TYPE_ANY)) self.addParameter( ParameterTableField(UniqueValues.FIELD_NAME, "Targer field", UniqueValues.INPUT_LAYER, ParameterTableField.DATA_TYPE_ANY)) self.addOutput(OutputHTML(UniqueValues.OUTPUT, "Unique values")) self.addOutput( OutputNumber(UniqueValues.TOTAL_VALUES, "Total unique values"))
def defineCharacteristics(self): self.name = "Raster layer statistics" self.group = "Raster tools" self.addParameter(ParameterRaster(self.INPUT, "Input layer")) self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE, "Statistics")) self.addOutput(OutputNumber(self.MIN, "Minimum value")) self.addOutput(OutputNumber(self.MAX, "Maximum value")) self.addOutput(OutputNumber(self.SUM, "Sum")) self.addOutput(OutputNumber(self.MEAN, "Mean value")) self.addOutput(OutputNumber(self.COUNT, "valid cells count")) self.addOutput(OutputNumber(self.COUNT, "No-data cells count")) self.addOutput(OutputNumber(self.STD_DEV, "Standard deviation"))
def processParameterLine(self,line): param = None out = None line = line.replace("#", ""); # If the line is in the format of the text description files for normal algorithms, # then process it using parameter and output factories if '|' in line: self.processDescriptionParameterLine(line) return tokens = line.split("="); desc = self.createDescriptiveName(tokens[0]) if tokens[1].lower().strip() == "group": self.group = tokens[0] return if tokens[1].lower().strip() == "name": self.name = tokens[0] return if tokens[1].lower().strip() == "raster": param = ParameterRaster(tokens[0], desc, False) elif tokens[1].lower().strip() == "vector": param = ParameterVector(tokens[0], desc,ParameterVector.VECTOR_TYPE_ANY) elif tokens[1].lower().strip() == "table": param = ParameterTable(tokens[0], desc, False) elif tokens[1].lower().strip() == "multiple raster": param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_RASTER) param.optional = False elif tokens[1].lower().strip() == "multiple vector": param = ParameterMultipleInput(tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY) param.optional = False elif tokens[1].lower().strip().startswith("selection"): options = tokens[1].strip()[len("selection"):].split(";") param = ParameterSelection(tokens[0], desc, options); elif tokens[1].lower().strip().startswith("boolean"): default = tokens[1].strip()[len("boolean")+1:] param = ParameterBoolean(tokens[0], desc, default) elif tokens[1].lower().strip() == "extent": param = ParameterExtent(tokens[0], desc) elif tokens[1].lower().strip() == "file": param = ParameterFile(tokens[0], desc, False) elif tokens[1].lower().strip() == "folder": param = ParameterFile(tokens[0], desc, True) elif tokens[ 1].lower().strip().startswith("number"): default = tokens[1].strip()[len("number")+1:] param = ParameterNumber(tokens[0], desc, default=default) elif tokens[1].lower().strip().startswith("field"): field = tokens[1].strip()[len("field")+1:] found = False for p in self.parameters: if p.name == field: found = True break if found: param = ParameterTableField(tokens[0], tokens[0], field) elif tokens[1].lower().strip().startswith("string"): default = tokens[1].strip()[len("string")+1:] param = ParameterString(tokens[0], desc, default) elif tokens[1].lower().strip().startswith("output raster"): out = OutputRaster() elif tokens[1].lower().strip().startswith("output vector"): out = OutputVector() elif tokens[1].lower().strip().startswith("output table"): out = OutputTable() elif tokens[1].lower().strip().startswith("output html"): out = OutputHTML() elif tokens[1].lower().strip().startswith("output file"): out = OutputFile() elif tokens[1].lower().strip().startswith("output number"): out = OutputNumber() elif tokens[1].lower().strip().startswith("output string"): out = OutputString() if param != None: self.addParameter(param) elif out != None: out.name = tokens[0] out.description = tokens[0] self.addOutput(out) else: raise WrongScriptException("Could not load script:" + self.descriptionFile + ".\n Problem with line \"" + line + "\"")