r_null.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. ***************************************************************************
  3. r_null.py
  4. ---------------------
  5. Date : February 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__ = 'February 2016'
  19. __copyright__ = '(C) 2016, Médéric Ribreux'
  20. def checkParameterValuesBeforeExecuting(alg, parameters, context):
  21. """ Verify if we have the right parameters """
  22. if (alg.parameterAsString(parameters, 'setnull', context)
  23. or alg.parameterAsString(parameters, 'null', context)):
  24. return True, None
  25. return False, alg.tr("You need to set at least 'setnull' or 'null' parameters for this algorithm!")
  26. def processInputs(alg, parameters, context, feedback):
  27. """Prepare the GRASS import commands"""
  28. if 'map' in alg.exportedLayers:
  29. return
  30. # We need to import without r.external
  31. alg.loadRasterLayerFromParameter('map', parameters, context, False)
  32. alg.postInputs(context)
  33. def processCommand(alg, parameters, context, feedback):
  34. # We temporary remove the output 'sequence'
  35. alg.processCommand(parameters, context, feedback, True)
  36. def processOutputs(alg, parameters, context, feedback):
  37. fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
  38. grassName = alg.exportedLayers['map']
  39. alg.exportRasterLayer(grassName, fileName, False)