Пример #1
0
def processOutputs(alg, parameters, context, feedback):
    # We take all the outputs and we export them to the output directory
    outputDir = alg.parameterAsString(parameters, 'output_dir', context)
    output = alg.parameterAsString(parameters, 'output', context)
    outfile = alg.parameterAsString(parameters, 'outfile', context)
    outs = []
    if output:
        outs = output.split(',')
    elif outfile:
        # Handle file manually to find the name of the layers
        with open(outfile) as f:
            for line in f:
                if '|' in line:
                    outs.append(line.split('|')[0])

    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)

    for out in outs:
        # We need to export the raster with all its bands and its color table
        fileName = os.path.join(outputDir, out)
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer(out, fileName, True, outFormat, createOpt,
                              metaOpt)
Пример #2
0
def processOutputs(alg, parameters, context, feedback):
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)

    # We need to export the raster with all its bands and its color table
    fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
    outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
    grassName = alg.exportedLayers['input']
    alg.exportRasterLayer(grassName, fileName, True, outFormat, createOpt,
                          metaOpt)
Пример #3
0
def processOutputs(alg, parameters, context, feedback):
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)

    # Export the results from correctedoutput
    grassName = 'correctedoutput{}'.format(alg.uniqueSuffix)
    fileName = alg.parameterAsOutputLayer(parameters, 'routput', context)
    outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
    alg.exportRasterLayer(grassName, fileName, True, outFormat, createOpt,
                          metaOpt)
Пример #4
0
def processOutputs(alg, parameters, context, feedback):
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT, context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META, context)

    # Export all rasters with their color tables (and their bands)
    rasters = alg.parameterAsLayerList(parameters, 'map', context)
    outputDir = alg.parameterAsString(parameters, 'output_dir', context)
    for idx, raster in enumerate(rasters):
        rasterName = 'map_{}'.format(idx)
        fileName = os.path.join(outputDir, rasterName)
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer(alg.exportedLayers[rasterName], fileName, True,
                              outFormat, createOpt, metaOpt)
Пример #5
0
def processOutputs(alg, parameters, context, feedback):
    outputName = alg.parameterAsString(parameters, 'output', context)
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)
    for channel in ['red', 'green', 'blue']:
        fileName = alg.parameterAsOutputLayer(parameters,
                                              '{}output'.format(channel),
                                              context)
        grassName = '{}_{}'.format(outputName, channel)
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer(grassName, fileName, True, outFormat, createOpt,
                              metaOpt)
Пример #6
0
def processOutputs(alg, parameters, context, feedback):
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)
    outputDir = alg.parameterAsString(parameters, 'output_dir', context)
    outputParam = alg.parameterAsString(parameters, 'output', context)
    outputs = outputParam.split(',')

    # We need to export each of the output
    for output in outputs:
        fileName = os.path.join(outputDir, output)
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer(output, fileName, True, outFormat, createOpt,
                              metaOpt)
Пример #7
0
def processOutputs(alg, parameters, context, feedback):
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)

    # Export each color raster
    colors = ['red', 'green', 'blue']
    for color in colors:
        fileName = os.path.normpath(
            alg.parameterAsOutputLayer(parameters, 'output_{}'.format(color),
                                       context))
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer('blended.{}'.format(color[0]), fileName, True,
                              outFormat, createOpt, metaOpt)
Пример #8
0
def exportInputRasters(alg, parameters, context, rasterDic):
    """
    Export input rasters
    Use a dict to make input/output link:
    { 'inputName1': 'outputName1', 'inputName2': 'outputName2'}
    """
    createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT,
                                      context)
    metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META,
                                    context)

    # Get inputs and outputs
    for inputName, outputName in rasterDic.items():
        fileName = os.path.normpath(
            alg.parameterAsOutputLayer(parameters, outputName, context))
        grassName = alg.exportedLayers[inputName]
        outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
        alg.exportRasterLayer(grassName, fileName, True, outFormat, createOpt,
                              metaOpt)