def generateCommand(self, parameters, context, feedback): layers = self.parameterAsLayerList(parameters, self.INPUT, context) output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) for l in layers: arguments.append('-i') arguments.append(l.source()) arguments.append('-cr') arguments.append(self.rules[self.parameterAsEnum(parameters, self.RULE, context)][1]) bands = self.parameterAsString(parameters, self.BANDS, context) if bands == '': raise QgsProcessingException(self.tr('Please specify bands to use in composite rule.')) else: arguments.extend(pktoolsUtils.parseCompositeOption('-cb', bands)) if self.ARGUMENTS in parameters and parameters[self.ARGUMENTS] is not None: args = self.parameterAsString(parameters, self.ARGUMENTS, context).split(' ') if args: arguments.extend(args) if self.OPTIONS in parameters and parameters[self.OPTIONS] is not None: options = self.parameterAsString(parameters, self.OPTIONS, context) if options: arguments.extend(pktoolsUtils.parseCreationOptions(options)) arguments.append('-of') arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments
def generateCommand(self, parameters, context, feedback): layer = self.parameterAsRasterLayer(parameters, self.INPUT, context) if layer is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.INPUT)) training = self.parameterAsSource(parameters, self.TRAINING, context) if training is None: raise QgsProcessingException( self.invalidSourceError(parameters, self.TRAINING)) trainLayer, trainLayerName = self.parameterAsCompatibleSourceLayerPathAndLayerName( parameters, self.TRAINING, context, QgsVectorFileWriter.supportedFormatExtensions(), 'gpkg', feedback) output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(layer.source()) arguments.append('-t') arguments.append(trainLayer) if trainLayerName: arguments.append('-tln') arguments.append(trainLayerName) arguments.append('-label') arguments.append( self.parameterAsString(parameters, self.FIELD, context)) if self.NEURONS in parameters and parameters[self.NEURONS] is not None: neurons = self.parameterAsString(parameters, self.NEURONS, context) arguments.extend(pktoolsUtils.parseCompositeOption('-nn', neurons)) if self.N_FOLD in parameters and parameters[self.N_FOLD] is not None: arguments.append('-cv') arguments.append('{}'.format( self.parameterAsInt(parameters, self.N_FOLD, context))) if self.ARGUMENTS in parameters and parameters[ self.ARGUMENTS] is not None: args = self.parameterAsString(parameters, self.ARGUMENTS, context).split(' ') if args: arguments.extend(args) if self.OPTIONS in parameters and parameters[self.OPTIONS] is not None: options = self.parameterAsString(parameters, self.OPTIONS, context) if options: arguments.extend(pktoolsUtils.parseCreationOptions(options)) arguments.append('-of') arguments.append( QgsRasterFileWriter.driverForExtension( os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments
def generateCommand(self, parameters, context, feedback): layer = self.parameterAsRasterLayer(parameters, self.INPUT, context) if layer is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.INPUT)) samples = self.parameterAsRasterLayer(parameters, self.SAMPLES, context) if samples is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.SAMPLES)) output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(layer.source()) arguments.append('-s') arguments.append(samples.source()) if self.THRESHOLD in parameters and parameters[ self.THRESHOLD] is not None: arguments.append('-t') arguments.append('{}'.format( self.parameterAsDouble(parameters, self.THRESHOLD, context))) if self.CLASSES in parameters and parameters[self.CLASSES] is not None: classes = self.parameterAsString(parameters, self.CLASSES, context) arguments.extend(pktoolsUtils.parseCompositeOption('-c', classes)) if self.ARGUMENTS in parameters and parameters[ self.ARGUMENTS] is not None: args = self.parameterAsString(parameters, self.ARGUMENTS, context).split(' ') if args: arguments.extend(args) arguments.append('-f') arguments.append( QgsVectorFileWriter.driverForExtension( os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments
def generateCommand(self, parameters, context, feedback): layer, layerName = self.parameterAsCompatibleSourceLayerPathAndLayerName( parameters, self.INPUT, context, QgsVectorFileWriter.supportedFormatExtensions(), 'gpkg', feedback) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(layer) if layerName: arguments.append('-ln') arguments.append(layerName) useFields = False if self.FIELDS in parameters and parameters[self.FIELDS] is not None: fields = self.parameterAsString(parameters, self.FIELDS, context) if fields: arguments.extend( pktoolsUtils.parseCompositeOption('-n', fields)) useFields = True if self.SEPARATOR in parameters and parameters[ self.SEPARATOR] is not None: sep = self.parameterAsString(parameters, self.SEPARATOR, context) if sep: arguments.append('-fs') arguments.append(sep) if self.parameterAsBoolean(parameters, self.POSITION, context): arguments.append('-pos') if self.parameterAsBoolean(parameters, self.TRANSPOSE, context): if not useFields: raise QgsProcessingException( self. tr('Transposing output only possible in combination with "-n" parameter.' )) else: arguments.append('-t') arguments.append('-o') arguments.append( self.parameterAsFileOutput(parameters, self.OUTPUT, context)) return arguments
def generateCommand(self, parameters, context, feedback): layer = self.parameterAsRasterLayer(parameters, self.INPUT, context) if layer is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.INPUT)) mask = self.parameterAsRasterLayer(parameters, self.MASK, context) if mask is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.MASK)) bands = self.parameterAsInts(parameters, self.BANDS, context) bands = [b - 1 for b in bands] output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(layer.source()) arguments.append('-m') arguments.append(mask.source()) arguments.extend(pktoolsUtils.parseCompositeOption('-b', bands)) arguments.append('-d') arguments.append('{}'.format( self.parameterAsInt(parameters, self.DISTANCE, context))) arguments.append('-it') arguments.append('{}'.format( self.parameterAsInt(parameters, self.ITERATIONS, context))) arguments.append('-of') arguments.append( QgsRasterFileWriter.driverForExtension( os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments
def generateCommand(self, parameters, context, feedback): crs = self.parameterAsCrs(parameters, self.CRS, context) bbox = self.parameterAsExtent(parameters, self.EXTENT, context, crs) output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(self.parameterAsFile(parameters, self.INPUT, context)) arguments.append('-n') arguments.append(self.attributes[self.parameterAsEnum( parameters, self.ATTRIBUTE, context)][1]) arguments.append('-comp') arguments.append(self.composites[self.parameterAsEnum( parameters, self.COMPOSITE, context)][1]) arguments.append('-fir') arguments.append(self.filters[self.parameterAsEnum( parameters, self.FILTER, context)][1]) arguments.append('-ulx') arguments.append('{}'.format(bbox.xMinimum())) arguments.append('-uly') arguments.append('{}'.format(bbox.yMaximum())) arguments.append('-lrx') arguments.append('{}'.format(bbox.xMaximum())) arguments.append('-lry') arguments.append('{}'.format(bbox.yMinimum())) arguments.append('-dx') arguments.append('{}'.format( self.parameterAsDouble(parameters, self.SIZE_X, context))) arguments.append('-dy') arguments.append('{}'.format( self.parameterAsDouble(parameters, self.SIZE_Y, context))) arguments.append('-a_srs') arguments.append(crs.authid()) if self.CLASSES in parameters and parameters[self.CLASSES] is not None: classes = self.parameterAsString(parameters, self.CLASSES, context) if classes != '': arguments.extend( pktoolsUtils.parseCompositeOption('-class', classes)) if self.ARGUMENTS in parameters and parameters[ self.ARGUMENTS] is not None: args = self.parameterAsString(parameters, self.ARGUMENTS, context).split(' ') if args: arguments.extend(args) if self.OPTIONS in parameters and parameters[self.OPTIONS] is not None: options = self.parameterAsString(parameters, self.OPTIONS, context) if options: arguments.extend(pktoolsUtils.parseCreationOptions(options)) arguments.append('-of') arguments.append( QgsRasterFileWriter.driverForExtension( os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments
def generateCommand(self, parameters, context, feedback): layer = self.parameterAsRasterLayer(parameters, self.INPUT, context) if layer is None: raise QgsProcessingException( self.invalidRasterError(parameters, self.INPUT)) rule = self.rules[self.parameterAsEnum(parameters, self.RULE, context)][1] if rule in ('mode', 'proportion', 'count') and (self.CLASSES not in parameters or parameters[self.CLASSES] is None): raise QgsProcessingException( self. tr('Please specify classes to extract or choose another extraction rule.' )) if rule == 'percentile' and (self.PERCENTILE not in parameters or parameters[self.PERCENTILE] is None): raise QgsProcessingException( self. tr('Please specify percentile or choose another extraction rule.' )) output = self.parameterAsOutputLayer(parameters, self.OUTPUT, context) arguments = [] arguments.append(self.commandName()) arguments.append('-i') arguments.append(layer.source()) arguments.append('-rand') arguments.append('{}'.format( self.parameterAsInt(parameters, self.COUNT, context))) arguments.append('-buf') arguments.append('{}'.format( self.parameterAsInt(parameters, self.BUFFER, context))) arguments.append('-r') arguments.append(rule) if rule in ('mode', 'proportion', 'count'): classes = self.parameterAsString(parameters, self.CLASSES, context) arguments.extend(pktoolsUtils.parseCompositeOption('-c', classes)) if rule == 'percentile': arguments.append('-perc') arguments.append('{}'.format( self.parameterAsDouble(parameters, self.PERCENTILE, context))) if self.THRESHOLD in parameters and parameters[ self.THRESHOLD] is not None: arguments.append('-t') arguments.append('{}'.format( self.parameterAsDouble(parameters, self.THRESHOLD, context))) if self.ARGUMENTS in parameters and parameters[ self.ARGUMENTS] is not None: args = self.parameterAsString(parameters, self.ARGUMENTS, context).split(' ') if args: arguments.extend(args) arguments.append('-f') arguments.append( QgsVectorFileWriter.driverForExtension( os.path.splitext(output)[1])) arguments.append('-o') arguments.append(output) return arguments