v_edit.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. ***************************************************************************
  3. v_edit.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 processing.tools.system import getTempFilename
  22. def checkParameterValuesBeforeExecuting(alg, parameters, context):
  23. """ Verify if we have the right parameters """
  24. if (alg.parameterAsString(parameters, 'input_txt', context)
  25. and alg.parameterAsString(parameters, 'input', context)):
  26. return False, alg.tr("You need to set either an input ASCII file or inline data!")
  27. return True, None
  28. def processCommand(alg, parameters, context, feedback):
  29. # Handle inline rules
  30. txtRules = alg.parameterAsString(parameters, 'input_txt', context)
  31. if txtRules:
  32. # Creates a temporary txt file
  33. tempRulesName = getTempFilename(context=context)
  34. # Inject rules into temporary txt file
  35. with open(tempRulesName, "w") as tempRules:
  36. tempRules.write(txtRules)
  37. alg.removeParameter('input_txt')
  38. parameters['input'] = tempRulesName
  39. alg.processCommand(parameters, context, feedback, True)
  40. def processOutputs(alg, parameters, context, feedback):
  41. # We need to add the from layer to outputs:
  42. fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
  43. grassName = alg.exportedLayers['map']
  44. dataType = 'auto'
  45. alg.exportVectorLayer(grassName, fileName, dataType=dataType)