Newer
Older
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
import processing
from PyQt5.QtWidgets import (
QAction,
QToolBar,
QApplication,
QDialog
)
from PyQt5.QtCore import pyqtSignal, QObject
from qgis.core import QgsApplication
from qgis.gui import QgisInterface
from .provider import IAMapProvider
from .icons import QIcon_EncoderTool, QIcon_ReductionTool, QIcon_ClusterTool, QIcon_SimilarityTool, QIcon_RandomforestTool
class IAMap(QObject):
execute_iamap = pyqtSignal()
def __init__(self, iface: QgisInterface, cwd: str):
super().__init__()
self.iface = iface
self.cwd = cwd
def initProcessing(self):
self.provider = IAMapProvider()
QgsApplication.processingRegistry().addProvider(self.provider)
def initGui(self):
self.initProcessing()
self.toolbar: QToolBar = self.iface.addToolBar('IAMap Toolbar')
self.toolbar.setObjectName('IAMapToolbar')
self.toolbar.setToolTip('IAMap Toolbar')
self.actionEncoder = QAction(
QIcon_EncoderTool,
"Deep Learning Image Encoder",
self.iface.mainWindow()
)
self.actionReducer = QAction(
QIcon_ReductionTool,
"Reduce dimensions",
self.iface.mainWindow()
)
self.actionCluster = QAction(
QIcon_ClusterTool,
"Cluster raster",
self.iface.mainWindow()
)
self.actionSimilarity = QAction(
QIcon_SimilarityTool,
"Compute similarity",
self.iface.mainWindow()
)
self.actionRF = QAction(
QIcon_RandomforestTool,
"Use Random Forest algorithm",
self.iface.mainWindow()
)
self.actionEncoder.setObjectName("mActionEncoder")
self.actionReducer.setObjectName("mActionReducer")
self.actionCluster.setObjectName("mActionCluster")
self.actionSimilarity.setObjectName("mactionSimilarity")
self.actionRF.setObjectName("mactionRF")
self.actionEncoder.setToolTip(
"Encode a raster with a deep learning backbone")
self.actionReducer.setToolTip(
"Reduce raster dimensions")
self.actionCluster.setToolTip(
"Cluster raster")
self.actionSimilarity.setToolTip(
"Compute similarity")
self.actionRF.setToolTip(
"Use Random Forest ")
self.actionEncoder.triggered.connect(self.encodeImage)
self.actionReducer.triggered.connect(self.reduceImage)
self.actionCluster.triggered.connect(self.clusterImage)
self.actionSimilarity.triggered.connect(self.similarityImage)
self.actionRF.triggered.connect(self.rfImage)
self.toolbar.addAction(self.actionEncoder)
self.toolbar.addAction(self.actionReducer)
self.toolbar.addAction(self.actionCluster)
self.toolbar.addAction(self.actionSimilarity)
self.toolbar.addAction(self.actionRF)
def unload(self):
# self.wdg_select.setVisible(False)
self.iface.removeToolBarIcon(self.actionEncoder)
self.iface.removeToolBarIcon(self.actionReducer)
self.iface.removeToolBarIcon(self.actionCluster)
self.iface.removeToolBarIcon(self.actionSimilarity)
self.iface.removeToolBarIcon(self.actionRF)
del self.actionEncoder
del self.actionReducer
del self.actionCluster
del self.actionSimilarity
del self.actionRF
del self.toolbar
QgsApplication.processingRegistry().removeProvider(self.provider)
def encodeImage(self):
'''
'''
result = processing.execAlgorithmDialog('iamap:encoder', {})
print(result)
# Check if algorithm execution was successful
if result:
# Retrieve output parameters from the result dictionary
if 'OUTPUT_RASTER' in result:
output_raster_path = result['OUTPUT_RASTER']
output_layer_name = result['OUTPUT_LAYER_NAME']
self.iface.addRasterLayer(str(output_raster_path),output_layer_name)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
else:
# Handle missing or unexpected output
print('Output raster not found in algorithm result.')
else:
# Handle algorithm execution failure or cancellation
print('Algorithm execution was not successful.')
# processing.execAlgorithmDialog('', {})
# self.close_all_dialogs()
def reduceImage(self):
'''
'''
result = processing.execAlgorithmDialog('iamap:reduction', {})
print(result)
# Check if algorithm execution was successful
if result:
# Retrieve output parameters from the result dictionary
if 'OUTPUT_RASTER' in result:
output_raster_path = result['OUTPUT_RASTER']
# Add the output raster layer to the map canvas
self.iface.addRasterLayer(str(output_raster_path), 'reduced features')
else:
# Handle missing or unexpected output
print('Output raster not found in algorithm result.')
else:
# Handle algorithm execution failure or cancellation
print('Algorithm execution was not successful.')
# processing.execAlgorithmDialog('', {})
def clusterImage(self):
'''
'''
result = processing.execAlgorithmDialog('iamap:cluster', {})
print(result)
# Check if algorithm execution was successful
if result:
# Retrieve output parameters from the result dictionary
if 'OUTPUT_RASTER' in result:
output_raster_path = result['OUTPUT_RASTER']
# Add the output raster layer to the map canvas
self.iface.addRasterLayer(str(output_raster_path), 'clustering')
else:
# Handle missing or unexpected output
print('Output raster not found in algorithm result.')
else:
# Handle algorithm execution failure or cancellation
print('Algorithm execution was not successful.')
# processing.execAlgorithmDialog('', {})
def similarityImage(self):
'''
'''
result = processing.execAlgorithmDialog('iamap:similarity', {})
print(result)
# Check if algorithm execution was successful
if result:
# Retrieve output parameters from the result dictionary
if 'OUTPUT_RASTER' in result:
output_raster_path = result['OUTPUT_RASTER']
# Add the output raster layer to the map canvas
self.iface.addRasterLayer(str(output_raster_path), 'similarity map')
else:
# Handle missing or unexpected output
print('Output raster not found in algorithm result.')
else:
# Handle algorithm execution failure or cancellation
print('Algorithm execution was not successful.')
# processing.execAlgorithmDialog('', {})
def rfImage(self):
'''
'''
result = processing.execAlgorithmDialog('iamap:Random_forest', {})
print(result)
# Check if algorithm execution was successful
if result:
# Retrieve output parameters from the result dictionary
if 'OUTPUT_RASTER' in result:
output_raster_path = result['OUTPUT_RASTER']
# Add the output raster layer to the map canvas
self.iface.addRasterLayer(str(output_raster_path), 'random forest map')
else:
# Handle missing or unexpected output
print('Output raster not found in algorithm result.')
else:
# Handle algorithm execution failure or cancellation
print('Algorithm execution was not successful.')
# processing.execAlgorithmDialog('', {})
def close_all_dialogs(self):
# Get the main QGIS window (QgisInterface)
qgis_main_window = self.iface.mainWindow()
# Get all open dialogs associated with the main window
open_dialogs = qgis_main_window.findChildren(QDialog)
# Iterate through the open dialogs and close them
for dialog in open_dialogs:
# Check if the dialog is visible (to avoid closing hidden dialogs)
if dialog.isVisible():
# Close the dialog
dialog.close()