@@ -41,7 +41,6 @@ def __init__(self):
41
41
42
42
self .defineCharacteristics ()
43
43
44
-
45
44
def getCopy (self ):
46
45
newone = copy .copy (self )
47
46
newone .parameters = copy .deepcopy (self .parameters )
@@ -106,8 +105,8 @@ def checkParameterValuesBeforeExecuting(self):
106
105
This check is called from the parameters dialog, and also when calling from the console'''
107
106
return None
108
107
#=========================================================
109
-
110
-
108
+
109
+
111
110
def execute (self , progress ):
112
111
'''The method to use to call a SEXTANTE algorithm.
113
112
Although the body of the algorithm is in processAlgorithm(),
@@ -120,9 +119,9 @@ def execute(self, progress):
120
119
self .resolveTemporaryOutputs ()
121
120
self .checkOutputFileExtensions ()
122
121
self .runPreExecutionScript (progress )
123
- self .processAlgorithm (progress )
122
+ self .processAlgorithm (progress )
124
123
self .convertUnsupportedFormats (progress )
125
- self .runPostExecutionScript (progress )
124
+ self .runPostExecutionScript (progress )
126
125
except GeoAlgorithmExecutionException , gaee :
127
126
SextanteLog .addToLog (SextanteLog .LOG_ERROR , gaee .msg )
128
127
raise gaee
@@ -144,49 +143,49 @@ def execute(self, progress):
144
143
def runPostExecutionScript (self , progress ):
145
144
scriptFile = SextanteConfig .getSetting (SextanteConfig .POST_EXECUTION_SCRIPT )
146
145
self .runHookScript (scriptFile , progress );
147
-
146
+
148
147
def runPreExecutionScript (self , progress ):
149
148
scriptFile = SextanteConfig .getSetting (SextanteConfig .PRE_EXECUTION_SCRIPT )
150
149
self .runHookScript (scriptFile , progress );
151
-
152
- def runHookScript (self , filename , progress ):
150
+
151
+ def runHookScript (self , filename , progress ):
153
152
if not os .path .exists (filename ):
154
153
return
155
- try :
154
+ try :
156
155
script = "import sextante\n "
157
156
ns = {}
158
157
ns ['progress' ] = progress
159
- ns ['alg' ] = self
158
+ ns ['alg' ] = self
160
159
f = open (filename )
161
160
lines = f .readlines ()
162
161
for line in lines :
163
162
script += line
164
- exec (script ) in ns
163
+ exec (script ) in ns
165
164
except : # a wrong script should not cause problems, so we swallow all exceptions
166
165
pass
167
-
166
+
168
167
def convertUnsupportedFormats (self , progress ):
169
168
i = 0
170
169
progress .setText ("Converting outputs" )
171
- for out in self .outputs :
172
- if isinstance (out , OutputVector ):
170
+ for out in self .outputs :
171
+ if isinstance (out , OutputVector ):
173
172
if out .compatible is not None :
174
173
layer = QGisLayers .getObjectFromUri (out .compatible )
175
174
provider = layer .dataProvider ()
176
175
writer = out .getVectorWriter ( provider .fields (), provider .geometryType (), provider .crs ())
177
176
features = QGisLayers .features (layer )
178
177
for feature in features :
179
178
writer .addFeature (feature )
180
- elif isinstance (out , OutputRaster ):
179
+ elif isinstance (out , OutputRaster ):
181
180
if out .compatible is not None :
182
181
layer = QGisLayers .getObjectFromUri (out .compatible )
183
182
provider = layer .dataProvider ()
184
183
writer = QgsRasterFileWriter (out .value )
185
184
format = self .getFormatShortNameFromFilename (out .value )
186
- writer .setOutputFormat (format );
187
- writer .writeRaster (layer .pipe (), layer .width (), layer .height (), layer .extent (), layer .crs ())
188
- progress .setPercentage (100 * i / float (len (self .outputs )))
189
-
185
+ writer .setOutputFormat (format );
186
+ writer .writeRaster (layer .pipe (), layer .width (), layer .height (), layer .extent (), layer .crs ())
187
+ progress .setPercentage (100 * i / float (len (self .outputs )))
188
+
190
189
def getFormatShortNameFromFilename (self , filename ):
191
190
ext = filename [filename .rfind ("." )+ 1 :]
192
191
supported = GdalUtils .getSupportedRasters ()
@@ -195,7 +194,7 @@ def getFormatShortNameFromFilename(self, filename):
195
194
if ext in exts :
196
195
return name
197
196
return "GTiff"
198
-
197
+
199
198
def checkOutputFileExtensions (self ):
200
199
'''Checks if the values of outputs are correct and have one of the supported output extensions.
201
200
If not, it adds the first one of the supported extensions, which is assumed to be the default one'''
0 commit comments