def executeStep(self, step): if isinstance(step['algorithm'], GrassAlgorithm): GrassUtils.startGrassSession() else: GrassUtils.endGrassSession() self.setStepParameters(step) stepDialog = StepDialog(step['algorithm'], None, False) stepDialog.setMode(step['mode']) stepDialog.setInstructions(step['instructions']) stepDialog.setWindowTitle("WOIS Workflow " + unicode(self.name) + ", Step "+unicode(self._steps.index(step)+1)+" of "+unicode(len(self._steps))+": "+step['algorithm'].name) stepDialog.setWindowIcon(self.getIcon()) # set as window modal to allow access to QGIS functions stepDialog.setWindowModality(1) stepDialog.exec_() return stepDialog
def testGrass(self): '''Test GRASS is installed QGIS-89 (2)''' folder = ProcessingConfig.getSetting(GrassUtils.GRASS_FOLDER) ProcessingConfig.removeSetting(GrassUtils.GRASS_FOLDER) msg = GrassUtils.checkGrassIsInstalled() self.assertIsNone(msg) ProcessingConfig.setSettingValue(GrassUtils.GRASS_FOLDER, folder)
def run(self): # execute the first step step = self._steps[0] stepDialog = self.executeStep(step) # execute the rest while True: # check if workflow should go forward, backward or finish if stepDialog.goForward: step = self.nextStep(step) elif stepDialog.goBackward: step = self.previousStep(step) else: step = None # finish the workflow or execute the next step if step == None: GrassUtils.endGrassSession() return stepDialog.executed else: stepDialog = self.executeStep(step)
loglines.append('GRASS r.series for whole directory script console output') loglines.append('') oldDir = os.getcwd() progress.setText("Looking for matching files.") getFiles(os.path.dirname(dataDir), filenameFormat, outputFileFormat, groupFiles, outputFiles, groupBy) os.chdir(oldDir) if len(groupFiles) == 0 or len(outputFiles) == 0: ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "No matching files found! r.series will not be executed.") raise GeoAlgorithmExecutionException("No matching files found! r.series will not be executed.") else: # run r.series for each group of files GrassUtils.startGrassSession() progress.setText("Starting GRASS r.series executions") loglines.append("Starting GRASS r.series executions") iteration = 1.0 for date in sorted(groupFiles.iterkeys()): progress.setPercentage(int(iteration/float(len(groupFiles))*100)) progress.setText("Processing date string: "+date) loglines.append("Processing date string: "+date) params={'input':groupFiles[date], '-n':propagateNulls, 'method':operation, \ 'range':range, 'GRASS_REGION_CELLSIZE_PARAMETER':cellSize, 'GRASS_REGION_PARAMETER':extent, 'output':outputDir+os.sep+outputFiles[date]} if processing.runalg("grass7:r.series",params): iteration +=1 else: GrassUtils.endGrassSession() raise GeoAlgorithmExecutionException("Unable to execute script \"GRASS r.series for whole directory\". Check Processing log for details.") progress.setText("Finished!")
def qgis_session_info(self): # import re # from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # from processing.algs.saga import SagaUtils # from processing.algs.grass.GrassUtils import GrassUtils # from processing.algs.grass7.Grass7Utils import Grass7Utils # from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider # from processing.algs.otb.OTBUtils import getInstalledVersion # from processing.algs.taudem.TauDEMUtils import TauDEMUtils # from osgeo import gdal # from processing.tools.system import isWindows, isMac # QGIS version qgis = QGis.QGIS_VERSION # GRASS versions # grassPath returns "" if called under Linux and if there is no GRASS # installation GrassUtils.checkGrassIsInstalled() g6 = GrassUtils.isGrassInstalled if g6 is True and isWindows(): g6 = GrassUtils.grassPath() # extract everything followed by grass-, i.e. extract the version number g6 = re.findall("grass-(.*)", g6) if g6 is True and isMac(): g6 = GrassUtils.grassPath()[0:21] g6 = os.listdir(g6) delim = ';' g6 = delim.join(g6) g6 = re.findall('[0-9].[0-9].[0-9]', g6) Grass7Utils.checkGrass7IsInstalled() g7 = Grass7Utils.isGrass7Installed if g7 is True and isWindows(): g7 = Grass7Utils.grassPath() g7 = re.findall('grass-(.*)', g7) if g7 is True and isMac(): g7 = Grass7Utils.grassPath()[0:21] g7 = os.listdir(g7) delim = ';' g7 = delim.join(g7) #g7 = re.findall(';(grass[0-9].);', g7) g7 = re.findall('[0-9].[0-9].[0-9]', g7) # installed SAGA version usable with QGIS saga = SagaUtils.getSagaInstalledVersion() # supported SAGA versions my_dict = SagaAlgorithmProvider.supportedVersions saga_versions = my_dict.keys() saga_versions.sort() # GDAL gdal_v = gdal.VersionInfo('VERSION_NUM') gdal_v = '.'.join([gdal_v[0], gdal_v[2], gdal_v[4]]) ## this is good to have for the future, but so far, I would not report ## these software versions since we don't know if they actually work ## with QGIS (without additional functions such as run_taudem...) ## OTB versions # otb = getInstalledVersion() # otb = OTBUtils.getInstalledVersion() ## TauDEM versions (currently not in use because no function to extract ## Taudem version in 'TauDEMUtils') # TauDEMUtils.taudemMultifilePath() # finally, put it all into a named dictionary keys = ["qgis_version", "gdal", "grass6", "grass7", "saga",\ "supported_saga_versions"] values = [qgis, gdal_v, g6, g7, saga, saga_versions] info = dict(zip(keys, values)) return info
def qgis_session_info(self): # import re # from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider # from processing.algs.saga import SagaUtils # from processing.algs.grass.GrassUtils import GrassUtils # from processing.algs.grass7.Grass7Utils import Grass7Utils # from processing.algs.otb.OTBAlgorithmProvider import OTBAlgorithmProvider # from processing.algs.otb.OTBUtils import getInstalledVersion # from processing.algs.taudem.TauDEMUtils import TauDEMUtils # from osgeo import gdal # from processing.tools.system import isWindows, isMac # QGIS version qgis = QGis.QGIS_VERSION # GRASS versions # grassPath returns "" if called under Linux and if there is no GRASS # installation GrassUtils.checkGrassIsInstalled() g6 = GrassUtils.isGrassInstalled if g6 is True and isWindows(): g6 = GrassUtils.grassPath() # extract everything followed by grass-, i.e. extract the version number g6 = re.findall("grass-(.*)", g6) if g6 is True and isMac(): g6 = GrassUtils.grassPath()[0:21] g6 = os.listdir(g6) delim = ';' g6 = delim.join(g6) g6 = re.findall('[0-9].[0-9].[0-9]', g6) Grass7Utils.checkGrass7IsInstalled() g7 = Grass7Utils.isGrass7Installed if g7 is True and isWindows(): g7 = Grass7Utils.grassPath() g7 = re.findall('grass-(.*)', g7) if g7 is True and isMac(): g7 = Grass7Utils.grassPath()[0:21] g7 = os.listdir(g7) delim = ';' g7 = delim.join(g7) #g7 = re.findall(';(grass[0-9].);', g7) g7 = re.findall('[0-9].[0-9].[0-9]', g7) # installed SAGA version usable with QGIS saga = SagaUtils.getSagaInstalledVersion() # supported SAGA versions try: # supportedVersions were deleted from SagaAlgorithmProvider since # QGIS 2.18.10. At least this is the case with custom applications... my_dict = SagaAlgorithmProvider.supportedVersions saga_versions = my_dict.keys() saga_versions.sort() except: # with QGIS 2.18.10 only SAGA 2.3.0 and 2.3.1 is suppported # well, observe next QGIS releases and try to avoid the hard-coding! saga_versions = [""] # GDAL gdal_v = gdal.VersionInfo('VERSION_NUM') gdal_v = '.'.join([gdal_v[0], gdal_v[2], gdal_v[4]]) ## this is good to have for the future, but so far, I would not report ## these software versions since we don't know if they actually work ## with QGIS (without additional functions such as run_taudem...) ## OTB versions # otb = getInstalledVersion() # otb = OTBUtils.getInstalledVersion() ## TauDEM versions (currently not in use because no function to extract ## Taudem version in 'TauDEMUtils') # TauDEMUtils.taudemMultifilePath() # finally, put it all into a named dictionary keys = ["qgis_version", "gdal", "grass6", "grass7", "saga",\ "supported_saga_versions"] values = [qgis, gdal_v, g6, g7, saga, saga_versions] info = dict(zip(keys, values)) return info
# verify if the provider is well installed if provider.getName() == 'saga': from processing.algs.saga.SagaUtils import SagaUtils msg = SagaUtils.checkSagaIsInstalled() if msg: logging.info(msg) continue elif provider.getName() == 'r': from processing.algs.r.RUtils import RUtils msg = RUtils.checkRIsInstalled() if msg: logging.info(msg) continue elif provider.getName() == 'grass': from processing.algs.grass.GrassUtils import GrassUtils msg = GrassUtils.checkGrassIsInstalled() if msg: logging.info(msg) continue elif provider.getName() == 'grass7': from processing.algs.grass.Grass7Utils import Grass7Utils msg = Grass7Utils.checkGrass7IsInstalled() if msg: logging.info(msg) continue #logging.info( provider.getName()+' active and install') # sort algorithms sortedlist = sorted(provider.algs, key=lambda alg: alg.name) for alg in sortedlist: if algList and str( alg.commandLineName() ) not in algList : continue;