pktools  2.6.3
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
29 from pktools.pkcomposite import pkcomposite
30 from pktools.pkcrop import pkcrop
31 from pktools.pkreclass import pkreclass
32 from pktools.pkgetmask import pkgetmask
33 from pktools.pksetmask import pksetmask
34 #raster/vector utilities
35 from pktools.pkextract import pkextract
36 from pktools.pkextract_grid import pkextract_grid
37 from pktools.pkextract_random import pkextract_random
38 #Supervised classification utilities
39 from pktools.pksvm import pksvm
40 #LiDAR utilities
41 from pktools.pklas2img import pklas2img
42 from pktools.pkfilterdem import pkfilterdem
43 #filter utilities
44 from pktools.pkfilter_spectral import pkfilter_spectral
45 from pktools.pkfilter_spatial import pkfilter_spatial
46 
47 from processing.core.AlgorithmProvider import AlgorithmProvider
48 from processing.core.ProcessingConfig import Setting, ProcessingConfig
49 import os
50 from PyQt4 import QtGui
51 from pktools.pktoolsUtils import pktoolsUtils
52 
53 
54 class pktoolsAlgorithmProvider(AlgorithmProvider):
55 
56  MY_DUMMY_SETTING = "MY_DUMMY_SETTING"
57 
58  def __init__(self):
59  AlgorithmProvider.__init__(self)
60  # deactivate provider by default
61  self.activate = True
62  # load algorithms
63 # self.alglist = [pkinfo()]
64  self.alglist = [pkreclass(),pkcrop(),pkcomposite(),pkgetmask(),pksetmask(),pkextract(),pkextract_grid(),pkextract_random(),pksvm(),pklas2img(),pkfilterdem(),pkfilter_spectral(),pkfilter_spatial()]
65  # pktools = [pkinfo()]
66  # for alg in pktools:
67  # alg.group = "pktools"
68  # self.alglist.extend(pktools)
69  for alg in self.alglist:
70  alg.provider = self
71 
72  def initializeSettings(self):
73  '''In this method we add settings needed to configure our provider.
74  Do not forget to call the parent method, since it takes care or
75  automatically adding a setting for activating or deactivating the
76  algorithms in the provider
77  '''
78  AlgorithmProvider.initializeSettings(self)
79  ProcessingConfig.addSetting(Setting(self.getDescription(), pktoolsUtils.PKTOOLS_FOLDER, "pktools folder", pktoolsUtils.pktoolsPath()))
80 
81 # ProcessingConfig.addSetting(Setting("Example algorithms", pktoolsAlgorithmProvider.MY_DUMMY_SETTING, "Example setting", "Default value"))
82  # '''To get the parameter of a setting parameter, use
83 # ProcessingConfig.getSetting(name_of_parameter)
84 # '''
85 
86  def unload(self):
87  '''Setting should be removed here, so they do not appear anymore
88  when the plugin is unloaded'''
89  AlgorithmProvider.unload(self)
90  ProcessingConfig.removeSetting(pktoolsAlgorithmProvider.MY_DUMMY_SETTING)
91 
92  def getName(self):
93  '''This is the name that will appear on the toolbox group.
94  It is also used to create the command line name of all the algorithms
95  from this provider
96  '''
97  return "pktools"
98 
99  def getDescription(self):
100  '''This is the provired full name.
101  '''
102  return "Utilities for remote sensing image processing"
103 
104  def getIcon(self):
105  filepath = os.path.dirname(__file__) + "/logo.png"
106  return QtGui.QIcon(filepath)
107 
108  def _loadAlgorithms(self):
109  '''Here we fill the list of algorithms in self.algs.
110  This method is called whenever the list of algorithms should be updated.
111  If the list of algorithms can change
112  (for instance, if it contains algorithms from user-defined scripts and
113  a new script might have been added), you should create the list again
114  here.
115  In this case, since the list is always the same, we assign from the pre-made list.
116  This assignment has to be done in this method even if the list does not change,
117  since the self.algs list is cleared before calling this method
118  '''
119  self.algs = self.alglist