コード例 #1
0
ファイル: RUtils.py プロジェクト: Adam-Brown/Quantum-GIS
    def checkRIsInstalled(ignoreRegistrySettings=False):
        if SextanteUtils.isWindows():
            path = RUtils.RFolder()
            if path == "":
                return "R folder is not configured.\nPlease configure it before running R scripts."

        R_INSTALLED = "R_INSTALLED"
        settings = QSettings()
        if not ignoreRegistrySettings:
            if settings.contains(R_INSTALLED):
                return
        if SextanteUtils.isWindows():
            if SextanteConfig.getSetting(RUtils.R_USE64):
                execDir = "x64"
            else:
                execDir = "i386"
            command = [RUtils.RFolder() + os.sep + "bin" + os.sep + execDir + os.sep + "R.exe", "--version"]
        else:
            command = ["R --version"]
        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout

        for line in iter(proc.readline, ""):
            if "R version" in line:
                settings.setValue(R_INSTALLED, True)
                return
        html = ("<p>This algorithm requires R to be run."
            "Unfortunately, it seems that R is not installed in your system, or it is not correctly configured to be used from QGIS</p>"
            '<p><a href= "http://docs.qgis.org/2.0/html/en/docs/user_manual/sextante/3rdParty.html">Click here</a>'
             'to know more about how to install and configure R to be used with SEXTANTE</p>')
        return html
コード例 #2
0
    def checkBeforeOpeningParametersDialog(self):
        if SextanteUtils.isWindows():
            path = RUtils.RFolder()
            if path == "":
                return "R folder is not configured.\nPlease configure it before running R scripts."

        R_INSTALLED = "R_INSTALLED"
        settings = QSettings()
        if settings.contains(R_INSTALLED):
            return
        if SextanteUtils.isWindows():
            if SextanteConfig.getSetting(RUtils.R_USE64):
                execDir = "x64"
            else:
                execDir = "i386"
            command = [
                RUtils.RFolder() + os.sep + "bin" + os.sep + execDir + os.sep +
                "R.exe --version"
            ]
        else:
            command = ["R --version"]
        proc = subprocess.Popen(command,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stdin=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=True).stdout

        for line in iter(proc.readline, ""):
            if "R version" in line:
                settings.setValue(R_INSTALLED, True)
                return
        return "It seems that R is not correctly installed in your system.\nPlease install it before running R Scripts."
コード例 #3
0
ファイル: RAlgorithm.py プロジェクト: JoeyPinilla/Quantum-GIS
    def checkBeforeOpeningParametersDialog(self):
        if SextanteUtils.isWindows():
            path = RUtils.RFolder()
            if path == "":
                return "R folder is not configured.\nPlease configure it before running R scripts."
    
        R_INSTALLED = "R_INSTALLED"
        settings = QSettings()
        if settings.contains(R_INSTALLED):
            return
        if SextanteUtils.isWindows(): 
            if SextanteConfig.getSetting(RUtils.R_USE64):
                execDir = "x64"
            else:
                execDir = "i386"
            command = [RUtils.RFolder() + os.sep + "bin" + os.sep + execDir + os.sep + "R.exe --version"]
        else:
            command = ["R --version"]
        proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout

        for line in iter(proc.readline, ""):
            if "R version" in line:
                settings.setValue(R_INSTALLED, True)
                return
        return "It seems that R is not correctly installed in your system.\nPlease install it before running R Scripts."
コード例 #4
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_FOLDER, "GRASS folder", GrassUtils.grassPath()))
         SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_WIN_SHELL, "Msys folder", GrassUtils.grassWinShell()))
     SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_LOG_COMMANDS, "Log execution commands", False))
     SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_LOG_CONSOLE, "Log console output", False))
コード例 #5
0
ファイル: RUtils.py プロジェクト: kimaidou/Quantum-GIS
    def executeRAlgorithm(alg, progress):
        RUtils.verboseCommands = alg.getVerboseCommands()
        RUtils.createRScriptFromRCommands(alg.getFullSetOfRCommands())
        if SextanteUtils.isWindows():
            command = [
                RUtils.RFolder() + os.sep + "bin" + os.sep + "R.exe", "CMD",
                "BATCH", "--vanilla",
                RUtils.getRScriptFilename(),
                RUtils.getConsoleOutputFilename()
            ]
        else:
            os.chmod(RUtils.getRScriptFilename(),
                     stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
            command = "R CMD BATCH --vanilla " + RUtils.getRScriptFilename(
            ) + " " + RUtils.getConsoleOutputFilename()

        proc = subprocess.Popen(command,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stdin=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                universal_newlines=True)
        proc.wait()
        RUtils.createConsoleOutput()
        loglines = []
        loglines.append("R execution console output")
        loglines += RUtils.allConsoleResults
        for line in loglines:
            progress.setConsoleInfo(line)
        SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
コード例 #6
0
ファイル: SagaUtils.py プロジェクト: Nald/Quantum-GIS
 def executeSaga(progress):
     if SextanteUtils.isWindows():
         command = ["cmd.exe", "/C ", SagaUtils.sagaBatchJobFilename()]
     else:
         os.chmod(SagaUtils.sagaBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
         command = [SagaUtils.sagaBatchJobFilename()]
     loglines = []
     loglines.append("SAGA execution console output")
     proc = subprocess.Popen(
         command,
         shell=True,
         stdout=subprocess.PIPE,
         stdin=subprocess.PIPE,
         stderr=subprocess.STDOUT,
         universal_newlines=True,
     ).stdout
     for line in iter(proc.readline, ""):
         if "%" in line:
             s = "".join([x for x in line if x.isdigit()])
             try:
                 progress.setPercentage(int(s))
             except:
                 pass
         else:
             line = line.strip()
             if line != "/" and line != "-" and line != "\\" and line != "|":
                 loglines.append(line)
                 progress.setConsoleInfo(line)
     if SextanteConfig.getSetting(SagaUtils.SAGA_LOG_CONSOLE):
         SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
コード例 #7
0
ファイル: OTBUtils.py プロジェクト: geodenilson/Quantum-GIS
 def otbPath():
     folder = SextanteConfig.getSetting(OTBUtils.OTB_FOLDER)
     if folder == None:
         folder = ""
         #try to configure the path automatically
         if SextanteUtils.isMac():
             testfolder = os.path.join(str(QgsApplication.prefixPath()), "bin")
             if os.path.exists(os.path.join(testfolder, "otbcli")):
                 folder = testfolder
             else:
                 testfolder = "/usr/local/bin"
                 if os.path.exists(os.path.join(testfolder, "otbcli")):
                     folder = testfolder
         elif SextanteUtils.isWindows():
             testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
             testfolder = os.path.dirname(testfolder)
             testfolder = os.path.join(testfolder,  "bin")
             path = os.path.join(testfolder, "otbcli.bat")
             if os.path.exists(path):
                 folder = testfolder
         else:
             testfolder = "/usr/bin"
             if os.path.exists(os.path.join(testfolder, "otbcli")):
                 folder = testfolder
     return folder
コード例 #8
0
ファイル: GrassUtils.py プロジェクト: geodenilson/Quantum-GIS
    def checkGrassIsInstalled(ignoreRegistrySettings=False):
        if SextanteUtils.isWindows():
            path = GrassUtils.grassPath()
            if path == "":
                return "GRASS folder is not configured.\nPlease configure it before running SAGA algorithms."
            cmdpath = os.path.join(path, "bin","r.out.gdal.exe")
            if not os.path.exists(cmdpath):
                return ("The specified GRASS folder does not contain a valid set of GRASS modules.\n"
                        + "Please, go to the SEXTANTE settings dialog, and check that the GRASS\n"
                        + "folder is correctly configured")

        settings = QSettings()
        GRASS_INSTALLED = "/SextanteQGIS/GrassInstalled"
        if not ignoreRegistrySettings:
            if settings.contains(GRASS_INSTALLED):
                return

        try:
            from sextante import runalg
            result = runalg("grass:v.voronoi", points(),False,False,"270778.60198,270855.745301,4458921.97814,4458983.8488",-1,0.0001,None)
            if not os.path.exists(result['output']):
                return "It seems that GRASS is not correctly installed and configured in your system.\nPlease install it before running GRASS algorithms."
        except:
            s = traceback.format_exc()
            return "Error while checking GRASS installation. GRASS might not be correctly configured.\n" + s;

        settings.setValue(GRASS_INSTALLED, True)
コード例 #9
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         SextanteConfig.addSetting(
             Setting(self.getDescription(), GrassUtils.GRASS_FOLDER,
                     "GRASS folder", GrassUtils.grassPath()))
         SextanteConfig.addSetting(
             Setting(self.getDescription(), GrassUtils.GRASS_WIN_SHELL,
                     "Msys folder", GrassUtils.grassWinShell()))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), GrassUtils.GRASS_LOG_COMMANDS,
                 "Log execution commands", False))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), GrassUtils.GRASS_LOG_CONSOLE,
                 "Log console output", False))
     #SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_AUTO_REGION, "Use min covering region", True))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), GrassUtils.GRASS_LATLON,
                 "Coordinates are lat/lon", False))
     #=======================================================================
     # SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMIN, "GRASS Region min x", 0))
     # SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMIN, "GRASS Region min y", 0))
     # SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_XMAX, "GRASS Region max x", 1000))
     # SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_YMAX, "GRASS Region max y", 1000))
     # SextanteConfig.addSetting(Setting(self.getDescription(), GrassUtils.GRASS_REGION_CELLSIZE, "GRASS Region cellsize", 100))
     #=======================================================================
     SextanteConfig.addSetting(
         Setting(self.getDescription(), GrassUtils.GRASS_HELP_FOLDER,
                 "GRASS help folder", GrassUtils.grassHelpPath()))
コード例 #10
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     if SextanteUtils.isWindows():
         SextanteConfig.addSetting(
             Setting(self.getDescription(), SagaUtils.SAGA_FOLDER, "SAGA folder", SagaUtils.sagaPath())
         )
     SextanteConfig.addSetting(
         Setting(
             self.getDescription(),
             SagaUtils.SAGA_AUTO_RESAMPLING,
             "Use min covering grid system for resampling",
             True,
         )
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS, "Log execution commands", False)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE, "Log console output", False)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMIN, "Resampling region min x", 0)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_YMIN, "Resampling region min y", 0)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_XMAX, "Resampling region max x", 1000)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_YMAX, "Resampling region max y", 1000)
     )
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE, "Resampling region cellsize", 1)
     )
コード例 #11
0
 def unload(self):
     AlgorithmProvider.unload(self)
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
         SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)
コード例 #12
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     if SextanteUtils.isWindows():
         SextanteConfig.addSetting(
             Setting(self.getDescription(), SagaUtils.SAGA_FOLDER,
                     "SAGA folder", SagaUtils.sagaPath()))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_AUTO_RESAMPLING,
                 "Use min covering grid system for resampling", True))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_LOG_COMMANDS,
                 "Log execution commands", False))
     SextanteConfig.addSetting(
         Setting(self.getDescription(), SagaUtils.SAGA_LOG_CONSOLE,
                 "Log console output", False))
     SextanteConfig.addSetting(
         Setting(self.getDescription(),
                 SagaUtils.SAGA_RESAMPLING_REGION_XMIN,
                 "Resampling region min x", 0))
     SextanteConfig.addSetting(
         Setting(self.getDescription(),
                 SagaUtils.SAGA_RESAMPLING_REGION_YMIN,
                 "Resampling region min y", 0))
     SextanteConfig.addSetting(
         Setting(self.getDescription(),
                 SagaUtils.SAGA_RESAMPLING_REGION_XMAX,
                 "Resampling region max x", 1000))
     SextanteConfig.addSetting(
         Setting(self.getDescription(),
                 SagaUtils.SAGA_RESAMPLING_REGION_YMAX,
                 "Resampling region max y", 1000))
     SextanteConfig.addSetting(
         Setting(self.getDescription(),
                 SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE,
                 "Resampling region cellsize", 1))
コード例 #13
0
    def checkSagaIsInstalled(ignoreRegistrySettings=False):
        if SextanteUtils.isWindows():
            path = SagaUtils.sagaPath()
            if path == "":
                return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
            cmdpath = os.path.join(path, "saga_cmd.exe")
            if not os.path.exists(cmdpath):
                return (
                    "The specified SAGA folder does not contain a valid SAGA executable.\n"
                    +
                    "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n"
                    + "folder is correctly configured")

        settings = QSettings()
        SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
        if not ignoreRegistrySettings:
            if settings.contains(SAGA_INSTALLED):
                return

        try:
            from sextante import runalg
            result = runalg("saga:thiessenpolygons", points(), None)
            if not os.path.exists(result['POLYGONS']):
                return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
        except:
            s = traceback.format_exc()
            return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s

        settings.setValue(SAGA_INSTALLED, True)
コード例 #14
0
    def checkSagaIsInstalled(ignoreRegistrySettings=False):
        if SextanteUtils.isWindows():
            path = SagaUtils.sagaPath()
            if path == "":
                return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
            cmdpath = os.path.join(path, "saga_cmd.exe")
            if not os.path.exists(cmdpath):
                return ("The specified SAGA folder does not contain a valid SAGA executable.\n"
                        + "Please, go to the SEXTANTE settings dialog, and check that the SAGA\n"
                        + "folder is correctly configured")

        settings = QSettings()
        if not ignoreRegistrySettings:
            SAGA_INSTALLED = "/SextanteQGIS/SagaInstalled"
            if settings.contains(SAGA_INSTALLED):
                return

        try:
            from sextante.core.Sextante import runalg
            result = runalg("saga:thiessenpolygons", points(), None)
            if not os.path.exists(result['POLYGONS']):
                return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
        except:
            s = traceback.format_exc()
            return "Error while checking SAGA installation. SAGA might not be correctly configured.\n" + s;

        settings.setValue(SAGA_INSTALLED, True)
コード例 #15
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilename("sgrd")
     self.exportedLayers[layer]= destFilename
     if SextanteUtils.isWindows():
         return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
     else:
         return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
コード例 #16
0
 def executeGrass(commands, progress):
     if SextanteUtils.isWindows():
         GrassUtils.createGrassScript(commands)
         command = ["cmd.exe", "/C ", GrassUtils.grassScriptFilename()]
     else:
         gisrc =  SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
         os.putenv("GISRC", gisrc)
         os.putenv("GRASS_MESSAGE_FORMAT", "gui")
         os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
         GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
         os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
         if SextanteUtils.isMac():
             command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/user"
         else:
             command = "grass64 " + GrassUtils.grassMapsetFolder() + "/user"
     loglines = []
     loglines.append("GRASS execution console output")
     proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
     for line in iter(proc.readline, ""):
         if "GRASS_INFO_PERCENT" in line:
             try:
                 progress.setPercentage(int(line[len("GRASS_INFO_PERCENT")+ 2:]))
             except:
                 pass
         else:
             loglines.append(line)
             progress.setConsoleInfo(line)
     if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_CONSOLE):
         SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
コード例 #17
0
ファイル: SplitRGBBands.py プロジェクト: kimaidou/Quantum-GIS
    def processAlgorithm(self, progress):
        #TODO:check correct num of bands
        input = self.getParameterValue(SplitRGBBands.INPUT)
        temp = SextanteUtils.getTempFilename()
        r = self.getOutputValue(SplitRGBBands.R)
        g = self.getOutputValue(SplitRGBBands.G)
        b = self.getOutputValue(SplitRGBBands.B)
        commands = []
        if SextanteUtils.isWindows():
            commands.append("io_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" +
                            input + "\"")
            commands.append("io_gdal 1 -GRIDS \"" + temp +
                            "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r +
                            "\"")
            commands.append("io_gdal 1 -GRIDS \"" + temp +
                            "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g +
                            "\"")
            commands.append("io_gdal 1 -GRIDS \"" + temp +
                            "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b +
                            "\"")
        else:
            commands.append("libio_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" +
                            input + "\"")
            commands.append("libio_gdal 1 -GRIDS \"" + temp +
                            "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r +
                            "\"")
            commands.append("libio_gdal 1 -GRIDS \"" + temp +
                            "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g +
                            "\"")
            commands.append("libio_gdal 1 -GRIDS \"" + temp +
                            "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b +
                            "\"")

        SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
        SagaUtils.executeSaga(progress)
コード例 #18
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
     self.exportedLayers[layer] = destFilename
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         return 'io_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + layer + '"'
     else:
         return 'libio_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + layer + '"'
コード例 #19
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilename("sgrd")
     self.exportedLayers[layer] = destFilename
     if SextanteUtils.isWindows():
         return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
     else:
         return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
コード例 #20
0
 def unload(self):
     AlgorithmProvider.unload(self)
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
         SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)
コード例 #21
0
 def otbPath():
     folder = SextanteConfig.getSetting(OTBUtils.OTB_FOLDER)
     if folder == None:
         folder = ""
         #try to configure the path automatically
         if SextanteUtils.isMac():
             testfolder = os.path.join(str(QgsApplication.prefixPath()),
                                       "bin")
             if os.path.exists(os.path.join(testfolder, "otbcli")):
                 folder = testfolder
             else:
                 testfolder = "/usr/local/bin"
                 if os.path.exists(os.path.join(testfolder, "otbcli")):
                     folder = testfolder
         elif SextanteUtils.isWindows():
             testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
             testfolder = os.path.dirname(testfolder)
             testfolder = os.path.join(testfolder, "bin")
             path = os.path.join(testfolder, "otbcli.bat")
             if os.path.exists(path):
                 folder = testfolder
         else:
             testfolder = "/usr/bin"
             if os.path.exists(os.path.join(testfolder, "otbcli")):
                 folder = testfolder
     return folder
コード例 #22
0
 def otbLibPath():
     folder = SextanteConfig.getSetting(OTBUtils.OTB_LIB_FOLDER)
     if folder == None:
         folder = ""
         #try to configure the path automatically
         if SextanteUtils.isMac():
             testfolder = os.path.join(str(QgsApplication.prefixPath()),
                                       "lib/otb/applications")
             if os.path.exists(testfolder):
                 folder = testfolder
             else:
                 testfolder = "/usr/local/lib/otb/applications"
                 if os.path.exists(testfolder):
                     folder = testfolder
         elif SextanteUtils.isWindows():
             testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
             testfolder = os.path.join(testfolder, "orfeotoolbox")
             testfolder = os.path.join(testfolder, "applications")
             if os.path.exists(testfolder):
                 folder = testfolder
         else:
             testfolder = "/usr/lib/otb/applications"
             if os.path.exists(testfolder):
                 folder = testfolder
     return folder
コード例 #23
0
    def processAlgorithm(self, progress):
        #TODO:check correct num of bands
        input = self.getParameterValue(SplitRGBBands.INPUT)
        temp = SextanteUtils.getTempFilename(None).replace('.','');
        basename = os.path.basename(temp)
        validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        safeBasename = ''.join(c for c in basename if c in validChars)
        temp = os.path.join(os.path.dirname(temp), safeBasename)

        r = self.getOutputValue(SplitRGBBands.R)
        g = self.getOutputValue(SplitRGBBands.G)
        b = self.getOutputValue(SplitRGBBands.B)
        commands = []
        if SextanteUtils.isWindows():
            commands.append("io_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input+"\"")
            commands.append("io_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
            commands.append("io_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
            commands.append("io_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");
        else:
            commands.append("libio_gdal 0 -GRIDS \"" + temp + "\" -FILES \"" + input + "\"")
            commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0001.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + r + "\"");
            commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0002.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + g + "\"");
            commands.append("libio_gdal 1 -GRIDS \"" + temp + "_0003.sgrd\" -FORMAT 1 -TYPE 0 -FILE \"" + b + "\"");

        SagaUtils.createSagaBatchJobFileFromSagaCommands(commands)
        SagaUtils.executeSaga(progress);
コード例 #24
0
    def checkGrassIsInstalled(ignoreRegistrySettings=False):
        if SextanteUtils.isWindows():
            path = GrassUtils.grassPath()
            if path == "":
                return "GRASS folder is not configured.\nPlease configure it before running SAGA algorithms."
            cmdpath = os.path.join(path, "bin","r.out.gdal.exe")
            if not os.path.exists(cmdpath):
                return ("The specified GRASS folder does not contain a valid set of GRASS modules.\n"
                        + "Please, go to the SEXTANTE settings dialog, and check that the GRASS\n"
                        + "folder is correctly configured")

        settings = QSettings()
        GRASS_INSTALLED = "/SextanteQGIS/GrassInstalled"
        if not ignoreRegistrySettings:
            if settings.contains(GRASS_INSTALLED):
                return

        try:
            from sextante import runalg
            result = runalg("grass:v.voronoi", points(),False,False,"270778.60198,270855.745301,4458921.97814,4458983.8488",-1,0.0001, 0, None)
            if not os.path.exists(result['output']):
                return "It seems that GRASS is not correctly installed and configured in your system.\nPlease install it before running GRASS algorithms."
        except:
            s = traceback.format_exc()
            return "Error while checking GRASS installation. GRASS might not be correctly configured.\n" + s;

        settings.setValue(GRASS_INSTALLED, True)
コード例 #25
0
ファイル: GrassUtils.py プロジェクト: mokerjoke/Quantum-GIS
 def executeGrass(commands, progress):
     if SextanteUtils.isWindows():
         GrassUtils.createGrassScript(commands)
         command = ["cmd.exe", "/C ", GrassUtils.grassScriptFilename()]
     else:
         gisrc =  SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
         os.putenv("GISRC", gisrc)
         os.putenv("GRASS_MESSAGE_FORMAT", "gui")
         os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
         GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
         os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
         if SextanteUtils.isMac():
             command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/user"
         else:
             command = "grass64 " + GrassUtils.grassMapsetFolder() + "/user"
     loglines = []
     loglines.append("GRASS execution console output")
     proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
     for line in iter(proc.readline, ""):
         if "GRASS_INFO_PERCENT" in line:
             try:
                 progress.setPercentage(int(line[len("GRASS_INFO_PERCENT")+ 2:]))
             except:
                 pass
         else:
             loglines.append(line)
             progress.setConsoleInfo(line)
     if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_CONSOLE):
         SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
     shutil.rmtree(GrassUtils.grassMapsetFolder(), True)
コード例 #26
0
 def executeSaga(progress):
     if SextanteUtils.isWindows():
         command = ["cmd.exe", "/C ", SagaUtils.sagaBatchJobFilename()]
     else:
         os.chmod(SagaUtils.sagaBatchJobFilename(),
                  stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
         command = [SagaUtils.sagaBatchJobFilename()]
     loglines = []
     loglines.append("SAGA execution console output")
     proc = subprocess.Popen(command,
                             shell=True,
                             stdout=subprocess.PIPE,
                             stdin=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             universal_newlines=True).stdout
     for line in iter(proc.readline, ""):
         if "%" in line:
             s = "".join([x for x in line if x.isdigit()])
             try:
                 progress.setPercentage(int(s))
             except:
                 pass
         else:
             line = line.strip()
             if line != "/" and line != "-" and line != "\\" and line != "|":
                 loglines.append(line)
                 progress.setConsoleInfo(line)
     if SextanteConfig.getSetting(SagaUtils.SAGA_LOG_CONSOLE):
         SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
コード例 #27
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     SextanteConfig.addSetting(
         Setting(self.getDescription(), RUtils.RSCRIPTS_FOLDER, "R Scripts folder", RUtils.RScriptsFolder())
     )
     if SextanteUtils.isWindows():
         SextanteConfig.addSetting(Setting(self.getDescription(), RUtils.R_FOLDER, "R folder", RUtils.RFolder()))
         SextanteConfig.addSetting(Setting(self.getDescription(), RUtils.R_USE64, "Use 64 bit version", False))
コード例 #28
0
 def getValueAsCommandLineParameter(self):
     if self.value == None:
         return str(None)
     else:
         if not SextanteUtils.isWindows():
             return "\"" + unicode(self.value) + "\""
         else:
             return "\"" + unicode(self.value).replace("\\", "\\\\") + "\""
コード例 #29
0
ファイル: Output.py プロジェクト: rudivs/Quantum-GIS
 def getValueAsCommandLineParameter(self):
     if self.value == None:
         return str(None)
     else:
         if not SextanteUtils.isWindows():
             return '"' + str(self.value) + '"'
         else:
             return '"' + str(self.value).replace("\\", "\\\\") + '"'
コード例 #30
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilenameInTempFolder(
         os.path.basename(layer)[0:5] + ".sgrd")
     self.exportedLayers[layer] = destFilename
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
     else:
         return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
コード例 #31
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     SextanteConfig.addSetting(
         Setting(self.getDescription(), RUtils.RSCRIPTS_FOLDER,
                 "R Scripts folder", RUtils.RScriptsFolder()))
     if SextanteUtils.isWindows():
         SextanteConfig.addSetting(
             Setting(self.getDescription(), RUtils.R_FOLDER, "R folder",
                     RUtils.RFolder()))
コード例 #32
0
    def sagaBatchJobFilename():

        if SextanteUtils.isWindows():
            filename = "saga_batch_job.bat"
        else:
            filename = "saga_batch_job.sh"

        batchfile = SextanteUtils.userFolder() + os.sep + filename

        return batchfile
コード例 #33
0
ファイル: SagaUtils.py プロジェクト: geonux/Quantum-GIS
    def sagaBatchJobFilename():

        if SextanteUtils.isWindows():
            filename = "saga_batch_job.bat";
        else:
            filename = "saga_batch_job.sh";

        batchfile = SextanteUtils.userFolder() + os.sep + filename

        return batchfile
コード例 #34
0
    def __init__(self):
        AlgorithmProvider.__init__(self)
        self.activate = False
        self.algsList = []
        if SextanteUtils.isWindows():
            lastools = [
                las2shp(),
                lasboundary(),
                las2dem(),
                las2iso(),
                lasgrid(),
                lasground(),
                lasinfo(),
                lasheight(),
                lasprecision(),
                lassplit(),
                lasclassify(),
                lasclip()
            ]
        else:
            lastools = [lasinfo(), lasprecision()]
        for alg in lastools:
            alg.group = "LASTools"
        self.algsList.extend(lastools)

        if SextanteUtils.isWindows():
            self.actions.append(OpenViewerAction())
            fusiontools = [
                CloudMetrics(),
                CanopyMaxima(),
                CanopyModel(),
                ClipData(),
                Cover(),
                FilterData(),
                GridMetrics(),
                GroundFilter(),
                GridSurfaceCreate(),
                MergeData()
            ]
            for alg in fusiontools:
                alg.group = "Fusion"
            self.algsList.extend(fusiontools)
コード例 #35
0
    def grassPath():
        if not SextanteUtils.isWindows() and not SextanteUtils.isMac():
            return ""

        folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
        if folder == None:
            if SextanteUtils.isWindows():
                testfolder = os.path.dirname(str(QgsApplication.prefixPath()))
                testfolder = os.path.join(testfolder,  "grass")
                if os.path.isdir(testfolder):
                    for subfolder in os.listdir(testfolder):
                        if subfolder.startswith("grass"):
                            folder = os.path.join(testfolder, subfolder)
                            break
            else:
                folder = os.path.join(str(QgsApplication.prefixPath()), "grass")
                if not os.path.isdir(folder):
                    folder = "/Applications/GRASS-6.4.app/Contents/MacOS"

        return folder
コード例 #36
0
    def __init__(self):
        AlgorithmProvider.__init__(self)
        self.activate = False
        self.algsList = []
        if SextanteUtils.isWindows():
            lastools = [las2shp(), lasboundary(), las2dem(), las2iso(), lasgrid(), lasground(),
                         lasinfo(), lasheight(), lasprecision(), lassplit(), lasclassify(), lasclip()]
        else:
            lastools = [lasinfo(), lasprecision()]
        for alg in lastools:
            alg.group = "LASTools"
        self.algsList.extend(lastools)

        if SextanteUtils.isWindows():
            self.actions.append(OpenViewerAction())
            fusiontools = [CloudMetrics(), CanopyMaxima(), CanopyModel(), ClipData(), Cover(), FilterData(),
                         GridMetrics(), GroundFilter(), GridSurfaceCreate(), MergeData()]
            for alg in fusiontools:
                alg.group = "Fusion"
            self.algsList.extend(fusiontools)
コード例 #37
0
ファイル: RUtils.py プロジェクト: carsonfarmer/Quantum-GIS
    def executeRAlgorithm(alg, progress):
        RUtils.verboseCommands = alg.getVerboseCommands();
        RUtils.createRScriptFromRCommands(alg.getFullSetOfRCommands())
        if SextanteUtils.isWindows():
            command = [RUtils.RFolder() + os.sep + "bin" + os.sep + "R.exe", "CMD", "BATCH", "--vanilla",
                       RUtils.getRScriptFilename(), RUtils.getConsoleOutputFilename()]
        else:
            os.chmod(RUtils.getRScriptFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
            command = "R CMD BATCH --vanilla " + RUtils.getRScriptFilename() + " "+ RUtils.getConsoleOutputFilename()

        proc = subprocess.Popen(command, shell=SextanteUtils.isWindows(), stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT,
                                universal_newlines=True)
        proc.wait()
        RUtils.createConsoleOutput()
        loglines = []
        loglines.append("R execution console output")
        loglines += RUtils.allConsoleResults
        for line in loglines:
            progress.setConsoleInfo(line)
        SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
コード例 #38
0
ファイル: GrassUtils.py プロジェクト: geodenilson/Quantum-GIS
    def grassPath():
        if not SextanteUtils.isWindows() and not SextanteUtils.isMac():
            return ""

        folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
        if folder == None:
            if SextanteUtils.isWindows():                    
                testfolder = os.path.dirname(str(QgsApplication.prefixPath()))                                
                testfolder = os.path.join(testfolder,  "grass")
                if os.path.isdir(testfolder):                                                                
                    for subfolder in os.listdir(testfolder):
                        if subfolder.startswith("grass"):
                            folder = os.path.join(testfolder, subfolder)
                            break
            else:
                folder = os.path.join(str(QgsApplication.prefixPath()), "grass")
                if not os.path.isdir(folder):
                    folder = "/Applications/GRASS-6.4.app/Contents/MacOS"

        return folder
コード例 #39
0
ファイル: GrassUtils.py プロジェクト: Nald/Quantum-GIS
    def grassPath():
        if not SextanteUtils.isWindows() and not SextanteUtils.isMac():
            return ""

        folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
        if folder == None:
            if SextanteUtils.isWindows():
                folder = plugin_installer.__file__
                idx = folder.find('qgis')
                folder = folder[:idx] + "grass"
                if not os.path.isdir(folder):
                    return ""
                for subfolder in os.listdir(folder):
                    if subfolder.startswith("grass"):
                        folder = folder + os.sep + subfolder
                        break
            else:
                return "/Applications/GRASS-6.4.app/Contents/MacOS"

        return folder
コード例 #40
0
    def grassPath():
        if not SextanteUtils.isWindows() and not SextanteUtils.isMac():
            return ""

        folder = SextanteConfig.getSetting(GrassUtils.GRASS_FOLDER)
        if folder == None:
            if SextanteUtils.isWindows():
                folder = plugin_installer.__file__
                idx = folder.find('qgis')
                folder = folder[:idx] + "grass"
                if not os.path.isdir(folder):
                    return ""
                for subfolder in os.listdir(folder):
                    if subfolder.startswith("grass"):
                        folder = folder + os.sep + subfolder
                        break
            else:
                return "/Applications/GRASS-6.4.app/Contents/MacOS"

        return folder
コード例 #41
0
 def unload(self):
     AlgorithmProvider.unload(self)
     if SextanteUtils.isWindows():
         SextanteConfig.removeSetting(SagaUtils.SAGA_FOLDER)
     SextanteConfig.removeSetting(SagaUtils.SAGA_AUTO_RESAMPLING)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMIN)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMIN)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMAX)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMAX)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE)
     SextanteConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE)
     SextanteConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS)
コード例 #42
0
 def unload(self):
     AlgorithmProvider.unload(self)
     if SextanteUtils.isWindows():
         SextanteConfig.removeSetting(SagaUtils.SAGA_FOLDER)
     SextanteConfig.removeSetting(SagaUtils.SAGA_AUTO_RESAMPLING)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMIN)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMIN)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMAX)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMAX)
     SextanteConfig.removeSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE)
     SextanteConfig.removeSetting(SagaUtils.SAGA_LOG_CONSOLE)
     SextanteConfig.removeSetting(SagaUtils.SAGA_LOG_COMMANDS)
コード例 #43
0
ファイル: GrassUtils.py プロジェクト: Nald/Quantum-GIS
    def grassHelpPath():
        folder = SextanteConfig.getSetting(GrassUtils.GRASS_HELP_FOLDER)
        if folder == None or folder == "":
            if SextanteUtils.isWindows():
                testfolders = [os.path.join(GrassUtils.grassPath(), "docs", "html")]
            else:
                testfolders = ['/usr/share/doc/grass-doc/html']
            for f in testfolders:
                if os.path.exists(f):
                    folder = f
                    break

        return folder
コード例 #44
0
    def grassHelpPath():
        folder = SextanteConfig.getSetting(GrassUtils.GRASS_HELP_FOLDER)
        if folder == None or folder == "":
            if SextanteUtils.isWindows():
                testfolders = [os.path.join(GrassUtils.grassPath(), "docs", "html")]
            else:
                testfolders = ['/usr/share/doc/grass-doc/html']
            for f in testfolders:
                if os.path.exists(f):
                    folder = f
                    break

        return folder
コード例 #45
0
ファイル: IliUtils.py プロジェクト: ThomasG77/ogrtools
 def runShellCmd(args, progress):
     loglines = []
     loglines.append("Ili execution console output")
     if SextanteUtils.isWindows():
         command = ["cmd.exe", "/C ", '"' + args[0] + '"'] + args[1:]
     else:
         command = args
     SextanteLog.addToLog(SextanteLog.LOG_INFO, ' '.join(command))
     fused_command = ' '.join(command) # java doesn't find quoted file on Win with: ''.join(['"%s" ' % c for c in command])
     proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
     for line in iter(proc.readline, ""):
         loglines.append(line)
     SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
     IliUtils.consoleOutput = loglines
コード例 #46
0
ファイル: pct2rgb.py プロジェクト: mokerjoke/Quantum-GIS
    def processAlgorithm(self, progress):
        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "pct2rgb.bat"]
        else:
            commands = ["pct2rgb.py"]
        commands.append("-b")
        commands.append(str(self.getParameterValue(pct2rgb.NBAND) + 1))
        commands.append("-of")
        out = self.getOutputValue(pct2rgb.OUTPUT)
        commands.append(GdalUtils.getFormatShortNameFromFilename(out))
        commands.append(self.getParameterValue(pct2rgb.INPUT))
        commands.append(out)

        GdalUtils.runGdal(commands, progress)
コード例 #47
0
ファイル: polygonize.py プロジェクト: mokerjoke/Quantum-GIS
 def processAlgorithm(self, progress):
     if SextanteUtils.isWindows():
         commands = ["cmd.exe", "/C ", "gdal_polygonize.bat"]
     else:
         commands = ["gdal_polygonize.py"]
     commands.append(self.getParameterValue(polygonize.INPUT))
     commands.append('-f')
     commands.append('"ESRI Shapefile"')
     output = self.getOutputValue(polygonize.OUTPUT)
     commands.append(output)
     commands.append(QtCore.QFileInfo(output).baseName())
     commands.append(self.getParameterValue(polygonize.FIELD))
     
     GdalUtils.runGdal(commands, progress)
コード例 #48
0
ファイル: SagaUtils.py プロジェクト: geonux/Quantum-GIS
    def createSagaBatchJobFileFromSagaCommands(commands):

        fout = open(SagaUtils.sagaBatchJobFilename(), "w")
        if SextanteUtils.isWindows():
            fout.write("set SAGA=" + SagaUtils.sagaPath() + "\n");
            fout.write("set SAGA_MLB=" + SagaUtils.sagaPath()+ os.sep + "modules" + "\n");
            fout.write("PATH=PATH;%SAGA%;%SAGA_MLB%\n");
        else:
            pass
        for command in commands:
            fout.write("saga_cmd " + command.encode("utf8") + "\n")

        fout.write("exit")
        fout.close()
コード例 #49
0
    def processAlgorithm(self, progress):
        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "rgb2pct.bat"]
        else:
            commands = ["rgb2pct.py"]
        commands.append("-n")
        commands.append(str(self.getParameterValue(rgb2pct.NCOLORS)))
        commands.append("-of")
        out = self.getOutputValue(rgb2pct.OUTPUT)
        commands.append(GdalUtils.getFormatShortNameFromFilename(out))
        commands.append(self.getParameterValue(rgb2pct.INPUT))
        commands.append(out)

        GdalUtils.runGdal(commands, progress)
コード例 #50
0
    def processAlgorithm(self, progress):
        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "gdal_polygonize.bat"]
        else:
            commands = ["gdal_polygonize.py"]
        commands.append(self.getParameterValue(polygonize.INPUT))
        commands.append('-f')
        commands.append('"ESRI Shapefile"')
        output = self.getOutputValue(polygonize.OUTPUT)
        commands.append(output)
        commands.append(QtCore.QFileInfo(output).baseName())
        commands.append(self.getParameterValue(polygonize.FIELD))

        GdalUtils.runGdal(commands, progress)
コード例 #51
0
ファイル: SagaUtils.py プロジェクト: hCivil/Quantum-GIS
    def createSagaBatchJobFileFromSagaCommands(commands):

        fout = open(SagaUtils.sagaBatchJobFilename(), "w")
        if SextanteUtils.isWindows():
            fout.write("set SAGA=" + SagaUtils.sagaPath() + "\n")
            fout.write("set SAGA_MLB=" + SagaUtils.sagaPath() + os.sep +
                       "modules" + "\n")
            fout.write("PATH=PATH;%SAGA%;%SAGA_MLB%\n")
        else:
            pass
        for command in commands:
            fout.write("saga_cmd " + command.encode("utf8") + "\n")

        fout.write("exit")
        fout.close()
コード例 #52
0
ファイル: merge.py プロジェクト: mokerjoke/Quantum-GIS
    def processAlgorithm(self, progress):
        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "gdal_merge.bat"]
        else:
            commands = ["gdal_merge.py"]
        if self.getParameterValue(merge.SEPARATE):
            commands.append("-separate")
        if self.getParameterValue(merge.PCT):
            commands.append("-pct")
        commands.append("-of")
        out = self.getOutputValue(merge.OUTPUT)
        commands.append(GdalUtils.getFormatShortNameFromFilename(out))
        commands.append(self.getParameterValue(merge.INPUT).replace(";", " "))
        commands.append(out)

        GdalUtils.runGdal(commands, progress)
コード例 #53
0
ファイル: rgb2pct.py プロジェクト: Adam-Brown/Quantum-GIS
    def processAlgorithm(self, progress):
        arguments = []
        arguments.append("-n")
        arguments.append(str(self.getParameterValue(rgb2pct.NCOLORS)))
        arguments.append("-of")
        out = self.getOutputValue(rgb2pct.OUTPUT)
        arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
        arguments.append(self.getParameterValue(rgb2pct.INPUT))
        arguments.append(out)

        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "rgb2pct.bat", GdalUtils.escapeAndJoin(arguments)]
        else:
            commands = ["rgb2pct.py", GdalUtils.escapeAndJoin(arguments)]

        GdalUtils.runGdal(commands, progress)
コード例 #54
0
ファイル: merge.py プロジェクト: sdikiy/Quantum-GIS
    def processAlgorithm(self, progress):
        if SextanteUtils.isWindows():
            commands = ["cmd.exe", "/C ", "gdal_merge.bat"]
        else:
            commands = ["gdal_merge.py"]
        if self.getParameterValue(merge.SEPARATE):
            commands.append("-separate")
        if self.getParameterValue(merge.PCT):
            commands.append("-pct")
        commands.append("-of")
        out = self.getOutputValue(merge.OUTPUT)
        commands.append(GdalUtils.getFormatShortNameFromFilename(out))
        commands.append(self.getParameterValue(merge.INPUT).replace(";", " "))
        commands.append(out)

        GdalUtils.runGdal(commands, progress)
コード例 #55
0
ファイル: GrassUtils.py プロジェクト: Nald/Quantum-GIS
    def prepareGrassExecution(commands):
        if SextanteUtils.isWindows():
            GrassUtils.createGrassScript(commands)
            command = ["cmd.exe", "/C ", GrassUtils.grassScriptFilename()]
        else:
            gisrc =  SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
            os.putenv("GISRC", gisrc)
            os.putenv("GRASS_MESSAGE_FORMAT", "gui")
            os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
            GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
            os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
            if SextanteUtils.isMac():
                command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/PERMANENT"
            else:
                command = "grass64 " + GrassUtils.grassMapsetFolder() + "/PERMANENT"

        return command
コード例 #56
0
 def checkBeforeOpeningParametersDialog(self):
     if SextanteUtils.isWindows():
         path = SagaUtils.sagaPath()
         if path == "":
             return "SAGA folder is not configured.\nPlease configure it before running SAGA algorithms."
     else:
         SAGA_INSTALLED = "SAGA_INSTALLED"
         settings = QSettings()
         if settings.contains(SAGA_INSTALLED):
             return
         command = ["saga_cmd"]
         proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.STDOUT, universal_newlines=True).stdout
         for line in iter(proc.readline, ""):
             if "________" in line:
                 settings.setValue(SAGA_INSTALLED, True)
                 return
         return "It seems that SAGA is not correctly installed in your system.\nPlease install it before running SAGA algorithms."
コード例 #57
0
    def prepareGrassExecution(commands):
        if SextanteUtils.isWindows():
            GrassUtils.createGrassScript(commands)
            command = ["cmd.exe", "/C ", GrassUtils.grassScriptFilename()]
        else:
            gisrc =  SextanteUtils.userFolder() + os.sep + "sextante.gisrc"
            os.putenv("GISRC", gisrc)
            os.putenv("GRASS_MESSAGE_FORMAT", "gui")
            os.putenv("GRASS_BATCH_JOB", GrassUtils.grassBatchJobFilename())
            GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
            os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
            if SextanteUtils.isMac():
                command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/PERMANENT"
            else:
                command = "grass64 " + GrassUtils.grassMapsetFolder() + "/PERMANENT"

        return command
コード例 #58
0
 def resampleRasterLayer(self, layer):
     '''this is supposed to be run after having exported all raster layers'''
     if layer in self.exportedLayers.keys():
         inputFilename = self.exportedLayers[layer]
     else:
         inputFilename = layer
     destFilename = SextanteUtils.getTempFilename("sgrd")
     self.exportedLayers[layer] = destFilename
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         s = "grid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
             str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX "  + str(self.ymax) +\
             " -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
     else:
         s = "libgrid_tools \"Resampling\" -INPUT \"" + inputFilename + "\" -TARGET 0 -SCALE_UP_METHOD 4 -SCALE_DOWN_METHOD 4 -USER_XMIN " +\
             str(self.xmin) + " -USER_XMAX " + str(self.xmax) + " -USER_YMIN " + str(self.ymin) + " -USER_YMAX "  + str(self.ymax) +\
             " -USER_SIZE " + str(self.cellsize) + " -USER_GRID \"" + destFilename + "\""
     return s
コード例 #59
0
 def unload(self):
     AlgorithmProvider.unload(self)
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         SextanteConfig.removeSetting(GrassUtils.GRASS_FOLDER)
         SextanteConfig.removeSetting(GrassUtils.GRASS_WIN_SHELL)
     #SextanteConfig.removeSetting(GrassUtils.GRASS_AUTO_REGION)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LATLON)
     #=======================================================================
     # SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMIN)
     # SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMIN)
     # SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_XMAX)
     # SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_YMAX)
     # SextanteConfig.removeSetting(GrassUtils.GRASS_REGION_CELLSIZE)
     #=======================================================================
     SextanteConfig.removeSetting(GrassUtils.GRASS_HELP_FOLDER)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_COMMANDS)
     SextanteConfig.removeSetting(GrassUtils.GRASS_LOG_CONSOLE)