Ciao Andrea e intanto grazie.

Faccio prima ad allegare tutto lo script.
Probabilmente adesso hai una visione d'insieme più chiara

In pratica lo script dovrebbe prendere un multilayer raster, convertire
tutte le bande in decibel e rifare lo stack

Non capisco perchè QGIS tenti di aggiungere vettoriali, dato che nello
script non sono contemplati layer vettoriali.

Di nuovo grazie

giacomo


Il giorno gio 16 dic 2021 alle ore 16:11 Andrea Giudiceandrea <
andreaer...@libero.it> ha scritto:

> Il 16/12/2021 14:42, Andrea Giudiceandrea ha scritto:
> > Comunque ho corretto gli errori e ho messo il tuo pezzo di script
> > all'interno di un algoritmo generico adattandolo per l'occorrenza e
> > aggiungendo quello che mancava, e non riscontro il problema da te
> > riscontrato e le operazioni vanno a buon fine senza che si tenti di
> > aggiungere layer inutili alla mappa.
>
> Ops.. mi correggo.
> Non riscontro l'errore:
> "I seguenti layer non sono stati generati correttamente
> • /tmp/processing_xWeKZC/c39d842bacba4a1a824e685ea21c8b5c/OUTPUT.tif
> Puoi verificare il "Pannello dei messaggi" nella finestra principale di
> QGIS per trovare maggiori informazioni circa l'esecuzione dell'algoritmo".
>
> Invece effettivamente riscontro gli avvisi "Warning" nel pannello OGR.
> Questi avvisi non sono però legati all'errore relativo al layer non
> generato correttamente.
> _______________________________________________
> QGIS-it-user mailing list
> QGIS-it-user@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/qgis-it-user
>
def initAlgorithm(self, config=None):

        # 3A Input stack
        self.addParameter(QgsProcessingParameterRasterLayer(
            self.INPUT,
            self.tr('Input linear stack'),
            None,
            False))
                
        # 3B Output raster
        self.addParameter(QgsProcessingParameterRasterDestination(
            self.OUTPUT,
            self.tr('Output dB stack')))
            
    # --------------------------------------------------------------------------------------------------------------------
    # 4 ----------------------------------------- Import layers ----------------------------------------------------
    # --------------------------------------------------------------------------------------------------------------------
    
    # 4A
    def processAlgorithm(
        self, 
        parameters, 
        context, 
        feedback):

       # 4B Input string 
        pathStackIn = self.parameterAsString(
            parameters,
            self.INPUT,
            context)

       # 4C Output stack 
        stackOut = self.parameterAsOutputLayer(
            parameters, 
            self.OUTPUT, 
            context)
 
        # -------------------------------------------------------------------------------------------------------------
        # 5 ------------------------------------- Check -----------------------------------------------------------
        # -------------------------------------------------------------------------------------------------------------
        
        # 5A If source was not found, throw an exception
        if pathStackIn is None:
            raise QgsProcessingException(self.invalidSourceError(parameters, INPUT))
   
        # 5B Check for cancelation
        if feedback.isCanceled():
            return {}

        # -------------------------------------------------------------------------------------------------------------
        # 6 -------------------------------------- Processing ----------------------------------------------------
        # -------------------------------------------------------------------------------------------------------------    
        
        #6A deriving input stack
        stackIn = QgsRasterLayer(pathStackIn, "stack")

        # 6B loop over the bands
        nBand = stackIn.bandCount()
        
        bandList = []

        for band in range(1, nBand+1):
        
            # 6C db calculation 
            operation = "10 * ( log10 ( " + pathStackIn + "@" + str(band) + " ) )"
            
            parametersCalc = {
                "EXPRESSION": operation,
                "LAYERS": stackIn,
                "CELLSIZE": None,
                "EXTENT": None,
                "CRS": None,
                "OUTPUT": "TEMPORARY_OUTPUT"}

            # 6D
            outRas = processing.run(
                'qgis:rastercalculator',
                parametersCalc,
                is_child_algorithm = True,
                context = context,
                feedback = feedback)

            # 6E 
            bandList.append(outRas["OUTPUT"])
 
            # 6F Check for cancelation
            if feedback.isCanceled():
                return {}

        # 6G stacking
        parametersStack = {
            "INPUT": bandList,
            "PCT": False,
            "SEPARATE": True,
            "NODATA_INPUT": None,
            "NODATA_OUTPUT": None,
            "OPTIONS":"",
            "EXTRA":"",
            "DATA_TYPE": 5,
            "OUTPUT": parameters[self.OUTPUT]}

        # 6H
        outStack = processing.run(
            'gdal:merge', 
            parametersStack,
            is_child_algorithm = True,
            context = context,
            feedback = feedback)
            
        # 6I Check for cancelation
        if feedback.isCanceled():
            return {}
            
        return {self.OUTPUT: outStack["OUTPUT"]}
_______________________________________________
QGIS-it-user mailing list
QGIS-it-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/qgis-it-user

Rispondere a