outputs.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """
  2. ***************************************************************************
  3. Output.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf at gmail dot com
  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__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. import sys
  21. from qgis.core import (QgsExpressionContext,
  22. QgsExpressionContextUtils,
  23. QgsExpression,
  24. QgsExpressionContextScope,
  25. QgsProject,
  26. QgsSettings,
  27. QgsVectorFileWriter,
  28. QgsProcessingUtils,
  29. QgsProcessingParameterDefinition,
  30. QgsProcessingOutputRasterLayer,
  31. QgsProcessingOutputVectorLayer,
  32. QgsProcessingOutputMapLayer,
  33. QgsProcessingOutputHtml,
  34. QgsProcessingOutputNumber,
  35. QgsProcessingOutputString,
  36. QgsProcessingOutputBoolean,
  37. QgsProcessingOutputFolder,
  38. QgsProcessingOutputMultipleLayers,
  39. QgsProcessingOutputPointCloudLayer)
  40. def getOutputFromString(s):
  41. try:
  42. if "|" in s and s.startswith("Output"):
  43. tokens = s.split("|")
  44. params = [t if str(t) != "None" else None for t in tokens[1:]]
  45. clazz = getattr(sys.modules[__name__], tokens[0])
  46. return clazz(*params)
  47. else:
  48. tokens = s.split("=")
  49. if tokens[1].lower()[: len('output')] != 'output':
  50. return None
  51. name = tokens[0]
  52. description = tokens[0]
  53. token = tokens[1].strip()[len('output') + 1:]
  54. out = None
  55. if token.lower().strip().startswith('outputraster'):
  56. out = QgsProcessingOutputRasterLayer(name, description)
  57. elif token.lower().strip() == 'outputvector':
  58. out = QgsProcessingOutputVectorLayer(name, description)
  59. elif token.lower().strip() == 'outputlayer':
  60. out = QgsProcessingOutputMapLayer(name, description)
  61. elif token.lower().strip() == 'outputmultilayers':
  62. out = QgsProcessingOutputMultipleLayers(name, description)
  63. # elif token.lower().strip() == 'vector point':
  64. # out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT])
  65. # elif token.lower().strip() == 'vector line':
  66. # out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE])
  67. # elif token.lower().strip() == 'vector polygon':
  68. # out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON])
  69. # elif token.lower().strip().startswith('table'):
  70. # out = OutputTable()
  71. elif token.lower().strip().startswith('outputhtml'):
  72. out = QgsProcessingOutputHtml(name, description)
  73. # elif token.lower().strip().startswith('file'):
  74. # out = OutputFile()
  75. # ext = token.strip()[len('file') + 1:]
  76. # if ext:
  77. # out.ext = ext
  78. elif token.lower().strip().startswith('outputfolder'):
  79. out = QgsProcessingOutputFolder(name, description)
  80. elif token.lower().strip().startswith('outputnumber'):
  81. out = QgsProcessingOutputNumber(name, description)
  82. elif token.lower().strip().startswith('outputstring'):
  83. out = QgsProcessingOutputString(name, description)
  84. elif token.lower().strip().startswith('outputboolean'):
  85. out = QgsProcessingOutputBoolean(name, description)
  86. elif token.lower().strip().startswith('outputPointCloud'):
  87. out = QgsProcessingOutputPointCloudLayer(name, description)
  88. # elif token.lower().strip().startswith('extent'):
  89. # out = OutputExtent()
  90. return out
  91. except:
  92. return None