-
Notifications
You must be signed in to change notification settings - Fork 19
/
lecos_sextanteprov.py
145 lines (121 loc) · 5.91 KB
/
lecos_sextanteprov.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
"""
/***************************************************************************
LecoS
A QGIS plugin
Contains analytical functions for landscape analysis
-------------------
begin : 2012-09-06
copyright : (C) 2013 by Martin Jung
email : martinjung at zoho.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. *
* *
***************************************************************************/
"""
# Import PyQT bindings
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# Sextante bindings
from processing.core.AlgorithmProvider import AlgorithmProvider
from processing.core.ProcessingConfig import Setting, ProcessingConfig
from processing.core.ProcessingLog import ProcessingLog
from lecos_sextantealgorithms import *
# Import modules
import tempfile
tmpdir = tempfile.gettempdir() # tempdir
import os
# NLMPY
nlmpy = False
try:
import nlmpy
except ImportError:
nlmpy = True
if nlmpy:
from nlmpy_sextantewrapper import *
class LecoSAlgorithmsProv(AlgorithmProvider):
tmpdir = tmpdir
def __init__(self):
AlgorithmProvider.__init__(self)
# Create algorithms list
self.createAlgsList()
def getDescription(self):
return "LecoS (Landscape ecology statistics)"
def initializeSettings(self):
'''In this method we add settings needed to configure our provider.
Do not forget to call the parent method, since it takes care or
automatically adding a setting for activating or deactivating the
algorithms in the provider'''
AlgorithmProvider.initializeSettings(self)
#SextanteConfig.addSetting(Setting(self.getDescription(), LecoSAlgorithmsProv.tmpdir, "Temporary Directory", tmpdir))
'''To get the parameter of a setting parameter, use SextanteConfig.getSetting(name_of_parameter)'''
def unload(self):
'''Setting should be removed here, so they do not appear anymore
when the plugin is unloaded'''
AlgorithmProvider.unload(self)
#SextanteConfig.removeSetting(LecoSAlgorithmsProv.tmpdir)
def getName(self):
'''This is the name that will appear on the toolbox group.
It is also used to create the command line name of all the algorithms
from this provider'''
return "lecos"
def getIcon(self):
'''We return the icon for lecos'''
return QIcon(os.path.dirname(__file__) + os.sep+"icons"+os.sep+"icon.png")
def createAlgsList(self):
'''Create list of Arguments'''
self.preloadedAlgs = []
# Load in Algorithms from lecos_sextantealgorithms
# Landscape preperation
self.preloadedAlgs.append( CreateRandomLandscape() )
self.preloadedAlgs.append( MatchLandscapes() )
self.preloadedAlgs.append( RasterWithRasterClip() )
# Landscape statistics
self.preloadedAlgs.append( LandscapeStatistics() )
self.preloadedAlgs.append( PatchStatistics() )
self.preloadedAlgs.append( CountRasterCells() )
self.preloadedAlgs.append( ZonalStatistics() )
# Landscape Vector Overlay
self.preloadedAlgs.append( RasterPolyOver() )
self.preloadedAlgs.append( GetRasterValuesPoint() )
#self.preloadedAlgs.append( VectorPolyOver() )
# Landscape modifications
self.preloadedAlgs.append( LabelLandscapePatches() )
self.preloadedAlgs.append( NeighbourhoodAnalysis() )
self.preloadedAlgs.append( IncreaseLandPatch() )
self.preloadedAlgs.append( ExtractEdges() )
self.preloadedAlgs.append( IsolateExtremePatch() )
self.preloadedAlgs.append( CloseHoles() )
self.preloadedAlgs.append( CleanSmallPixels() )
# NLMPY if available
if nlmpy:
self.preloadedAlgs.append( RandomElementNN() )
self.preloadedAlgs.append( RandomClusterNN() )
self.preloadedAlgs.append( LinearRescale01() )
self.preloadedAlgs.append( RandomUniformed01() )
self.preloadedAlgs.append( SpatialRandom() )
self.preloadedAlgs.append( PlanarGradient() )
self.preloadedAlgs.append( EdgeGradient() )
self.preloadedAlgs.append( DistanceGradient() )
self.preloadedAlgs.append( MidpointDisplacement() )
self.preloadedAlgs.append( RandomRectangularCluster() )
self.preloadedAlgs.append( MeanOfCluster() )
self.preloadedAlgs.append( ClassifyArray() )
for alg in self.preloadedAlgs:
alg.provider = self # reset provider
def _loadAlgorithms(self):
'''Here we fill the list of algorithms in self.algs.
This method is called whenever the list of algorithms should be updated.
If the list of algorithms can change while executing SEXTANTE for QGIS
(for instance, if it contains algorithms from user-defined scripts and
a new script might have been added), you should create the list again
here.
In this case, since the list is always the same, we assign from the pre-made list.
This assignment has to be done in this method even if the list does not change,
since the self.algs list is cleared before calling this method'''
self.algs = self.preloadedAlgs