Browse Source

Added avoid types for routing, styling for acc areas

master
Nils 1 year ago
parent
commit
cd7b188aeb
5 changed files with 194 additions and 98 deletions
  1. 1
    1
      apikey.txt
  2. 1
    1
      osm_tools.py
  3. 40
    19
      osm_tools_access.py
  4. 139
    74
      osm_tools_dialog_base.ui
  5. 13
    3
      osm_tools_routing.py

+ 1
- 1
apikey.txt View File

@@ -1 +1 @@
1
-
1
+58d904a497c67e00015b45fc467d815680654992543fa46ac3aa6535

+ 1
- 1
osm_tools.py View File

@@ -87,7 +87,7 @@ class OSMtools():
87 87
         self.canvas = qgis.utils.iface.mapCanvas()
88 88
         self.script_dir = os.path.dirname(os.path.abspath(__file__))
89 89
         
90
-        # Init dialoag boxes
90
+        # Init dialog boxes
91 91
         # Routing
92 92
         self.dlg.mode_travel.clear()
93 93
         self.dlg.mode_routing.clear()           

+ 40
- 19
osm_tools_access.py View File

@@ -318,10 +318,9 @@ class accessAnalysis:
318 318
         QgsMapLayerRegistry.instance().addMapLayer(layer_out)
319 319
         QgsMapLayerRegistry.instance().addMapLayer(layer_out_point)
320 320
         
321
-        
322
-
323
-#        fields_diss = ["AA_MINS"]
324
-#        self.dissolveFields(layer_out, fields_diss)
321
+        # Call styleLayer function
322
+        self.styleLayer(layer_out, isochrone_list)
323
+        qgis.utils.iface.mapCanvas().setExtent(layer_out.extent())
325 324
         
326 325
         # Unset Map Tool and show dialog again
327 326
         self.dlg.showNormal()
@@ -389,8 +388,9 @@ class accessAnalysis:
389 388
 
390 389
             layer_out.updateExtents()
391 390
 
392
-#        id_field = self.dlg.id_field.currentText()
393
-#        fields_diss = ["AA_MINS", id_field]
391
+        # Call styleLayer function
392
+        self.styleLayer(layer_out, isochrone_list)
393
+        qgis.utils.iface.mapCanvas().setExtent(layer_out.extent())
394 394
         
395 395
         qgis.utils.iface.messageBar().clearWidgets() 
396 396
         
@@ -398,16 +398,37 @@ class accessAnalysis:
398 398
     
399 399
     #TODO: Apply styling to polygon layers
400 400
     def styleLayer(self, layer, isochrone_list):
401
-        renderer_field = layer.fields()[0]
402
-        range_iso = [x for x in set(isochrone_list)]
403
-        renderer_symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
404
-        color_ramp = QgsStyleV2().defaultStyle().colorRampNames()[4]
405
-
406
-        renderer_colour = QColor('#ffee00')
407
-        renderer_symbol.setColor(renderer_colour)
408
-        renderer_symbol.setAlpha(0.5)
409
-        renderer_range = QgsRendererRangeV2(min(range_list), max(range_list), renderer_symbol)
410
-        myVectorLayer.setRendererV2(myRenderer)
411
-        myRenderer = QgsGraduatedSymbolRendererV2('', myRangeList)
412
-        myRenderer.setMode(QgsGraduatedSymbolRendererV2.EqualInterval)
413
-        myRenderer.setClassAttribute(myTargetField)
401
+        if self.iso_range_type == 'time':
402
+            field = 'AA_MINS'
403
+            legend_suffix = ' mins'
404
+        else:
405
+            field = 'AA_METERS'
406
+            legend_suffix = ' m'
407
+            
408
+        colors = {0: '#2b83ba',
409
+                  1: '#64abb0',
410
+                  2: '#9dd3a7',
411
+                  3: '#c7e9ad',
412
+                  4: '#edf8b9',
413
+                  5: '#ffedaa',
414
+                  6: '#fec980',
415
+                  7: '#f99e59',
416
+                  8: '#e85b3a',
417
+                  9: '#d7191c'}
418
+        
419
+        iso_list = []
420
+        for cid, iso in enumerate(isochrone_list):
421
+            iso_list.append([iso, colors[cid], str(iso) + legend_suffix])
422
+            
423
+        categories = []
424
+        for classes, color, legend in iso_list:
425
+            symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
426
+            symbol.setColor(QColor(color))
427
+            category = QgsRendererCategoryV2(classes, symbol, legend)
428
+            categories.append(category)
429
+        
430
+        # set up an empty categorized renderer and assign the color ramp
431
+        renderer = QgsCategorizedSymbolRendererV2(field, categories)
432
+        layer.setRendererV2(renderer)
433
+        layer.setLayerTransparency(50)
434
+        layer.triggerRepaint()

+ 139
- 74
osm_tools_dialog_base.ui View File

@@ -91,7 +91,7 @@
91 91
    <item row="6" column="0">
92 92
     <widget class="QTabWidget" name="tabWidget">
93 93
      <property name="currentIndex">
94
-      <number>1</number>
94
+      <number>0</number>
95 95
      </property>
96 96
      <property name="usesScrollButtons">
97 97
       <bool>true</bool>
@@ -110,13 +110,51 @@
110 110
           <property name="geometry">
111 111
            <rect>
112 112
             <x>0</x>
113
-            <y>0</y>
113
+            <y>-408</y>
114 114
             <width>315</width>
115
-            <height>691</height>
115
+            <height>839</height>
116 116
            </rect>
117 117
           </property>
118 118
           <layout class="QGridLayout" name="gridLayout_8">
119
-           <item row="0" column="0">
119
+           <item row="7" column="0">
120
+            <widget class="QGroupBox" name="groupBox_5">
121
+             <property name="title">
122
+              <string>Via</string>
123
+             </property>
124
+             <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
125
+              <property name="sizeConstraint">
126
+               <enum>QLayout::SetDefaultConstraint</enum>
127
+              </property>
128
+              <item>
129
+               <widget class="QLabel" name="add_via">
130
+                <property name="font">
131
+                 <font>
132
+                  <italic>true</italic>
133
+                 </font>
134
+                </property>
135
+                <property name="text">
136
+                 <string>Long,Lat</string>
137
+                </property>
138
+               </widget>
139
+              </item>
140
+              <item>
141
+               <widget class="QPushButton" name="add_via_button">
142
+                <property name="text">
143
+                 <string>Map</string>
144
+                </property>
145
+               </widget>
146
+              </item>
147
+              <item>
148
+               <widget class="QPushButton" name="add_via_button_clear">
149
+                <property name="text">
150
+                 <string>Clear</string>
151
+                </property>
152
+               </widget>
153
+              </item>
154
+             </layout>
155
+            </widget>
156
+           </item>
157
+           <item row="2" column="0">
120 158
             <widget class="QGroupBox" name="groupBox">
121 159
              <property name="font">
122 160
               <font>
@@ -206,7 +244,45 @@
206 244
              </layout>
207 245
             </widget>
208 246
            </item>
209
-           <item row="1" column="0">
247
+           <item row="6" column="0">
248
+            <widget class="QGroupBox" name="groupBox_3">
249
+             <property name="title">
250
+              <string>Two layer mode</string>
251
+             </property>
252
+             <layout class="QGridLayout" name="gridLayout_6">
253
+              <item row="0" column="0">
254
+               <widget class="QRadioButton" name="radio_one">
255
+                <property name="enabled">
256
+                 <bool>false</bool>
257
+                </property>
258
+                <property name="toolTip">
259
+                 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[2]&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
260
+                </property>
261
+                <property name="text">
262
+                 <string>Row by row</string>
263
+                </property>
264
+                <property name="checked">
265
+                 <bool>true</bool>
266
+                </property>
267
+               </widget>
268
+              </item>
269
+              <item row="0" column="1">
270
+               <widget class="QRadioButton" name="radio_many">
271
+                <property name="enabled">
272
+                 <bool>false</bool>
273
+                </property>
274
+                <property name="toolTip">
275
+                 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[2]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[2]&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
276
+                </property>
277
+                <property name="text">
278
+                 <string>All rows by all rows</string>
279
+                </property>
280
+               </widget>
281
+              </item>
282
+             </layout>
283
+            </widget>
284
+           </item>
285
+           <item row="5" column="0">
210 286
             <widget class="QGroupBox" name="groupBox_2">
211 287
              <property name="title">
212 288
               <string>End Location(s)</string>
@@ -294,110 +370,99 @@
294 370
              </layout>
295 371
             </widget>
296 372
            </item>
297
-           <item row="2" column="0">
298
-            <widget class="QGroupBox" name="groupBox_3">
299
-             <property name="title">
300
-              <string>Two layer mode</string>
301
-             </property>
302
-             <layout class="QGridLayout" name="gridLayout_6">
303
-              <item row="0" column="0">
304
-               <widget class="QRadioButton" name="radio_one">
305
-                <property name="enabled">
306
-                 <bool>false</bool>
307
-                </property>
308
-                <property name="toolTip">
309
-                 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[2]&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
310
-                </property>
373
+           <item row="0" column="0">
374
+            <widget class="QWidget" name="widget" native="true">
375
+             <layout class="QHBoxLayout" name="horizontalLayout_2">
376
+              <item>
377
+               <widget class="QLabel" name="label_10">
311 378
                 <property name="text">
312
-                 <string>Row by row</string>
313
-                </property>
314
-                <property name="checked">
315
-                 <bool>true</bool>
379
+                 <string>Travel mode</string>
316 380
                 </property>
317 381
                </widget>
318 382
               </item>
319
-              <item row="0" column="1">
320
-               <widget class="QRadioButton" name="radio_many">
321
-                <property name="enabled">
322
-                 <bool>false</bool>
323
-                </property>
324
-                <property name="toolTip">
325
-                 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[1]--&amp;gt;end_layer[2]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[1]&lt;/p&gt;&lt;p&gt;start_layer[2]--&amp;gt;end_layer[2]&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
326
-                </property>
383
+              <item>
384
+               <widget class="QComboBox" name="mode_travel"/>
385
+              </item>
386
+             </layout>
387
+            </widget>
388
+           </item>
389
+           <item row="1" column="0">
390
+            <widget class="QWidget" name="widget_2" native="true">
391
+             <layout class="QHBoxLayout" name="horizontalLayout_3">
392
+              <item>
393
+               <widget class="QLabel" name="label_12">
327 394
                 <property name="text">
328
-                 <string>All rows by all rows</string>
395
+                 <string>Routing mode</string>
329 396
                 </property>
330 397
                </widget>
331 398
               </item>
399
+              <item>
400
+               <widget class="QComboBox" name="mode_routing"/>
401
+              </item>
332 402
              </layout>
333 403
             </widget>
334 404
            </item>
335
-           <item row="3" column="0">
336
-            <widget class="QGroupBox" name="groupBox_5">
405
+           <item row="8" column="0">
406
+            <widget class="QGroupBox" name="avoid_type">
337 407
              <property name="title">
338
-              <string>Via</string>
408
+              <string>Avoid features</string>
339 409
              </property>
340
-             <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
341
-              <property name="sizeConstraint">
342
-               <enum>QLayout::SetDefaultConstraint</enum>
343
-              </property>
344
-              <item>
345
-               <widget class="QLabel" name="add_via">
346
-                <property name="font">
347
-                 <font>
348
-                  <italic>true</italic>
349
-                 </font>
410
+             <layout class="QGridLayout" name="gridLayout_9">
411
+              <item row="0" column="0">
412
+               <widget class="QCheckBox" name="checkBox">
413
+                <property name="text">
414
+                 <string>highways</string>
350 415
                 </property>
416
+               </widget>
417
+              </item>
418
+              <item row="0" column="1">
419
+               <widget class="QCheckBox" name="checkBox_2">
351 420
                 <property name="text">
352
-                 <string>Long,Lat</string>
421
+                 <string>tollways</string>
353 422
                 </property>
354 423
                </widget>
355 424
               </item>
356
-              <item>
357
-               <widget class="QPushButton" name="add_via_button">
425
+              <item row="1" column="0">
426
+               <widget class="QCheckBox" name="checkBox_4">
358 427
                 <property name="text">
359
-                 <string>Map</string>
428
+                 <string>tunnels</string>
360 429
                 </property>
361 430
                </widget>
362 431
               </item>
363
-              <item>
364
-               <widget class="QPushButton" name="add_via_button_clear">
432
+              <item row="1" column="1">
433
+               <widget class="QCheckBox" name="checkBox_3">
365 434
                 <property name="text">
366
-                 <string>Clear</string>
435
+                 <string>ferries</string>
367 436
                 </property>
368 437
                </widget>
369 438
               </item>
370
-             </layout>
371
-            </widget>
372
-           </item>
373
-           <item row="4" column="0">
374
-            <widget class="QWidget" name="widget" native="true">
375
-             <layout class="QHBoxLayout" name="horizontalLayout_2">
376
-              <item>
377
-               <widget class="QLabel" name="label_10">
439
+              <item row="2" column="0">
440
+               <widget class="QCheckBox" name="checkBox_6">
378 441
                 <property name="text">
379
-                 <string>Travel mode</string>
442
+                 <string>fords</string>
380 443
                 </property>
381 444
                </widget>
382 445
               </item>
383
-              <item>
384
-               <widget class="QComboBox" name="mode_travel"/>
446
+              <item row="3" column="0">
447
+               <widget class="QCheckBox" name="checkBox_7">
448
+                <property name="text">
449
+                 <string>pavedroads</string>
450
+                </property>
451
+               </widget>
385 452
               </item>
386
-             </layout>
387
-            </widget>
388
-           </item>
389
-           <item row="5" column="0">
390
-            <widget class="QWidget" name="widget_2" native="true">
391
-             <layout class="QHBoxLayout" name="horizontalLayout_3">
392
-              <item>
393
-               <widget class="QLabel" name="label_12">
453
+              <item row="2" column="1">
454
+               <widget class="QCheckBox" name="checkBox_5">
394 455
                 <property name="text">
395
-                 <string>Routing mode</string>
456
+                 <string>tracks</string>
396 457
                 </property>
397 458
                </widget>
398 459
               </item>
399
-              <item>
400
-               <widget class="QComboBox" name="mode_routing"/>
460
+              <item row="3" column="1">
461
+               <widget class="QCheckBox" name="checkBox_8">
462
+                <property name="text">
463
+                 <string>unpavedroads</string>
464
+                </property>
465
+               </widget>
401 466
               </item>
402 467
              </layout>
403 468
             </widget>

+ 13
- 3
osm_tools_routing.py View File

@@ -187,10 +187,9 @@ class routing:
187 187
         layer_out_prov = layer_out.dataProvider()
188 188
         layer_out_prov.addAttributes([QgsField("DISTANCE", QVariant.Double)])
189 189
         layer_out_prov.addAttributes([QgsField("TIME_H", QVariant.Double)])
190
-#        layer_out_prov.addAttributes([QgsField("TIME_MIN", QVariant.Int)])
191
-#        layer_out_prov.addAttributes([QgsField("TIME_SEC", QVariant.Int)])
192 190
         layer_out_prov.addAttributes([QgsField("MODE", QVariant.String)])
193 191
         layer_out_prov.addAttributes([QgsField("PREF", QVariant.String)])
192
+        layer_out_prov.addAttributes([QgsField("AVOID_TYPE", QVariant.String)])
194 193
         layer_out_prov.addAttributes([QgsField("FROM_ID", QVariant.String)])
195 194
         layer_out_prov.addAttributes([QgsField("TO_ID", QVariant.String)])
196 195
         layer_out_prov.addAttributes([QgsField("FROM_LAT", QVariant.Double)])
@@ -308,7 +307,17 @@ class routing:
308 307
                                                     self.mode_routing
309 308
                                                     )
310 309
                 
311
-                #print req
310
+                # Add avoid type features if specified
311
+                avoid_type_names = []
312
+                for widget in self.dlg.avoid_type.children():
313
+                    if isinstance(widget, QCheckBox):
314
+                        if widget.isChecked():
315
+                            avoid_type_names.append(widget.text())
316
+                avoid_type_str = "%7C".join(avoid_type_names)
317
+                if avoid_type_str != '':
318
+                    req += '&options=%7B%22avoid_features%22:%22{0}%22%7D'.format(avoid_type_str)
319
+                print avoid_type_str
320
+                print req
312 321
                 
313 322
                 # Avoid the 40 req/min limit
314 323
                 counter +=1
@@ -379,6 +388,7 @@ class routing:
379 388
 #                                        seconds,
380 389
                                         self.mode_travel,
381 390
                                         self.mode_routing,
391
+                                        ', '.join(avoid_type_names),
382 392
                                         route_ids[i][0],
383 393
                                         route_ids[i][1],
384 394
                                         route_start_y,

Loading…
Cancel
Save