1

I'm trying to run the i.topo.corr algorithm in the QGIS Python console, on a multi-band WorldView image. I'm still getting an error that the input value is incorrect. For this algorithm, the inputs are the bands on which the algorithm will be applied:

input: Name of reflectance raster maps to be corrected topographically

Parameter type: QgsProcessingParameterMultipleLayers

Accepted data types:
    - list[str]: list of layer identifiers
    - list[str]: list of layer names
    - list[str]: layer source list
    - list[QgsMapLayer]
    - QgsProperty

According to the documentation (https://docs.qgis.org/3.4/en/docs/user_manual/processing/console.html#processing-console), the value for a multiple input is:

« Multiple input. The value is a string with input descriptors separated by semicolons (;). As in the case of single layers or tables, each input descriptor can be the data object name, or its file path. Simply use a string with the name that identifies the data object to use (the name it has in the QGIS Table of Contents) or a filename. »

There is my code in QGIS Python console. I don't know how to refer to the bands of my image in the input parameter:

import processing

processing.run("grass7:i.topo.corr", {'INPUT': 'ImageName_band1';'ImageName_band2';'ImageName_band3',
    'BASEMAP': 'Illumination_model_name',
    'ZENITH': 69.7,
    'METHOD': 2,
    'OUTPUT': r'output_directory'})

I tried many thing for the bands in imput parameter: imageName.1, imageName_1, imageName@1, imageName_B1, etc.

1 Answer 1

1

If each band of the multiband raster exists as independent files in your hardrive then you can list those files names. Example as list:

input = ['C:/Users/Eloisa/band1.tif', 'C:/Users/Eloisa/band2.tif', 'C:/Users/Eloisa/band3.tif']

If you only have the multiband raster then you can extract each single band using GDAL. Assuming your image is a TIFF:

from osgeo import gdal
multiband = 'C:/Users/Javier/multibanda.tif'
in_ds = gdal.Open(multiband)
gtiff_driver = gdal.GetDriverByName('GTiff')
for i in range(1, in_ds.RasterCount+1):
    in_band = in_ds.GetRasterBand(i)
    out_ds = gtiff_driver.Create('C:/Users/Javier/band{0}.tif'.format(i), in_band.XSize, in_band.YSize, 1, in_band.DataType)
    out_ds.SetProjection(in_ds.GetProjection())
    out_ds.SetGeoTransform(in_ds.GetGeoTransform())
    in_data = in_band.ReadAsArray()
    out_band = out_ds.GetRasterBand(1)
    out_band.WriteArray(in_data)
out_ds.FlushCache()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.