File: general.py

package info (click to toggle)
qgis 2.14.11%2Bdfsg-3%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 991,448 kB
  • ctags: 73,105
  • sloc: cpp: 535,362; python: 162,580; xml: 16,494; ansic: 8,031; sh: 1,788; perl: 1,559; sql: 727; yacc: 319; lex: 269; makefile: 251
file content (77 lines) | stat: -rw-r--r-- 2,646 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-

"""
***************************************************************************
    general.py
    ---------------------
    Date                 : April 2013
    Copyright            : (C) 2013 by Victor Olaya
    Email                : volayaf at gmail dot com
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'April 2013'
__copyright__ = '(C) 2013, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from processing.core.Processing import Processing
from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.parameters import ParameterSelection


def alglist(text=None):
    s = ''
    for provider in Processing.algs.values():
        sortedlist = sorted(provider.values(), key=lambda alg: alg.name)
        for alg in sortedlist:
            if text is None or text.lower() in alg.name.lower():
                s += alg.name.ljust(50, '-') + '--->' + alg.commandLineName() \
                    + '\n'
    print s


def algoptions(name):
    alg = Processing.getAlgorithm(name)
    if alg is not None:
        s = ''
        for param in alg.parameters:
            if isinstance(param, ParameterSelection):
                s += param.name + '(' + param.description + ')\n'
                i = 0
                for option in param.options:
                    s += '\t' + unicode(i) + ' - ' + unicode(option) + '\n'
                    i += 1
        print s
    else:
        print 'Algorithm not found'


def alghelp(name):
    alg = Processing.getAlgorithm(name)
    if alg is not None:
        alg = alg.getCopy()
        print unicode(alg)
        algoptions(name)
    else:
        print 'Algorithm not found'


def runalg(algOrName, *args, **kwargs):
    alg = Processing.runAlgorithm(algOrName, None, *args, **kwargs)
    if alg is not None:
        return alg.getOutputValuesAsDictionary()


def runandload(name, *args, **kwargs):
    return Processing.runAlgorithm(name, handleAlgorithmResults, *args, **kwargs)