本文整理汇总了Python中processing.parameters.ParameterFactory.ParameterFactory类的典型用法代码示例。如果您正苦于以下问题:Python ParameterFactory类的具体用法?Python ParameterFactory怎么用?Python ParameterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParameterFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip("\n").strip()
self.appkey = line
line = lines.readline().strip("\n").strip()
self.cliName = line
line = lines.readline().strip("\n").strip()
self.name = line
line = lines.readline().strip("\n").strip()
self.group = line
while line != "":
try:
line = line.strip("\n").strip()
if line.startswith("Parameter"):
param = ParameterFactory.getFromString(line)
# Hack for initializing the elevation parameters from Processing configuration
if param.name == "-elev.dem.path" or param.name == "-elev.dem":
param.default = OTBUtils.otbSRTMPath()
elif param.name == "-elev.dem.geoid" or param.name == "-elev.geoid":
param.default = OTBUtils.otbGeoidPath()
self.addParameter(param)
elif line.startswith("*Parameter"):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
elif line.startswith("Extent"):
self.addParameter(ParameterExtent(self.REGION_OF_INTEREST, "Region of interest", "0,1,0,1"))
self.hasROI = True
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
except Exception,e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not open OTB algorithm: " + self.descriptionFile + "\n" + line)
raise e
示例2: processDescriptionParameterLine
def processDescriptionParameterLine(self, line):
try:
if line.startswith("Parameter"):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith("*Parameter"):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
except Exception:
raise WrongScriptException("Could not load script:" + self.descriptionFile + ".\n Problem with line \"" + line + "\"")
示例3: processDescriptionParameterLine
def processDescriptionParameterLine(self, line):
try:
if line.startswith('Parameter'):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith('*Parameter'):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
except Exception:
raise WrongScriptException('Could not load script:'
+ self.descriptionFile or ''
+ '.\n Problem with line "' + line + '"'
)
示例4: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
self.hardcodedStrings = []
lines = open(self.descriptionFile)
line = lines.readline().strip("\n").strip()
self.name = line
if "|" in self.name:
tokens = self.name.split("|")
self.name = tokens[0]
self.cmdname = tokens[1]
else:
self.cmdname = self.name
self.name = self.name[0].upper() + self.name[1:].lower()
line = lines.readline().strip("\n").strip()
self.undecoratedGroup = line
self.group = SagaGroupNameDecorator.getDecoratedName(self.undecoratedGroup)
while line != "":
line = line.strip("\n").strip()
if line.startswith("Hardcoded"):
self.hardcodedStrings.append(line[len("Harcoded|")+1:])
elif line.startswith("Parameter"):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith("DontResample"):
self.resample = False
elif line.startswith("Extent"): #An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(" ")
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT, "Output extent", "0,1,0,1"))
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
lines.close()
示例5: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip('\n').strip()
self.name = line
if '|' in self.name:
tokens = self.name.split('|')
self.name = tokens[0]
self.cmdname = tokens[1]
else:
self.cmdname = self.name
self.name = self.name[0].upper() + self.name[1:].lower()
line = lines.readline().strip('\n').strip()
self.undecoratedGroup = line
self.group = SagaGroupNameDecorator.getDecoratedName(
self.undecoratedGroup)
while line != '':
line = line.strip('\n').strip()
if line.startswith('Hardcoded'):
self.hardcodedStrings.append(line[len('Harcoded|') + 1:])
elif line.startswith('Parameter'):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith('AllowUnmatching'):
self.allowUnmatchingGridExtents = True
elif line.startswith('Extent'):
# An extent parameter that wraps 4 SAGA numerical parameters
self.extentParamNames = line[6:].strip().split(' ')
self.addParameter(ParameterExtent(self.OUTPUT_EXTENT,
'Output extent', '0,1,0,1'))
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip('\n').strip()
lines.close()
示例6: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip('\n').strip()
self.appkey = line
line = lines.readline().strip('\n').strip()
self.cliName = line
line = lines.readline().strip('\n').strip()
self.name = line
line = lines.readline().strip('\n').strip()
self.group = line
while line != '':
try:
line = line.strip('\n').strip()
if line.startswith('Parameter'):
param = ParameterFactory.getFromString(line)
# Hack for initializing the elevation parameters
# from Processing configuration
if param.name == '-elev.dem.path' or param.name \
== '-elev.dem':
param.default = OTBUtils.otbSRTMPath()
elif param.name == '-elev.dem.geoid' or param.name \
== '-elev.geoid':
param.default = OTBUtils.otbGeoidPath()
self.addParameter(param)
elif line.startswith('*Parameter'):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
elif line.startswith('Extent'):
self.addParameter(ParameterExtent(self.REGION_OF_INTEREST,
'Region of interest', '0,1,0,1'))
self.hasROI = True
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open OTB algorithm: '
+ self.descriptionFile + '\n' + line)
raise e
示例7: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip('\n').strip()
self.grassName = line
line = lines.readline().strip('\n').strip()
self.name = line
line = lines.readline().strip('\n').strip()
self.group = line
hasRasterOutput = False
hasVectorInput = False
vectorOutputs = 0
while line != '':
try:
line = line.strip('\n').strip()
if line.startswith('Parameter'):
parameter = ParameterFactory.getFromString(line)
self.addParameter(parameter)
if isinstance(parameter, ParameterVector):
hasVectorInput = True
if isinstance(parameter, ParameterMultipleInput) \
and parameter.datatype < 3:
hasVectorInput = True
elif line.startswith('*Parameter'):
param = ParameterFactory.getFromString(line[1:])
param.isAdvanced = True
self.addParameter(param)
else:
output = OutputFactory.getFromString(line)
self.addOutput(output)
if isinstance(output, OutputRaster):
hasRasterOutput = True
elif isinstance(output, OutputVector):
vectorOutputs += 1
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open GRASS algorithm: '
+ self.descriptionFile + '\n' + line)
raise e
示例8: defineCharacteristicsFromFile
def defineCharacteristicsFromFile(self):
lines = open(self.descriptionFile)
line = lines.readline().strip("\n").strip()
self.name = line
line = lines.readline().strip("\n").strip()
self.cmdName = line
line = lines.readline().strip("\n").strip()
self.group = line
while line != "":
try:
line = line.strip("\n").strip()
if line.startswith("Parameter"):
param = ParameterFactory.getFromString(line)
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not load TauDEM algorithm: " + self.descriptionFile + "\n" + line)
raise e
示例9: openModel
def openModel(self, filename):
self.algPos = []
self.paramPos = []
self.outputOutputs = []
self.algs = []
self.algParameters = []
self.algOutputs = []
self.paramValues = {}
self.dependencies = []
self.descriptionFile = filename
lines = codecs.open(filename, "r", encoding='utf-8')
line = lines.readline().strip("\n").strip("\r")
iAlg = 0
try:
while line != "":
if line.startswith("PARAMETER:"):
paramLine = line[len("PARAMETER:"):]
param = ParameterFactory.getFromString(paramLine)
if param:
self.parameters.append(param)
else:
raise WrongModelException("Error in parameter line: " + line)
line = lines.readline().strip("\n")
tokens = line.split(",")
self.paramPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
elif line.startswith("VALUE:"):
valueLine = line[len("VALUE:"):]
tokens = valueLine.split("===")
self.paramValues[tokens[0]] = tokens[1].replace(ModelerAlgorithm.LINE_BREAK_STRING, '\n')
elif line.startswith("NAME:"):
self.name = line[len("NAME:"):]
elif line.startswith("GROUP:"):
self.group = line[len("GROUP:"):]
if self.group == "[Test models]":
self.showInModeler = False
self.showInToolbox = False
elif line.startswith("ALGORITHM:"):
algParams={}
algOutputs={}
algLine = line[len("ALGORITHM:"):]
alg = ModelerUtils.getAlgorithm(algLine)
if alg is not None:
posline = lines.readline().strip("\n").strip("\r")
tokens = posline.split(",")
self.algPos.append(QtCore.QPointF(float(tokens[0]), float(tokens[1])))
self.algs.append(alg)
dependenceline = lines.readline().strip("\n").strip("\r")
dependencies = [];
if dependenceline != str(None):
for index in dependenceline.split(","):
try:
dependencies.append(int(index))
except:
pass #a quick fix while I figure out how to solve problems when parsing this
for param in alg.parameters:
line = lines.readline().strip("\n").strip("\r")
if line==str(None):
algParams[param.name] = None
else:
tokens = line.split("|")
algParams[param.name] = AlgorithmAndParameter(int(tokens[0]), tokens[1])
outputPos = {}
for out in alg.outputs:
line = lines.readline().strip("\n").strip("\r")
if str(None)!=line:
if "|" in line:
tokens = line.split("|")
name = tokens[0]
tokens = tokens[1].split(",")
outputPos[out.name] = QtCore.QPointF(float(tokens[0]), float(tokens[1]))
else:
name = line
outputPos[out.name] = None
algOutputs[out.name] = name
#we add the output to the algorithm, with a name indicating where it comes from
#that guarantees that the name is unique
output = copy.deepcopy(out)
output.description = name
output.name = self.getSafeNameForOutput(iAlg, output)
self.addOutput(output)
else:
algOutputs[out.name] = None
self.outputPos.append(outputPos)
self.algOutputs.append(algOutputs)
self.algParameters.append(algParams)
self.dependencies.append(dependencies)
iAlg += 1
else:
raise WrongModelException("Error in algorithm name: " + algLine)
line = lines.readline().strip("\n").strip("\r")
except Exception, e:
if isinstance (e, WrongModelException):
raise e
else:
raise WrongModelException("Error in model definition line:" + line.strip() + " : " + traceback.format_exc())
示例10: openModel
def openModel(self, filename):
self.algPos = []
self.paramPos = []
self.outputOutputs = []
self.algs = []
self.algParameters = []
self.algOutputs = []
self.paramValues = {}
self.dependencies = []
self.descriptionFile = filename
lines = codecs.open(filename, 'r', encoding='utf-8')
line = lines.readline().strip('\n').strip('\r')
iAlg = 0
try:
while line != '':
if line.startswith('PARAMETER:'):
paramLine = line[len('PARAMETER:'):]
param = ParameterFactory.getFromString(paramLine)
if param:
self.parameters.append(param)
else:
raise WrongModelException('Error in parameter line: '
+ line)
line = lines.readline().strip('\n')
tokens = line.split(',')
self.paramPos.append(QtCore.QPointF(float(tokens[0]),
float(tokens[1])))
elif line.startswith('VALUE:'):
valueLine = line[len('VALUE:'):]
tokens = valueLine.split('===')
self.paramValues[tokens[0]] = \
tokens[1].replace(ModelerAlgorithm.LINE_BREAK_STRING,
'\n')
elif line.startswith('NAME:'):
self.name = line[len('NAME:'):]
elif line.startswith('GROUP:'):
self.group = line[len('GROUP:'):]
if self.group == '[Test models]':
self.showInModeler = False
self.showInToolbox = False
elif line.startswith('ALGORITHM:'):
algParams = {}
algOutputs = {}
algLine = line[len('ALGORITHM:'):]
alg = ModelerUtils.getAlgorithm(algLine)
if alg is not None:
posline = lines.readline().strip('\n').strip('\r')
tokens = posline.split(',')
self.algPos.append(QtCore.QPointF(float(tokens[0]),
float(tokens[1])))
self.algs.append(alg)
dependenceline = lines.readline().strip('\n'
).strip('\r')
dependencies = []
if dependenceline != str(None):
for index in dependenceline.split(','):
try:
dependencies.append(int(index))
except:
# A quick fix while I figure out
# how to solve problems when
# parsing this
pass
for param in alg.parameters:
if not param.hidden:
line = lines.readline().strip('\n').strip('\r')
if line == str(None):
algParams[param.name] = None
else:
tokens = line.split('|')
algParams[param.name] = \
AlgorithmAndParameter(int(tokens[0]),
tokens[1])
outputPos = {}
for out in alg.outputs:
if not out.hidden:
line = lines.readline().strip('\n').strip('\r')
if str(None) != line:
if '|' in line:
tokens = line.split('|')
name = tokens[0]
tokens = tokens[1].split(',')
outputPos[out.name] = QtCore.QPointF(
float(tokens[0]), float(tokens[1]))
else:
name = line
outputPos[out.name] = None
algOutputs[out.name] = name
# We add the output to the algorithm,
# with a name indicating where it comes
# from that guarantees that the name is
# unique
output = copy.deepcopy(out)
output.description = name
output.name = self.getSafeNameForOutput(iAlg,
output)
self.addOutput(output)
else:
algOutputs[out.name] = None
#.........这里部分代码省略.........