-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui_walkingtime.py
123 lines (102 loc) · 4.68 KB
/
ui_walkingtime.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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Walking Time
A QGIS plugin
Module implementing WtPluginDialog. The Dialog for Walking time plugin.
-------------------
begin : 2013-09-27
copyright : (C) 2013 by Alexandre Neto / Cascais Ambiente
email : [email protected]
***************************************************************************/
****************************************************************************
* *
* 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
from builtins import str
from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QDialog
from qgis.core import QgsProject
import os
pluginPath = os.path.dirname(__file__)
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui_walkingtime.ui'))
class WtPluginDialog(BASE, WIDGET):
"""
Class documentation goes here.
"""
def __init__(self, iface):
"""
Constructor
"""
QDialog.__init__(self)
self.setupUi(self)
self.iface = iface
self.mc = self.iface.mapCanvas()
#self.legend = self.iface.legendInterface()
self.loaded_layers = [layer for layer in QgsProject.instance().mapLayers().values()]
# UI CCONNECTORS
self.buttonBox_ok_cancel.accepted.connect(self.run)
self.buttonBox_ok_cancel.rejected.connect(self.close)
self.comboBox_line_layer.currentIndexChanged.connect(self.update_fields)
# Get line layers and raster layers from legend
vector_line_layers, raster_layers = self.get_useful_layers()
# Populate comboboxes
self.comboBox_line_layer.clear()
self.comboBox_line_layer.addItems(vector_line_layers)
self.comboBox_elevation_layer.clear()
self.comboBox_elevation_layer.addItems(raster_layers)
#self.repaint()
def get_useful_layers(self):
"""
Purpose: iterate the map legend and return a list of line vector layers (with fields)
and a list of raster layers.
vector_line_layers is like {Layer1name:[Layer 1,[fileld1, field2, ...]], Layer2Name: [Layer 2,[fileld1, field2, ...]],...}
"""
self.vector_line_layers = {}
self.raster_layers = {}
for layer in self.loaded_layers:
fields_names = []
# select line vector layers
if (layer.type() == layer.VectorLayer) and (layer.geometryType() == 1):
layer_info = [layer]
provider = layer.dataProvider()
fields = provider.fields()
# get vector layer fields
for field in fields:
fields_names.append(field.name())
layer_info += [fields_names]
self.vector_line_layers[str(layer.name())] = layer_info
# select raster layers
elif layer.type() == layer.RasterLayer:
self.raster_layers[str(layer.name())] = layer
else:
pass
vector_line_layers = list(self.vector_line_layers)
raster_layers =list(self.raster_layers)
return vector_line_layers, raster_layers
def update_fields(self):
"""
Purpose: refresh list of available fields in update fields
"""
self.comboBox_time_field.clear()
self.comboBox_rev_time_field.clear()
line_layer_fields = self.vector_line_layers[self.comboBox_line_layer.currentText()][1]
self.comboBox_time_field.addItems(line_layer_fields)
self.comboBox_rev_time_field.addItems(line_layer_fields)
# auto select time and time_rev fields if they exist
if 'time' in line_layer_fields:
index = line_layer_fields.index('time')
self.comboBox_time_field.setCurrentIndex(index)
if 'rev_time' in line_layer_fields:
index = line_layer_fields.index('rev_time')
self.comboBox_rev_time_field.setCurrentIndex(index)
def run(self):
pass
return