-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathlecos_sextanteprov.py
More file actions
136 lines (122 loc) · 5.08 KB
/
Copy pathlecos_sextanteprov.py
File metadata and controls
136 lines (122 loc) · 5.08 KB
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
# -*- 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
***************************************************************************/
from qgis.PyQt.QtCore import *
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
from __future__ import absolute_import
# Import PyQT bindings
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
# Sextante bindings
from qgis.core import QgsProcessingProvider as AlgorithmProvider
from .lecos_dependencies import load_optional_nlmpy_module
from .lecos_sextantealgorithms import *
# Import modules
import tempfile
tmpdir = tempfile.gettempdir() # tempdir
import os
# NLMPY
nlmpy_module = load_optional_nlmpy_module()
HAS_NLMPY = nlmpy_module is not None
HAS_NLMPY_TOOLS = False
nlmpy_algorithms = None
if HAS_NLMPY:
try:
from . import nlmpy_sextantewrapper as nlmpy_algorithms
except Exception:
nlmpy_algorithms = None
else:
HAS_NLMPY_TOOLS = nlmpy_algorithms.NLMPY_DEPENDENCIES_AVAILABLE
class LecoSAlgorithmsProv(AlgorithmProvider):
tmpdir = tmpdir
def __init__(self):
super().__init__()
# Create algorithms list
self.algs = []
def id(self):
return "lecos"
def name(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 icon(self):
'''We return the icon for lecos'''
return QIcon(os.path.join(os.path.dirname(__file__), "icons", "icon.png"))
def getDescription(self):
return "LecoS (Landscape ecology statistics)"
def load(self):
self.refreshAlgorithms()
return True
def unload(self):
'''Setting should be removed here, so they do not appear anymore
when the plugin is unloaded'''
pass
def isActive(self):
return True
def setActive(self, active):
pass
def getAlgs(self):
algs = [CreateRandomLandscape()]
# Load in Algorithms from lecos_sextantealgorithms
# Landscape preperation
algs.append( MatchLandscapes() )
algs.append( RasterWithRasterClip() )
algs.append( CountRasterCells() )
algs.append( GetRasterValuesPoint() )
if CORE_DEPENDENCIES_AVAILABLE:
# Landscape statistics
algs.append( LandscapeStatistics() )
algs.append( PatchStatistics() )
algs.append( ZonalStatistics() )
# Landscape Vector Overlay
if POLYGON_OVERLAY_DEPENDENCIES_AVAILABLE:
algs.append( RasterPolyOver() )
#algs.append( VectorPolyOver() )
# Landscape modifications
algs.append( LabelLandscapePatches() )
algs.append( NeighbourhoodAnalysis() )
algs.append( IncreaseLandPatch() )
algs.append( ExtractEdges() )
algs.append( IsolateExtremePatch() )
algs.append( CloseHoles() )
algs.append( CleanSmallPixels() )
# TODO: Won't work
# NLMPY if available
if HAS_NLMPY_TOOLS and nlmpy_algorithms is not None:
algs.append( nlmpy_algorithms.RandomElementNN() )
algs.append( nlmpy_algorithms.RandomClusterNN() )
algs.append( nlmpy_algorithms.LinearRescale01() )
algs.append( nlmpy_algorithms.RandomUniformed01() )
algs.append( nlmpy_algorithms.SpatialRandom() )
algs.append( nlmpy_algorithms.PlanarGradient() )
algs.append( nlmpy_algorithms.EdgeGradient() )
algs.append( nlmpy_algorithms.DistanceGradient() )
algs.append( nlmpy_algorithms.MidpointDisplacement() )
algs.append( nlmpy_algorithms.RandomRectangularCluster() )
algs.append( nlmpy_algorithms.MeanOfCluster() )
algs.append( nlmpy_algorithms.ClassifyArray() )
return algs
def loadAlgorithms(self):
'''Create list of Arguments'''
self.algs = self.getAlgs()
for a in self.algs:
self.addAlgorithm(a)
def tr(self, string, context=''):
return QCoreApplication.translate(context or 'LecoSAlgorithmsProv', string)