2016-08-23 19:33:42 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-07-14 14:19:09 +02:00
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
Output.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
import sys
|
2016-08-23 19:33:42 +03:00
|
|
|
|
2017-04-03 15:41:32 +10:00
|
|
|
from qgis.core import (QgsExpressionContext,
|
|
|
|
QgsExpressionContextUtils,
|
|
|
|
QgsExpression,
|
|
|
|
QgsExpressionContextScope,
|
|
|
|
QgsProject,
|
|
|
|
QgsSettings,
|
2017-05-03 14:15:26 +10:00
|
|
|
QgsVectorFileWriter,
|
2017-05-16 16:36:00 +10:00
|
|
|
QgsProcessingUtils,
|
2017-06-26 15:47:51 +10:00
|
|
|
QgsProcessingParameterDefinition,
|
|
|
|
QgsProcessingOutputRasterLayer,
|
|
|
|
QgsProcessingOutputVectorLayer,
|
2017-11-26 15:39:36 +10:00
|
|
|
QgsProcessingOutputMapLayer,
|
2017-06-26 15:47:51 +10:00
|
|
|
QgsProcessingOutputHtml,
|
|
|
|
QgsProcessingOutputNumber,
|
|
|
|
QgsProcessingOutputString,
|
2018-02-11 10:57:44 +10:00
|
|
|
QgsProcessingOutputFolder,
|
|
|
|
QgsProcessingOutputMultipleLayers)
|
2016-09-14 09:49:04 +02:00
|
|
|
|
2016-09-19 11:52:31 +03:00
|
|
|
|
2016-09-08 10:30:30 +02:00
|
|
|
def getOutputFromString(s):
|
|
|
|
try:
|
2016-10-17 14:41:16 +02:00
|
|
|
if "|" in s and s.startswith("Output"):
|
2016-09-08 10:30:30 +02:00
|
|
|
tokens = s.split("|")
|
2016-09-27 19:51:06 +02:00
|
|
|
params = [t if str(t) != "None" else None for t in tokens[1:]]
|
2016-09-08 10:30:30 +02:00
|
|
|
clazz = getattr(sys.modules[__name__], tokens[0])
|
|
|
|
return clazz(*params)
|
|
|
|
else:
|
|
|
|
tokens = s.split("=")
|
2017-06-26 15:47:51 +10:00
|
|
|
if not tokens[1].lower()[:len('output')] == 'output':
|
|
|
|
return None
|
|
|
|
|
|
|
|
name = tokens[0]
|
|
|
|
description = tokens[0]
|
|
|
|
|
2016-09-08 10:30:30 +02:00
|
|
|
token = tokens[1].strip()[len('output') + 1:]
|
|
|
|
out = None
|
2016-09-19 11:52:31 +03:00
|
|
|
|
2017-06-26 15:47:51 +10:00
|
|
|
if token.lower().strip().startswith('outputraster'):
|
|
|
|
out = QgsProcessingOutputRasterLayer(name, description)
|
|
|
|
elif token.lower().strip() == 'outputvector':
|
|
|
|
out = QgsProcessingOutputVectorLayer(name, description)
|
2017-11-26 15:39:36 +10:00
|
|
|
elif token.lower().strip() == 'outputlayer':
|
|
|
|
out = QgsProcessingOutputMapLayer(name, description)
|
2018-02-11 10:57:44 +10:00
|
|
|
elif token.lower().strip() == 'outputmultilayers':
|
|
|
|
out = QgsProcessingOutputMultipleLayers(name, description)
|
2017-06-26 15:47:51 +10:00
|
|
|
# elif token.lower().strip() == 'vector point':
|
|
|
|
# out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT])
|
|
|
|
# elif token.lower().strip() == 'vector line':
|
|
|
|
# out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE])
|
|
|
|
# elif token.lower().strip() == 'vector polygon':
|
|
|
|
# out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON])
|
|
|
|
# elif token.lower().strip().startswith('table'):
|
|
|
|
# out = OutputTable()
|
|
|
|
elif token.lower().strip().startswith('outputhtml'):
|
|
|
|
out = QgsProcessingOutputHtml(name, description)
|
|
|
|
# elif token.lower().strip().startswith('file'):
|
|
|
|
# out = OutputFile()
|
|
|
|
# ext = token.strip()[len('file') + 1:]
|
|
|
|
# if ext:
|
|
|
|
# out.ext = ext
|
|
|
|
elif token.lower().strip().startswith('outputfolder'):
|
|
|
|
out = QgsProcessingOutputFolder(name, description)
|
|
|
|
elif token.lower().strip().startswith('outputnumber'):
|
|
|
|
out = QgsProcessingOutputNumber(name, description)
|
|
|
|
elif token.lower().strip().startswith('outputstring'):
|
|
|
|
out = QgsProcessingOutputString(name, description)
|
|
|
|
# elif token.lower().strip().startswith('extent'):
|
|
|
|
# out = OutputExtent()
|
2016-09-19 11:52:31 +03:00
|
|
|
|
2016-09-08 10:30:30 +02:00
|
|
|
return out
|
|
|
|
except:
|
2016-09-19 11:52:31 +03:00
|
|
|
return None
|