i_pansharpen.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. ***************************************************************************
  3. i_pansharpen.py
  4. ---------------
  5. Date : March 2016
  6. Copyright : (C) 2016 by Médéric Ribreux
  7. Email : medspx at medspx dot fr
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Médéric Ribreux'
  18. __date__ = 'March 2016'
  19. __copyright__ = '(C) 2016, Médéric Ribreux'
  20. import os
  21. from qgis.core import QgsProcessingParameterString
  22. from processing.tools.system import getTempFilename
  23. from grassprovider.Grass7Utils import Grass7Utils
  24. def processCommand(alg, parameters, context, feedback):
  25. # Temporary remove outputs and add a virtual output parameter
  26. outputName = 'output_{}'.format(os.path.basename(getTempFilename(context=context)))
  27. param = QgsProcessingParameterString('output', 'virtual output',
  28. outputName, False, False)
  29. alg.addParameter(param)
  30. alg.processCommand(parameters, context, feedback, True)
  31. def processOutputs(alg, parameters, context, feedback):
  32. outputName = alg.parameterAsString(parameters, 'output', context)
  33. createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT, context)
  34. metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META, context)
  35. for channel in ['red', 'green', 'blue']:
  36. fileName = alg.parameterAsOutputLayer(parameters, '{}output'.format(channel), context)
  37. grassName = '{}_{}'.format(outputName, channel)
  38. outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
  39. alg.exportRasterLayer(grassName, fileName, True, outFormat, createOpt, metaOpt)