pktools 2.6.7
Processing Kernel for geospatial data
pktoolsAlgorithmProvider.py
1# -*- coding: utf-8 -*-
2
3"""
4***************************************************************************
5 pktoolsAlgorithmProvider.py
6 ---------------------
7 Date : April 2015
8 Copyright : (C) 2015 by Pieter Kempeneers
9 Email : kempenep at gmail dot com
10***************************************************************************
11* *
12* This program is free software; you can redistribute it and/or modify *
13* it under the terms of the GNU General Public License as published by *
14* the Free Software Foundation; either version 2 of the License, or *
15* (at your option) any later version. *
16* *
17***************************************************************************
18"""
19
20__author__ = 'Pieter Kempeneers'
21__date__ = 'April 2015'
22__copyright__ = '(C) 2015, Pieter Kempeneers'
23# This will get replaced with a git SHA1 when you do a git archive
24__revision__ = '$Format:%H$'
25
26
27#from pktools.ExampleAlgorithm import ExampleAlgorithm
28#raster utilities
29from pktools.pkcomposite import pkcomposite
30from pktools.pkcrop import pkcrop
31from pktools.pkreclass import pkreclass
32from pktools.pkgetmask import pkgetmask
33from pktools.pksetmask import pksetmask
34#raster/vector utilities
35from pktools.pkextract import pkextract
36from pktools.pkextract_grid import pkextract_grid
37from pktools.pkextract_random import pkextract_random
38#Supervised classification utilities
39from pktools.pksvm import pksvm
40from pktools.pkdiff_accuracy import pkdiff_accuracy
41#LiDAR utilities
42from pktools.pklas2img import pklas2img
43from pktools.pkfilterdem import pkfilterdem
44#filter utilities
45from pktools.pkfilter_spectral import pkfilter_spectral
46from pktools.pkfilter_spatial import pkfilter_spatial
47
48from processing.core.AlgorithmProvider import AlgorithmProvider
49from processing.core.ProcessingConfig import Setting, ProcessingConfig
50import os
51from PyQt4 import QtGui
52from pktools.pktoolsUtils import pktoolsUtils
53
54
55class pktoolsAlgorithmProvider(AlgorithmProvider):
56
57 MY_DUMMY_SETTING = "MY_DUMMY_SETTING"
58
59 def __init__(self):
60 AlgorithmProvider.__init__(self)
61 # deactivate provider by default
62 self.activate = True
63 # load algorithms
64# self.alglist = [pkinfo()]
65 self.alglist = [pkreclass(),pkcrop(),pkcomposite(),pkgetmask(),pksetmask(),pkextract(),pkextract_grid(),pkextract_random(),pksvm(),pkdiff_accuracy(),pklas2img(),pkfilterdem(),pkfilter_spectral(),pkfilter_spatial()]
66 # pktools = [pkinfo()]
67 # for alg in pktools:
68 # alg.group = "pktools"
69 # self.alglist.extend(pktools)
70 for alg in self.alglist:
71 alg.provider = self
72
74 '''In this method we add settings needed to configure our provider.
75 Do not forget to call the parent method, since it takes care or
76 automatically adding a setting for activating or deactivating the
77 algorithms in the provider
78 '''
79 AlgorithmProvider.initializeSettings(self)
80 ProcessingConfig.addSetting(Setting(self.getDescription(), pktoolsUtils.PKTOOLS_FOLDER, "pktools folder", pktoolsUtils.pktoolsPath()))
81
82# ProcessingConfig.addSetting(Setting("Example algorithms", pktoolsAlgorithmProvider.MY_DUMMY_SETTING, "Example setting", "Default value"))
83 # '''To get the parameter of a setting parameter, use
84# ProcessingConfig.getSetting(name_of_parameter)
85# '''
86
87 def unload(self):
88 '''Setting should be removed here, so they do not appear anymore
89 when the plugin is unloaded'''
90 AlgorithmProvider.unload(self)
91 ProcessingConfig.removeSetting(pktoolsAlgorithmProvider.MY_DUMMY_SETTING)
92
93 def getName(self):
94 '''This is the name that will appear on the toolbox group.
95 It is also used to create the command line name of all the algorithms
96 from this provider
97 '''
98 return "pktools"
99
100 def getDescription(self):
101 '''This is the provired full name.
102 '''
103 return "Utilities for remote sensing image processing"
104
105 def getIcon(self):
106 filepath = os.path.dirname(__file__) + "/logo.png"
107 return QtGui.QIcon(filepath)
108
109 def _loadAlgorithms(self):
110 '''Here we fill the list of algorithms in self.algs.
111 This method is called whenever the list of algorithms should be updated.
112 If the list of algorithms can change
113 (for instance, if it contains algorithms from user-defined scripts and
114 a new script might have been added), you should create the list again
115 here.
116 In this case, since the list is always the same, we assign from the pre-made list.
117 This assignment has to be done in this method even if the list does not change,
118 since the self.algs list is cleared before calling this method
119 '''
120 self.algs = self.alglist