v_rectify.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """
  2. ***************************************************************************
  3. v_rectify.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 grassprovider.Grass7Utils import Grass7Utils
  22. from processing.tools.system import getTempFilename
  23. def checkParameterValuesBeforeExecuting(alg, parameters, context):
  24. """ Verify if we have the right parameters """
  25. if (alg.parameterAsString(parameters, 'inline_points', context)
  26. and alg.parameterAsString(parameters, 'points', context)):
  27. return False, alg.tr("You need to set either an input control point file or inline control points!")
  28. return True, None
  29. def processCommand(alg, parameters, context, feedback):
  30. # handle inline points
  31. inlinePoints = alg.parameterAsString(parameters, 'inline_points', context)
  32. if inlinePoints:
  33. # Creates a temporary txt file
  34. pointsName = getTempFilename(context=context)
  35. # Inject rules into temporary txt file
  36. with open(pointsName, "w") as tempPoints:
  37. tempPoints.write(inlinePoints)
  38. alg.removeParameter('inline_points')
  39. parameters['points'] = pointsName
  40. alg.processCommand(parameters, context, feedback)