4
4
***************************************************************************
5
5
i.py
6
6
----
7
- Date : February 2016
7
+ Date : April 2016
8
8
Copyright : (C) 2016 by Médéric Ribreux
9
- Email : medspx at medspx dot fr
9
+ Email : mederic dot ribreux at medspx dot fr
10
10
***************************************************************************
11
11
* *
12
12
* This program is free software; you can redistribute it and/or modify *
18
18
"""
19
19
20
20
__author__ = 'Médéric Ribreux'
21
- __date__ = 'March 2016'
21
+ __date__ = 'April 2016'
22
22
__copyright__ = '(C) 2016, Médéric Ribreux'
23
23
24
24
# This will get replaced with a git SHA1 when you do a git archive
@@ -94,12 +94,13 @@ def orderedInput(alg, inputParameter, targetParameterDef):
94
94
return rootFilename
95
95
96
96
97
- def regroupRasters (alg , field , groupField , subgroupField = None , sigsetField = None ):
97
+ def regroupRasters (alg , field , groupField , subgroupField = None , extFile = None ):
98
98
"""
99
99
Group multiple input rasters into a group
100
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
101
+ * When an external file is provided, the file is copied into the respective
102
102
directory of the subgroup.
103
+ * extFile is a dict of the form 'parameterName':'directory name'.
103
104
"""
104
105
# List of rasters names
105
106
rasters = alg .getParameterFromName (field )
@@ -123,24 +124,32 @@ def regroupRasters(alg, field, groupField, subgroupField=None, sigsetField=None)
123
124
)
124
125
alg .commands .append (command )
125
126
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 )
127
+ # Handle external files
128
+ origExtParams = {}
129
+ if subgroupField and extFile :
130
+ for ext in extFile .keys ():
131
+ extFileName = alg .getParameterValue (ext )
132
+ if extFileName :
133
+ shortFileName = path .basename (extFileName )
134
+ destPath = path .join (Grass7Utils .grassMapsetFolder (),
135
+ 'PERMANENT' ,
136
+ 'group' , group .value ,
137
+ 'subgroup' , subgroup .value ,
138
+ extFile [ext ], shortFileName )
139
+ copyFile (alg , extFileName , destPath )
140
+ origExtParams [ext ] = extFileName
141
+ alg .setParameterValue (ext , shortFileName )
138
142
139
143
# modify parameters values
140
144
alg .processCommand ()
141
145
142
146
# Re-add input rasters
143
147
alg .addParameter (rasters )
148
+
149
+ # replace external files value with original value
150
+ for param in origExtParams .keys ():
151
+ alg .setParameterValue (param , origExtParams [param ])
152
+
144
153
# Delete group:
145
154
alg .parameters .remove (group )
146
155
if subgroupField :
0 commit comments