|
24 | 24 |
|
25 | 25 | from PyQt4.QtCore import *
|
26 | 26 | from PyQt4.QtGui import *
|
27 |
| - |
| 27 | +from qgis.core import * |
28 | 28 | from sextante.core.QGisLayers import QGisLayers
|
29 | 29 | from sextante.core.SextanteConfig import SextanteConfig
|
30 | 30 | from sextante.core.GeoAlgorithm import GeoAlgorithm
|
@@ -238,45 +238,14 @@ def getAlgorithm(name):
|
238 | 238 | return provider[name]
|
239 | 239 | return None
|
240 | 240 |
|
241 |
| - |
242 |
| - ##This methods are here to be used from the python console, |
243 |
| - ##making it easy to use SEXTANTE from there |
244 |
| - ##========================================================== |
245 |
| - |
246 |
| - @staticmethod |
247 |
| - def alglist(text=None): |
248 |
| - s="" |
249 |
| - for provider in Sextante.algs.values(): |
250 |
| - sortedlist = sorted(provider.values(), key= lambda alg: alg.name) |
251 |
| - for alg in sortedlist: |
252 |
| - if text == None or text.lower() in alg.name.lower(): |
253 |
| - s+=(alg.name.ljust(50, "-") + "--->" + alg.commandLineName() + "\n") |
254 |
| - print s |
255 |
| - |
256 |
| - |
257 | 241 | @staticmethod
|
258 |
| - def algoptions(name): |
259 |
| - alg = Sextante.getAlgorithm(name) |
260 |
| - if alg != None: |
261 |
| - s ="" |
262 |
| - for param in alg.parameters: |
263 |
| - if isinstance(param, ParameterSelection): |
264 |
| - s+=param.name + "(" + param.description + ")\n" |
265 |
| - i=0 |
266 |
| - for option in param.options: |
267 |
| - s+= "\t" + str(i) + " - " + str(option) + "\n" |
268 |
| - i+=1 |
269 |
| - print(s) |
270 |
| - else: |
271 |
| - print "Algorithm not found" |
| 242 | + def getObject(uri): |
| 243 | + '''Returns the QGIS object identified by the given URI''' |
| 244 | + return QGisLayers.getObjectFromUri(uri) |
272 | 245 |
|
273 | 246 | @staticmethod
|
274 |
| - def alghelp(name): |
275 |
| - alg = Sextante.getAlgorithm(name) |
276 |
| - if alg != None: |
277 |
| - print(str(alg)) |
278 |
| - else: |
279 |
| - print "Algorithm not found" |
| 247 | + def runandload(name, *args): |
| 248 | + Sextante.runAlgorithm(name, SextantePostprocessing.handleAlgorithmResults, *args) |
280 | 249 |
|
281 | 250 | @staticmethod
|
282 | 251 | def runAlgorithm(algOrName, onFinish, *args):
|
@@ -359,28 +328,80 @@ def cancel():
|
359 | 328 | QApplication.restoreOverrideCursor()
|
360 | 329 | return alg
|
361 | 330 |
|
362 |
| - @staticmethod |
363 |
| - def runalg(algOrName, *args): |
364 |
| - alg = Sextante.runAlgorithm(algOrName, None, *args) |
365 |
| - return alg.getOutputValuesAsDictionary() |
366 |
| - |
367 | 331 |
|
368 |
| - @staticmethod |
369 |
| - def load(layer): |
370 |
| - '''Loads a layer into QGIS''' |
371 |
| - QGisLayers.load(layer) |
| 332 | + ##========================================================== |
| 333 | + ##This methods are here to be used from the python console, |
| 334 | + ##making it easy to use SEXTANTE from there |
| 335 | + ##========================================================== |
372 | 336 |
|
373 |
| - @staticmethod |
374 |
| - def loadFromAlg(layersdict): |
375 |
| - '''Load all layer resulting from a given algorithm. |
376 |
| - Layers are passed as a dictionary, obtained from alg.getOutputValuesAsDictionary()''' |
377 |
| - QGisLayers.loadFromDict(layersdict) |
378 | 337 |
|
379 |
| - @staticmethod |
380 |
| - def getObject(uri): |
381 |
| - '''Returns the QGIS object identified by the given URI''' |
382 |
| - return QGisLayers.getObjectFromUri(uri) |
383 |
| - |
384 |
| - @staticmethod |
385 |
| - def runandload(name, *args): |
386 |
| - Sextante.runAlgorithm(name, SextantePostprocessing.handleAlgorithmResults, *args) |
| 338 | +def alglist(text=None): |
| 339 | + s="" |
| 340 | + for provider in Sextante.algs.values(): |
| 341 | + sortedlist = sorted(provider.values(), key= lambda alg: alg.name) |
| 342 | + for alg in sortedlist: |
| 343 | + if text == None or text.lower() in alg.name.lower(): |
| 344 | + s+=(alg.name.ljust(50, "-") + "--->" + alg.commandLineName() + "\n") |
| 345 | + print s |
| 346 | + |
| 347 | +def algoptions(name): |
| 348 | + alg = Sextante.getAlgorithm(name) |
| 349 | + if alg != None: |
| 350 | + s ="" |
| 351 | + for param in alg.parameters: |
| 352 | + if isinstance(param, ParameterSelection): |
| 353 | + s+=param.name + "(" + param.description + ")\n" |
| 354 | + i=0 |
| 355 | + for option in param.options: |
| 356 | + s+= "\t" + str(i) + " - " + str(option) + "\n" |
| 357 | + i+=1 |
| 358 | + print(s) |
| 359 | + else: |
| 360 | + print "Algorithm not found" |
| 361 | + |
| 362 | +def alghelp(name): |
| 363 | + alg = Sextante.getAlgorithm(name) |
| 364 | + if alg != None: |
| 365 | + print(str(alg)) |
| 366 | + else: |
| 367 | + print "Algorithm not found" |
| 368 | + |
| 369 | +def runalg(algOrName, *args): |
| 370 | + alg = Sextante.runAlgorithm(algOrName, None, *args) |
| 371 | + return alg.getOutputValuesAsDictionary() |
| 372 | + |
| 373 | +def extent(layers): |
| 374 | + first = True |
| 375 | + for layer in layers: |
| 376 | + if not isinstance(layer, (QgsRasterLayer, QgsVectorLayer)): |
| 377 | + layer = QGisLayers.getObjectFromUri(layer) |
| 378 | + if first: |
| 379 | + xmin = layer.extent().xMinimum() |
| 380 | + xmax = layer.extent().xMaximum() |
| 381 | + ymin = layer.extent().yMinimum() |
| 382 | + ymax = layer.extent().yMaximum() |
| 383 | + else: |
| 384 | + xmin = min(xmin, layer.extent().xMinimum()) |
| 385 | + xmax = max(xmax, layer.extent().xMaximum()) |
| 386 | + ymin = min(ymin, layer.extent().yMinimum()) |
| 387 | + ymax = max(ymax, layer.extent().yMaximum()) |
| 388 | + first = False |
| 389 | + return str(xmin) + "," + str(xmax) + "," + str(ymin) + "," + str(ymax) |
| 390 | + |
| 391 | +def getObjectFromName(name): |
| 392 | + layers = QGisLayers.getAllLayers() |
| 393 | + for layer in layers: |
| 394 | + if layer.name() == name: |
| 395 | + return layer |
| 396 | + |
| 397 | +def getObjectFromUri(uri): |
| 398 | + return QGisLayers.getObjectFromUri(uri, False) |
| 399 | + |
| 400 | +def load(layer): |
| 401 | + '''Loads a layer into QGIS''' |
| 402 | + QGisLayers.load(layer) |
| 403 | + |
| 404 | +def loadFromAlg(layersdict): |
| 405 | + '''Load all layer resulting from a given algorithm. |
| 406 | + Layers are passed as a dictionary, obtained from alg.getOutputValuesAsDictionary()''' |
| 407 | + QGisLayers.loadFromDict(layersdict) |
0 commit comments