Skip to content

Commit 7e209b9

Browse files
committed
Merge pull request #1279 from pka/grass7
[FEATURE] (Processing) Initial Grass 7 support
2 parents 6852f9e + 72457b3 commit 7e209b9

File tree

181 files changed

+3268
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3268
-0
lines changed

python/plugins/processing/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ADD_SUBDIRECTORY(commander)
66
ADD_SUBDIRECTORY(core)
77
ADD_SUBDIRECTORY(gdal)
88
ADD_SUBDIRECTORY(grass)
9+
ADD_SUBDIRECTORY(grass7)
910
ADD_SUBDIRECTORY(gui)
1011
ADD_SUBDIRECTORY(images)
1112
ADD_SUBDIRECTORY(lidar)

python/plugins/processing/core/Processing.py

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
ModelerOnlyAlgorithmProvider
4949
from processing.algs.QGISAlgorithmProvider import QGISAlgorithmProvider
5050
from processing.grass.GrassAlgorithmProvider import GrassAlgorithmProvider
51+
from processing.grass7.Grass7AlgorithmProvider import Grass7AlgorithmProvider
5152
from processing.lidar.LidarToolsAlgorithmProvider import \
5253
LidarToolsAlgorithmProvider
5354
from processing.gdal.GdalOgrAlgorithmProvider import GdalOgrAlgorithmProvider
@@ -146,6 +147,7 @@ def initialize():
146147
Processing.addProvider(RAlgorithmProvider())
147148
Processing.addProvider(SagaAlgorithmProvider())
148149
Processing.addProvider(GrassAlgorithmProvider())
150+
Processing.addProvider(Grass7AlgorithmProvider())
149151
Processing.addProvider(ScriptAlgorithmProvider())
150152
Processing.addProvider(TauDEMAlgorithmProvider())
151153
Processing.addProvider(AdminToolsAlgorithmProvider())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FILE(GLOB PY_FILES *.py)
2+
FILE(GLOB OTHER_FILES grass7.txt)
3+
FILE(GLOB DESCR_FILES description/*.txt)
4+
5+
ADD_SUBDIRECTORY(ext)
6+
7+
PLUGIN_INSTALL(processing grass7 ${PY_FILES} ${OTHER_FILES})
8+
PLUGIN_INSTALL(processing grass7/description ${DESCR_FILES})

python/plugins/processing/grass7/Grass7Algorithm.py

+544
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
Grass7AlgorithmProvider.py
6+
---------------------
7+
Date : April 2014
8+
Copyright : (C) 2014 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
from processing.grass7.nviz7 import nviz7
21+
22+
__author__ = 'Victor Olaya'
23+
__date__ = 'April 2014'
24+
__copyright__ = '(C) 2014, Victor Olaya'
25+
26+
# This will get replaced with a git SHA1 when you do a git archive
27+
28+
__revision__ = '$Format:%H$'
29+
30+
import os
31+
from PyQt4.QtCore import *
32+
from PyQt4.QtGui import *
33+
from processing.core.ProcessingConfig import ProcessingConfig, Setting
34+
from processing.core.AlgorithmProvider import AlgorithmProvider
35+
from processing.core.ProcessingLog import ProcessingLog
36+
from processing.grass7.Grass7Utils import Grass7Utils
37+
from processing.grass7.Grass7Algorithm import Grass7Algorithm
38+
from processing.tools.system import *
39+
40+
41+
class Grass7AlgorithmProvider(AlgorithmProvider):
42+
43+
def __init__(self):
44+
AlgorithmProvider.__init__(self)
45+
self.createAlgsList() # Preloading algorithms to speed up
46+
47+
def initializeSettings(self):
48+
AlgorithmProvider.initializeSettings(self)
49+
if isWindows() or isMac():
50+
ProcessingConfig.addSetting(Setting(self.getDescription(),
51+
Grass7Utils.GRASS_FOLDER, 'GRASS7 folder',
52+
Grass7Utils.grassPath()))
53+
ProcessingConfig.addSetting(Setting(self.getDescription(),
54+
Grass7Utils.GRASS_WIN_SHELL, 'Msys folder',
55+
Grass7Utils.grassWinShell()))
56+
ProcessingConfig.addSetting(Setting(self.getDescription(),
57+
Grass7Utils.GRASS_LOG_COMMANDS,
58+
'Log execution commands', False))
59+
ProcessingConfig.addSetting(Setting(self.getDescription(),
60+
Grass7Utils.GRASS_LOG_CONSOLE,
61+
'Log console output', False))
62+
63+
def unload(self):
64+
AlgorithmProvider.unload(self)
65+
if isWindows() or isMac():
66+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_FOLDER)
67+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_WIN_SHELL)
68+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_COMMANDS)
69+
ProcessingConfig.removeSetting(Grass7Utils.GRASS_LOG_CONSOLE)
70+
71+
def createAlgsList(self):
72+
self.preloadedAlgs = []
73+
folder = Grass7Utils.grassDescriptionPath()
74+
for descriptionFile in os.listdir(folder):
75+
if descriptionFile.endswith('txt'):
76+
try:
77+
alg = Grass7Algorithm(os.path.join(folder, descriptionFile))
78+
if alg.name.strip() != '':
79+
self.preloadedAlgs.append(alg)
80+
else:
81+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
82+
'Could not open GRASS GIS 7 algorithm: '
83+
+ descriptionFile)
84+
except Exception, e:
85+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
86+
'Could not open GRASS GIS 7 algorithm: '
87+
+ descriptionFile)
88+
self.preloadedAlgs.append(nviz7())
89+
90+
def _loadAlgorithms(self):
91+
self.algs = self.preloadedAlgs
92+
93+
def getDescription(self):
94+
return 'GRASS GIS 7 commands'
95+
96+
def getName(self):
97+
return 'grass70'
98+
99+
def getIcon(self):
100+
return QIcon(os.path.dirname(__file__) + '/../images/grass.png')
101+
102+
def getSupportedOutputVectorLayerExtensions(self):
103+
return ['shp']
104+
105+
def getSupportedOutputRasterLayerExtensions(self):
106+
return ['tif']
107+

0 commit comments

Comments
 (0)