27
27
28
28
from processing .core .parameters import ParameterRaster , getParameterFromString
29
29
from processing .tools .system import isWindows
30
+ from ..Grass7Utils import Grass7Utils
31
+ from os import path
30
32
31
33
32
34
def multipleOutputDir (alg , field , basename = None ):
@@ -92,9 +94,12 @@ def orderedInput(alg, inputParameter, targetParameterDef):
92
94
return rootFilename
93
95
94
96
95
- def regroupRasters (alg , field , groupField , subgroupField = None ):
97
+ def regroupRasters (alg , field , groupField , subgroupField = None , sigsetField = None ):
96
98
"""
97
99
Group multiple input rasters into a group
100
+ * If there is a subgroupField, a subgroup will automatically created.
101
+ * When a sigset file is provided, the file is copied into the sigset
102
+ directory of the subgroup.
98
103
"""
99
104
# List of rasters names
100
105
rasters = alg .getParameterFromName (field )
@@ -118,6 +123,19 @@ def regroupRasters(alg, field, groupField, subgroupField=None):
118
123
)
119
124
alg .commands .append (command )
120
125
126
+ # If there is a sigset and a subgroupField, we copy the sigset file
127
+ if subgroupField and sigsetField :
128
+ sigsetFile = alg .getParameterValue (sigsetField )
129
+ shortSigsetFile = path .basename (sigsetFile )
130
+ if sigsetFile :
131
+ interSigsetFile = path .join (Grass7Utils .grassMapsetFolder (),
132
+ 'PERMANENT' ,
133
+ 'group' , group .value ,
134
+ 'subgroup' , subgroup .value ,
135
+ 'sigset' , shortSigsetFile )
136
+ copyFile (alg , sigsetFile , interSigsetFile )
137
+ alg .setParameterValue (sigsetField , shortSigsetFile )
138
+
121
139
# modify parameters values
122
140
alg .processCommand ()
123
141
@@ -127,8 +145,6 @@ def regroupRasters(alg, field, groupField, subgroupField=None):
127
145
alg .parameters .remove (group )
128
146
if subgroupField :
129
147
alg .parameters .remove (subgroup )
130
-
131
- if subgroupField :
132
148
return group .value , subgroup .value
133
149
134
150
return group .value
@@ -176,10 +192,32 @@ def file2Output(alg, output):
176
192
return outputFile
177
193
178
194
195
+ def createDestDir (alg , toFile ):
196
+ """ Generates an mkdir command for GRASS7 script """
197
+ # Creates the destination directory
198
+ command = "{} {}" .format (
199
+ "MD" if isWindows () else "mkdir -p" ,
200
+ path .dirname (toFile )
201
+ )
202
+ alg .commands .append (command )
203
+
204
+
179
205
def moveFile (alg , fromFile , toFile ):
180
- # move the file
181
- if isWindows ():
182
- command = "MOVE /Y {} {}" .format (fromFile , toFile )
183
- else :
184
- command = "mv -f {} {}" .format (fromFile , toFile )
206
+ """ Generates a move command for GRASS7 script """
207
+ createDestDir (alg , toFile )
208
+ command = "{} {} {}" .format (
209
+ "MOVE /Y" if isWindows () else "mv -f" ,
210
+ fromFile ,
211
+ toFile
212
+ )
213
+ alg .commands .append (command )
214
+
215
+
216
+ def copyFile (alg , fromFile , toFile ):
217
+ """ Generates a copy command for GRASS7 script """
218
+ createDestDir (alg , toFile )
219
+ command = "{} {} {}" .format (
220
+ "COPY /Y" if isWindows () else "cp -f" ,
221
+ fromFile ,
222
+ toFile )
185
223
alg .commands .append (command )
0 commit comments