def testParameterCRS(self): param = ParameterCrs("name", "desc") assert param.setValue("EPSG:12003") assert param.value == "EPSG:12003" assert param.setValue(None) assert param.value == param.default s = param.serialize() param2 = ParameterCrs() param2.deserialize(s) assert param.default == param2.default assert param.description == param2.description assert param.name == param2.name
def testParameterCRS(self): param = ParameterCrs('name', 'desc') assert param.setValue('EPSG:12003') assert param.value == 'EPSG:12003' assert param.setValue(None) assert param.value == param.default s = param.serialize() param2 = ParameterCrs() param2.deserialize(s) assert param.default == param2.default assert param.description == param2.description assert param.name == param2.name
def defineCharacteristics(self): self.name = 'Translate (convert format)' self.group = '[GDAL] Conversion' self.addParameter(ParameterRaster(self.INPUT, 'Input layer', False)) self.addParameter(ParameterNumber(self.OUTSIZE, 'Set the size of the output file (In pixels or %)', 1, None, 100)) self.addParameter(ParameterBoolean(self.OUTSIZE_PERC, 'Output size is a percentage of input size', True)) self.addParameter(ParameterString(self.NO_DATA, 'Nodata value, leave as none to take the nodata value from input', 'none')) self.addParameter(ParameterSelection(self.EXPAND, 'Expand', ['none', 'gray', 'rgb', 'rgba'])) self.addParameter(ParameterCrs(self.SRS, 'Override the projection for the output file', None)) self.addParameter(ParameterExtent(self.PROJWIN, 'Subset based on georeferenced coordinates')) self.addParameter(ParameterBoolean(self.SDS, 'Copy all subdatasets of this file to individual output files', False)) self.addParameter(ParameterString(self.EXTRA, 'Additional creation parameters', '')) self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))
def defineCharacteristics(self): self.name = 'Warp (reproject)' self.group = '[GDAL] Projections' self.addParameter(ParameterRaster(self.INPUT, 'Input layer', False)) self.addParameter(ParameterCrs(self.SOURCE_SRS, 'Source SRS (EPSG Code)', 'EPSG:4326')) self.addParameter(ParameterCrs(self.DEST_SRS, 'Destination SRS (EPSG Code)', 'EPSG:4326')) self.addParameter(ParameterNumber(self.TR, 'Output file resolution in target georeferenced units \ (leave 0 for no change)', 0.0, None, 0.0)) self.addParameter(ParameterSelection(self.METHOD, 'Resampling method', self.METHOD_OPTIONS)) self.addParameter(ParameterString(self.EXTRA, 'Additional creation parameters', '', optional=True)) self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))
def buildParametersDialog(self): for input in self.process.inputs: inputType = type(input) if inputType == VectorInput: self.addParameter( ParameterVector(str(input.identifier), str(input.title), ParameterVector.VECTOR_TYPE_ANY, input.minOccurs == 0)) elif inputType == MultipleVectorInput: self.addParameter( ParameterMultipleInput(str(input.identifier), str(input.title), ParameterVector.VECTOR_TYPE_ANY, input.minOccurs == 0)) elif inputType == StringInput: self.addParameter( ParameterString(str(input.identifier), str(input.title))) elif inputType == TextInput: self.addParameter( ParameterString(str(input.identifier), str(input.title))) elif inputType == RasterInput: self.addParameter( ParameterRaster(str(input.identifier), str(input.title), input.minOccurs == 0)) elif inputType == MultipleRasterInput: self.addParameter( ParameterMultipleInput(str(input.identifier), str(input.title), ParameterMultipleInput.TYPE_RASTER, input.minOccurs == 0)) elif inputType == FileInput: #self.addParameter(ParameterFile(str(input.identifier), str(input.title), False, input.minOccurs == 0)) self.addParameter( ParameterFile(str(input.identifier), str(input.title))) elif inputType == MultipleFileInput: pass #Not supported elif inputType == SelectionInput: self.addParameter( ParameterSelection(str(input.identifier), str(input.title), input.valList)) elif inputType == ExtentInput: self.addParameter( ParameterExtent(str(input.identifier), str(input.title))) elif inputType == CrsInput: self.addParameter( ParameterCrs(str(input.identifier), "Projection", None)) for output in self.process.outputs: outputType = type(output) if outputType == VectorOutput: self.addOutput( OutputVector(str(output.identifier), str(output.title))) elif outputType == RasterOutput: self.addOutput( OutputRaster(str(output.identifier), str(output.title))) elif outputType == StringOutput: self.addOutput( OutputString(str(output.identifier), str(output.title)))
def defineCharacteristics(self): self.name = 'Reproject layer' self.group = 'Vector general tools' self.addParameter( ParameterVector(self.INPUT, 'Input layer', [ParameterVector.VECTOR_TYPE_ANY])) self.addParameter( ParameterCrs(self.TARGET_CRS, 'Target CRS', 'EPSG:4326')) self.addOutput(OutputVector(self.OUTPUT, 'Reprojected layer'))
def defineCharacteristics(self): self.name = "Reproject layer" self.group = "Vector general tools" self.addParameter( ParameterVector(self.INPUT, "Input layer", [ParameterVector.VECTOR_TYPE_ANY])) self.addParameter( ParameterCrs(self.TARGET_CRS, "Target CRS", "EPSG:4326")) self.addOutput(OutputVector(self.OUTPUT, "Reprojected layer"))
def defineCharacteristics(self): self.name = "Warp (reproject)" self.group = "[GDAL] Projections" self.addParameter(ParameterRaster(warp.INPUT, "Input layer", False)) self.addParameter( ParameterCrs(warp.SOURCE_SRS, "Source SRS (EPSG Code)", "EPSG:4326")) self.addParameter( ParameterCrs(warp.DEST_SRS, "Destination SRS (EPSG Code)", "EPSG:4326")) self.addParameter( ParameterNumber( warp.TR, "Output file resolution in target georeferenced units (leave 0 for no change)", 0.0, None, 0.0)) self.addParameter( ParameterSelection(warp.METHOD, "Resampling method", warp.METHOD_OPTIONS)) self.addParameter( ParameterString(warp.EXTRA, "Additional creation parameters", "")) self.addOutput(OutputRaster(warp.OUTPUT, "Output layer"))
def defineCharacteristics(self): self.name = "Points layer from table" self.group = "Vector creation tools" self.addParameter(ParameterTable(self.INPUT, "Input layer")) self.addParameter( ParameterTableField(self.XFIELD, "X field", self.INPUT, ParameterTableField.DATA_TYPE_ANY)) self.addParameter( ParameterTableField(self.YFIELD, "Y field", self.INPUT, ParameterTableField.DATA_TYPE_ANY)) self.addParameter( ParameterCrs(self.TARGET_CRS, "Target CRS", "EPSG:4326")) self.addOutput(OutputVector(self.OUTPUT, "Output layer"))
def defineCharacteristics(self): self.name = "Translate (convert format)" self.group = "[GDAL] Conversion" self.addParameter(ParameterRaster(translate.INPUT, "Input layer", False)) self.addParameter(ParameterNumber(translate.OUTSIZE, "Set the size of the output file (In pixels or %)", 1, None, 100)) self.addParameter(ParameterBoolean(translate.OUTSIZE_PERC, "Output size is a percentage of input size", True)) self.addParameter(ParameterString(translate.NO_DATA, "Nodata value, leave as none to take the nodata value from input", "none")) self.addParameter(ParameterSelection(translate.EXPAND, "Expand", ["none","gray","rgb","rgba"])) self.addParameter(ParameterCrs(translate.SRS, "Override the projection for the output file", None)) self.addParameter(ParameterExtent(translate.PROJWIN, "Subset based on georeferenced coordinates")) self.addParameter(ParameterBoolean(translate.SDS, "Copy all subdatasets of this file to individual output files", False)) self.addParameter(ParameterString(translate.EXTRA, "Additional creation parameters", "")) self.addOutput(OutputRaster(translate.OUTPUT, "Output layer"))
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 if line == "nomodeler": self.showInModeler = False tokens = line.split('=', 1) 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() == 'vector point': param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_POINT]) elif tokens[1].lower().strip() == 'vector line': param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_LINE]) elif tokens[1].lower().strip() == 'vector polygon': param = ParameterVector(tokens[0], desc, [ParameterVector.VECTOR_TYPE_POLYGON]) 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], desc, 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('longstring'): default = tokens[1].strip()[len('longstring') + 1:] param = ParameterString(tokens[0], desc, default, multiline=True) elif tokens[1].lower().strip().startswith('crs'): default = tokens[1].strip()[len('crs') + 1:] if not default: default = 'EPSG:4326' param = ParameterCrs(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() subtokens = tokens[1].split(' ') if len(subtokens > 2): out.ext = subtokens[2] elif tokens[1].lower().strip().startswith('output directory'): out = OutputDirectory() elif tokens[1].lower().strip().startswith('output number'): out = OutputNumber() elif tokens[1].lower().strip().startswith('output string'): out = OutputString() if param is not None: self.addParameter(param) elif out is not None: out.name = tokens[0] out.description = desc self.addOutput(out) else: raise WrongScriptException( 'Could not load script:' + self.descriptionFile or '' + '.\n Problem with line "' + line + '"')