def parse_layer_input(param: QgsProcessingParameterDefinition, kwargs, context: MapContext = None) -> LiteralInput: """ Layers input are passed as layer name We treat layer destination the same as input since they refer to layers ids in qgisProject """ if isinstance(param, INPUT_LAYER_TYPES): kwargs['data_type'] = 'string' parse_allowed_layers(param, kwargs, context) elif isinstance(param, QgsProcessingParameterRasterDestination): kwargs['data_type'] = 'string' kwargs['metadata'].append( Metadata('processing:extension', param.defaultFileExtension())) elif isinstance(param, (QgsProcessingParameterVectorDestination, QgsProcessingParameterFeatureSink)): kwargs['data_type'] = 'string' kwargs['metadata'].append( Metadata('processing:dataType', str(param.dataType()))) kwargs['metadata'].append( Metadata('processing:extension', param.defaultFileExtension())) else: return None return LiteralInput(**kwargs)
def parse_file_input(param: QgsProcessingParameterDefinition, kwargs) -> Union[LiteralInput, ComplexInput]: """ Input is file """ typ = param.type() if typ == 'file': if param.behavior() == QgsProcessingParameterFile.Folder: kwargs['data_type'] = 'string' return LiteralInput(**kwargs) ext = param.extension() if ext: mime = mimetypes.types_map.get(param.extension()) if mime is not None: kwargs['supported_formats'] = [Format(mime)] kwargs['metadata'].append( Metadata('processing:extension', param.extension())) return ComplexInput(**kwargs) elif typ == 'fileDestination': extension = '.' + param.defaultFileExtension() kwargs['data_type'] = 'string' kwargs['metadata'].append( Metadata('processing:format', mimetypes.types_map.get(extension, ''))) return LiteralInput(**kwargs) elif typ == 'folderDestination': kwargs['data_type'] = 'string' return LiteralInput(**kwargs)
def get_processing_value(param: QgsProcessingParameterDefinition, inp: WPSInput, context: ProcessingContext) -> Any: """ Return processing value from wps inputs Processes other inputs than layers """ typ = param.type() if typ in ('fileDestination', 'folderDestination'): # Normalize path value = basename(normpath(inp[0].data)) if value != inp[0].data: LOGGER.warning( "Value for file or folder destination '%s' has been truncated from '%s' to '%s'", param.name(), inp[0].data, value) if typ == 'fileDestination': value = Path(value).with_suffix( '.' + param.defaultFileExtension()).as_posix() elif typ == 'file': # Handle file reference outputfile = (Path(context.workdir) / param.name()).with_suffix( param.extension()) LOGGER.debug("Saving input data as %s", outputfile.as_posix()) inp[0].download_ref(outputfile) value = outputfile.name else: value = None return value