Пример #1
0
 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()
Пример #2
0
 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()
Пример #3
0
 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()
Пример #4
0
 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
Пример #5
0
 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()
Пример #6
0
 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 + "\"")
Пример #7
0
 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 + '"')
Пример #8
0
 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 + '"'
                                    )
Пример #9
0
 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 +
                                    "\"")
Пример #10
0
 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
Пример #11
0
 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 GIS 7 algorithm: ' +
                 self.descriptionFile + '\n' + line)
             raise e
Пример #12
0
 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
Пример #13
0
 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
Пример #14
0
 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
Пример #15
0
 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
Пример #16
0
class OTBAlgorithm(GeoAlgorithm):

    REGION_OF_INTEREST = "ROI"

    def __init__(self, descriptionfile):
        GeoAlgorithm.__init__(self)
        self.roiFile = None
        self.descriptionFile = descriptionfile
        self.defineCharacteristicsFromFile()
        self.numExportedLayers = 0
        self.hasROI = None

    def __str__(self):
        return ("Algo : " + self.name + " from app : " + self.cliName +
                " in : " + self.group)

    def getCopy(self):
        newone = OTBAlgorithm(self.descriptionFile)
        newone.provider = self.provider
        return newone

    def getIcon(self):
        return PyQt4.QtGui.QIcon(
            os.path.dirname(__file__) + "/../../images/otb.png")

    def help(self):
        folder = os.path.join(OTBUtils.otbDescriptionPath(), 'doc')
        helpfile = os.path.join(str(folder), self.appkey + ".html")
        if os.path.exists(helpfile):
            return False, helpfile
        else:
            raise WrongHelpFileException(
                "Could not find help file for this algorithm. \nIf you have it put it in: \n"
                + str(folder))

    def adapt_list_to_string(self, c_list):
        a_list = c_list[1:]
        if a_list[0] in ["ParameterVector", "ParameterMultipleInput"]:
            if c_list[0] == "ParameterType_InputImageList":
                a_list[3] = 3
            elif c_list[0] == "ParameterType_InputFilenameList":
                a_list[3] = 4
            else:
                a_list[3] = -1

        a_list[1] = "-%s" % a_list[1]

        def mystr(par):
            if type(par) == type([]):
                return ";".join(par)
            return str(par)

        b_list = map(mystr, a_list)
        res = "|".join(b_list)
        return res

    def get_list_from_node(self, myet):
        all_params = []
        for parameter in myet.iter('parameter'):
            rebuild = []
            par_type = parameter.find('parameter_type').text
            key = parameter.find('key').text
            name = parameter.find('name').text
            source_par_type = parameter.find(
                'parameter_type').attrib['source_parameter_type']
            rebuild.append(source_par_type)
            rebuild.append(par_type)
            rebuild.append(key)
            rebuild.append(name)
            for each in parameter[4:]:
                if not each.tag in ["hidden"]:
                    if len(list(each)) == 0:
                        rebuild.append(each.text)
                    else:
                        rebuild.append(
                            [item.text for item in each.iter('choice')])
            all_params.append(rebuild)
        return all_params

    def defineCharacteristicsFromFile(self):
        content = open(self.descriptionFile).read()
        dom_model = ET.fromstring(content)

        self.appkey = dom_model.find('key').text
        self.cliName = dom_model.find('exec').text
        self.name = dom_model.find('longname').text
        self.group = dom_model.find('group').text

        #ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Reading parameters for %s" % self.appkey)

        rebu = None
        the_result = None

        try:
            rebu = self.get_list_from_node(dom_model)
            the_result = map(self.adapt_list_to_string, rebu)
        except Exception, e:
            ProcessingLog.addToLog(
                ProcessingLog.LOG_ERROR, "Could not open OTB algorithm: " +
                self.descriptionFile + "\n" + traceback.format_exc())
            raise e

        for line in the_result:
            try:
                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" or "elev.dem" in param.name:
                        param.default = OTBUtils.otbSRTMPath()
                    elif param.name == "-elev.dem.geoid" or param.name == "-elev.geoid" or "elev.geoid" in param.name:
                        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))
            except Exception, e:
                ProcessingLog.addToLog(
                    ProcessingLog.LOG_ERROR, "Could not open OTB algorithm: " +
                    self.descriptionFile + "\n" + line)
                raise e