SHARE
TWEET

Untitled

a guest Jun 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from qgis.core import QgsProcessing
  2. from qgis.core import QgsProcessingAlgorithm
  3. from qgis.core import QgsProcessingMultiStepFeedback
  4. from qgis.core import QgsProcessingParameterBand
  5. from qgis.core import QgsProcessingParameterRasterLayer
  6. from qgis.core import QgsProcessingParameterNumber
  7. from qgis.core import QgsProcessingParameterRasterDestination
  8. import processing
  9.  
  10.  
  11. class RasterCalculator(QgsProcessingAlgorithm):
  12.  
  13. def initAlgorithm(self, config=None):
  14.     self.addParameter(QgsProcessingParameterBand('band', 'band', parentLayerParameterName='rasterlayer', allowMultiple=False, defaultValue=None))
  15.     self.addParameter(QgsProcessingParameterRasterLayer('rasterlayer', 'layer', defaultValue=None))
  16.     self.addParameter(QgsProcessingParameterNumber('refadd', 'refadd', type=QgsProcessingParameterNumber.Double, defaultValue=-0.1))
  17.     self.addParameter(QgsProcessingParameterNumber('refmult', 'refmult', type=QgsProcessingParameterNumber.Double, defaultValue=2E-5))
  18.     self.addParameter(QgsProcessingParameterNumber('sunel', 'sunel', type=QgsProcessingParameterNumber.Double, defaultValue=60))
  19.     self.addParameter(QgsProcessingParameterRasterDestination('Reflectance', 'reflectance', createByDefault=True, defaultValue=None))
  20.  
  21. def processAlgorithm(self, parameters, context, model_feedback):
  22.     # Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
  23.     # overall progress through the model
  24.     feedback = QgsProcessingMultiStepFeedback(1, model_feedback)
  25.     results = {}
  26.     outputs = {}
  27.  
  28.     # Raster calculator
  29.     alg_params = {
  30.         'BAND_A': 1,
  31.         'BAND_B': None,
  32.         'BAND_C': None,
  33.         'BAND_D': None,
  34.         'BAND_E': None,
  35.         'BAND_F': None,
  36.         'FORMULA': '(A* refmult +(refadd) ) /( sin(sunel * 3.14159/180  ) )',
  37.         'INPUT_A': parameters['rasterlayer'],
  38.         'INPUT_B': None,
  39.         'INPUT_C': None,
  40.         'INPUT_D': None,
  41.         'INPUT_E': None,
  42.         'INPUT_F': None,
  43.         'NO_DATA': None,
  44.         'OPTIONS': '',
  45.         'RTYPE': 5,
  46.         'OUTPUT': parameters['Reflectance']
  47.     }
  48.     outputs['RasterCalculator'] = processing.run('gdal:rastercalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
  49.     results['Reflectance'] = outputs['RasterCalculator']['OUTPUT']
  50.     return results
  51.  
  52. def name(self):
  53.     return 'raster calculator'
  54.  
  55. def displayName(self):
  56.     return 'raster calculator'
  57.  
  58. def group(self):
  59.     return 'remote sensing'
  60.  
  61. def groupId(self):
  62.     return 'remote sensing'
  63.  
  64. def createInstance(self):
  65.     return RasterCalculator()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top