-
Notifications
You must be signed in to change notification settings - Fork 3
/
flowmapper.py
2988 lines (2599 loc) · 212 KB
/
flowmapper.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
/***************************************************************************
FlowMapper
A QGIS plugin
This plugin generates discreet flow lines between nodes
-------------------
begin : 2011-12-04
copyright : (C) 2011 by Cem GULLUOGLU
email : [email protected]
***************************************************************************/
"""
import sys
import os
#from os.path import isfile
from os.path import realpath
from os.path import isfile
import qgis.gui
from PyQt4 import QtCore, QtGui
#import ogr
from osgeo import ogr
import ogr
# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
# Initialize Qt resources from file resources.py
import resources
# Import the code for the dialog
from flowmapperdialog import FlowMapperDialog
import flowmapperdialog
from form2dialog import Form2Dialog
import form2dialog
from form3dialog import Form3Dialog
import form3dialog
from form6dialog import Form6Dialog
import form6dialog
from form4dialog import Form4Dialog
import form4dialog
from form7dialog import Form7Dialog
import form7dialog
from form5dialog import Form5Dialog
import form5dialog
import form_aboutdialog
# Import script that draws flow lines (kullan)
import flowpyv07
#import flowpyInterface (iptal)
class FlowMapper:
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/flowmapper/icon.png"), "Generate flow lines and nodes", self.iface.mainWindow())
self.actionform2 = QAction(QIcon(":/plugins/flowmapper/icon2.png"), "Filter flow lines by magnitude", self.iface.mainWindow())
self.actionform3 = QAction(QIcon(":/plugins/flowmapper/icon4.png"), "Filter flow lines by length", self.iface.mainWindow())
self.actionform6 = QAction(QIcon(":/plugins/flowmapper/icon7.png"), "Filter flow lines by node and direction", self.iface.mainWindow())
self.actionform4 = QAction(QIcon(":/plugins/flowmapper/icon5.png"), "Symbology for flow lines", self.iface.mainWindow())
self.actionform7 = QAction(QIcon(":/plugins/flowmapper/icon8.png"), "Symbology for flow nodes", self.iface.mainWindow())
self.actionform5 = QAction(QIcon(":/plugins/flowmapper/icon6.png"), "Export...", self.iface.mainWindow())
self.actionabout = QAction(QIcon(":/plugins/flowmapper/icon3.png"), "About FlowMapper", self.iface.mainWindow())
# connect the action to the run method
QObject.connect(self.action, SIGNAL("triggered()"), self.run)
QObject.connect(self.actionform2, SIGNAL("triggered()"), self.form2)
QObject.connect(self.actionform3, SIGNAL("triggered()"), self.form3)
QObject.connect(self.actionform6, SIGNAL("triggered()"), self.form6)
QObject.connect(self.actionform4, SIGNAL("triggered()"), self.form4)
QObject.connect(self.actionform7, SIGNAL("triggered()"), self.form7)
QObject.connect(self.actionform5, SIGNAL("triggered()"), self.form5)
QObject.connect(self.actionabout, SIGNAL("triggered()"), self.about)
# Add toolbar button and menu item to QGIS
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&FlowMapper", self.action)
self.iface.addPluginToMenu("&FlowMapper", self.actionform2)
self.iface.addPluginToMenu("&FlowMapper", self.actionform3)
self.iface.addPluginToMenu("&FlowMapper", self.actionform6)
self.iface.addPluginToMenu("&FlowMapper", self.actionform4)
self.iface.addPluginToMenu("&FlowMapper", self.actionform7)
self.iface.addPluginToMenu("&FlowMapper", self.actionform5)
self.iface.addPluginToMenu("&FlowMapper", self.actionabout)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&FlowMapper",self.action)
self.iface.removeToolBarIcon(self.action)
self.iface.removePluginMenu("&FlowMapper", self.actionform2)
self.iface.removeToolBarIcon(self.actionform2)
self.iface.removePluginMenu("&FlowMapper", self.actionform3)
self.iface.removeToolBarIcon(self.actionform3)
self.iface.removePluginMenu("&FlowMapper", self.actionform6)
self.iface.removeToolBarIcon(self.actionform6)
self.iface.removePluginMenu("&FlowMapper", self.actionform4)
self.iface.removeToolBarIcon(self.actionform4)
self.iface.removePluginMenu("&FlowMapper", self.actionform7)
self.iface.removeToolBarIcon(self.actionform5)
self.iface.removePluginMenu("&FlowMapper", self.actionform5)
self.iface.removeToolBarIcon(self.actionform5)
self.iface.removePluginMenu("&FlowMapper", self.actionabout)
self.iface.removeToolBarIcon(self.actionabout)
def OutputShp(self):
dlg = FlowMapperDialog()
#buttona basip file browser ile output shapefile LINES dosya adi vermek icin fonksiyon
fd = QtGui.QFileDialog(dlg)
global SaveShpName
global SaveShpDirectory
SaveShpName = fd.getSaveFileName(None, 'Shapefile(*.shp)', 'Type output shapefile name', '*.shp')
def OutputShpNodes(self):
dlg = FlowMapperDialog()
#buttona basip file browser ile output shapefile NODES dosya adi vermek icin fonksiyon
fd = QtGui.QFileDialog(dlg)
global SaveShpNameNodes
global SaveShpDirectoryNodes
SaveShpNameNodes = fd.getSaveFileName(None, 'Shapefile(*.shp)', 'Type output shapefile name', '*.shp')
def InputNodes(self):
dlg = FlowMapperDialog()
#buttona basip file browser ile input node coord. txt dosyasini sectirmek icin fonksiyon
fd = QtGui.QFileDialog(dlg)
global InputNodesName
InputNodesName = fd.getOpenFileName(None, 'Text Files(*.txt)', 'Select txt file', '*.txt')
def InputNodeNames(self):
dlg = FlowMapperDialog()
#buttona basip file browser ile input node coord. txt dosyasini sectirmek icin fonksiyon
fd = QtGui.QFileDialog(dlg)
global InputNodeNamesName
InputNodeNamesName = fd.getOpenFileName(None, 'Text Files(*.txt)', 'Select txt file', '*.txt')
def InputMatrix(self):
dlg = FlowMapperDialog()
#buttona basip file browser ile flow matrix txt dosyasini sectirmek icin fonksiyon
fd = QtGui.QFileDialog(dlg)
global InputMatrixName
InputMatrixName = fd.getOpenFileName(None, 'Text Files(*.txt)', 'Select txt file', '*.txt')
def InputShpFilter(self):
dlg = Form2Dialog()
fd = QtGui.QFileDialog(dlg)
global InputShpFilterName
global InputShpFilterDirectory
InputShpFilterName = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#InputShpFilterDirectory = os.path.realpath(InputShpFilterName)
InputShpFilterDirectory = InputShpFilterName
def OutputShpFilter(self):
dlg = Form2Dialog()
fd = QtGui.QFileDialog(dlg)
global OutputShpFilterName
global OutputShpFilterDirectory
OutputShpFilterName = fd.getSaveFileName(None, 'Shapefile(*.shp)', 'Type output shapefile name', '*.shp')
#OutputShpFilterDirectory = os.path.realpath(OutputShpFilterName)
OutputShpFilterDirectory = OutputShpFilterName
def InputShpFilterLength(self):
dlg = Form3Dialog()
fd = QtGui.QFileDialog(dlg)
global InputShpFilterLengthName
global InputShpFilterLengthDirectory
InputShpFilterLengthName = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#InputShpFilterLengthDirectory = os.path.realpath(InputShpFilterLengthName)
InputShpFilterLengthDirectory = InputShpFilterLengthName
def InputShpSymbology(self):
dlg = Form4Dialog()
fd = QtGui.QFileDialog(dlg)
global InputShpSymbologyName
global InputShpSymbologyDirectory
InputShpSymbologyName = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#InputShpSymbologyDirectory = os.path.realpath(InputShpSymbologyName)
InputShpSymbologyDirectory = InputShpSymbologyName
def InputShpNodeSymbology(self):
dlg = Form7Dialog()
fd = QtGui.QFileDialog(dlg)
global InputShpNodeSymbologyName
global InputShpNodeSymbologyDirectory
InputShpNodeSymbologyName = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#InputShpNodeSymbologyDirectory = os.path.realpath(InputShpNodeSymbologyName)
InputShpNodeSymbologyDirectory = InputShpNodeSymbologyName
def OutputShpFilterLength(self):
dlg = Form3Dialog()
fd = QtGui.QFileDialog(dlg)
global OutputShpFilterLengthName
global OutputShpFilterLengthDirectory
OutputShpFilterLengthName = fd.getSaveFileName(None, 'Shapefile(*.shp)', 'Type output shapefile name', '*.shp')
#OutputShpFilterLengthDirectory = os.path.realpath(OutputShpFilterLengthName)
OutputShpFilterLengthDirectory = OutputShpFilterLengthName
def InputShpNameExport(self):
dlg = Form5Dialog()
fd = QtGui.QFileDialog(dlg)
global BrowseShapeLineEditNameExport
global BrowseShapeLineEditDirectoryExport
BrowseShapeLineEditNameExport = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#BrowseShapeLineEditDirectoryExport = os.path.realpath(BrowseShapeLineEditNameExport)
BrowseShapeLineEditDirectoryExport = BrowseShapeLineEditNameExport
def OutputFileNameExport(self):
dlg = Form5Dialog()
fd = QtGui.QFileDialog(dlg)
global BrowseFileLineEditNameExport
global BrowseFileLineEditDirectoryExport
BrowseFileLineEditNameExport = fd.getSaveFileName(None, '', 'Type output file name with extension', '*.shp')
#BrowseFileLineEditDirectoryNameExport = os.path.realpath(BrowseFileLineEditNameExport)
BrowseFileLineEditDirectoryNameExport = BrowseFileLineEditNameExport
def InputShpFilterNodeNames(self):
dlg = Form6Dialog()
fd = QtGui.QFileDialog(dlg)
global InputShpFilterNodeNamesName
global InputShpFilterNodeNamesDirectory
InputShpFilterNodeNamesName = fd.getOpenFileName(None, 'Shapefile(*.shp)', 'Select shapefile', '*.shp')
#InputShpFilterLengthDirectory = os.path.realpath(InputShpFilterLengthName)
InputShpFilterNodeNamesDirectory = InputShpFilterNodeNamesName
def OutputShpFilterNodeNames(self):
dlg = Form6Dialog()
fd = QtGui.QFileDialog(dlg)
global OutputShpFilterNodeNamesName
global OutputShpFilterNodeNamesDirectory
OutputShpFilterNodeNamesName = fd.getSaveFileName(None, '', 'Type output file name with extension', '*.shp')
#InputShpFilterLengthDirectory = os.path.realpath(InputShpFilterLengthName)
OutputShpFilterNodeNamesDirectory = OutputShpFilterNodeNamesName
def CalStatFilter(self):
global CalStatNoOfFeatures
global CalStatNoOfFeaturesZero
global CalStatSumMagnitude
global CalStatMaxFlow
global CalStatMinFlow
global CalStatMean
global CalStatMeanNotZero
global CalStatStdDev
global CalStatStdDevNotZero
shp = ogr.Open(str(InputShpFilterDirectory),1)
layer = shp.GetLayer(0)
#get number of all features in shapefile
CalStatNoOfFeatures = str(layer.GetFeatureCount())
#----------------------------------------------------------------------------------------------------
feature = layer.GetNextFeature()
counterNotZero = 0
CalStatSumMagnitude = 0
CalStatList = []
while feature:
magnitude = feature.GetField('magnitude')
if magnitude > 0:
CalStatList.append(int(magnitude))
CalStatMinFlow = min(CalStatList)
CalStatMaxFlow = max(CalStatList)
counterNotZero = counterNotZero + 1
CalStatSumMagnitude = CalStatSumMagnitude + magnitude
feature.Destroy()
feature = layer.GetNextFeature()
CalStatMean = str((CalStatSumMagnitude / int(CalStatNoOfFeatures)))
CalStatMean = str(round(float(CalStatMean), 3))
CalStatMeanNotZero = str(CalStatSumMagnitude / int(counterNotZero))
CalStatMeanNotZero = str(round(float(CalStatMeanNotZero), 3))
CalStatSumMagnitude = str(CalStatSumMagnitude)
CalStatNoOfFeaturesZero = str(int(CalStatNoOfFeatures)-int(counterNotZero))
CalStatMaxFlow = str(int(CalStatMaxFlow))
CalStatMinFlow = str(int(CalStatMinFlow))
layer.ResetReading()
feature = layer.GetNextFeature()
var = 0
varNotZero = 0
while feature:
magnitude = feature.GetField('magnitude')
var = var + ((magnitude - float(CalStatMean))**2)
if magnitude > 0:
varNotZero = varNotZero + ((magnitude - float(CalStatMeanNotZero))**2)
feature.Destroy()
feature = layer.GetNextFeature()
CalStatStdDev = str((var / int(CalStatNoOfFeatures))**0.5)
CalStatStdDev = str(round(float(CalStatStdDev), 3))
CalStatStdDevNotZero = str((varNotZero / int(counterNotZero))**0.5)
CalStatStdDevNotZero = str(round(float(CalStatStdDevNotZero), 3))
layer.ResetReading()
feature = layer.GetNextFeature()
shp.Destroy()
#----------------------------------------------------------------------------------------------------
#QMessageBox.information(self.iface.mainWindow(),"info" ,"Statistics calculated successfully !")
#QMessageBox.information(self.iface.mainWindow(),"minflow" ,QString(str(CalStatMinFlow)))
#QMessageBox.information(self.iface.mainWindow(),"maxflow" ,QString(str(CalStatMaxFlow)))
#QMessageBox.information(self.iface.mainWindow(),"info" ,QString(str(CalStatSumMagnitude)))
#QMessageBox.information(self.iface.mainWindow(),"info" ,QString(str(CalStatStdDevNotZero)))
#QMessageBox.information(self.iface.mainWindow(),"info" ,QString(str(CalStatStdDev)))
#QMessageBox.information(self.iface.mainWindow(),"info" ,QString(str(CalStatMeanNotZero)))
#QMessageBox.information(self.iface.mainWindow(),"info" ,QString(str(CalStatMean)))
def CalStatFilterLength(self):
global CalStatLengthMax
global CalStatLengthMin
global CalStatLengthMean
global CalStatLengthMeanNotZero
global CalStatLengthStdDev
global CalStatLengthStdDevNotZero
shp = ogr.Open(str(InputShpFilterLengthDirectory),1)
layer = shp.GetLayer(0)
#get number of all features in shapefile
CalStatLengthNoOfFeatures = str(layer.GetFeatureCount())
#----------------------------------------------------------------------------------------------------
feature = layer.GetNextFeature()
counterNotZero = 0
CalStatLengthSumLength = 0
CalStatLengthList = []
while feature:
length = feature.GetField('length_km')
if length > 0:
CalStatLengthList.append(length)
CalStatLengthMin = min(CalStatLengthList)
CalStatLengthMax = max(CalStatLengthList)
counterNotZero = counterNotZero + 1
CalStatLengthSumLength = CalStatLengthSumLength + length
feature.Destroy()
feature = layer.GetNextFeature()
CalStatLengthMean = str((CalStatLengthSumLength / int(CalStatLengthNoOfFeatures)))
CalStatLengthMean = str(round(float(CalStatLengthMean), 3))
CalStatLengthMeanNotZero = str(CalStatLengthSumLength / int(counterNotZero))
CalStatLengthMeanNotZero = str(round(float(CalStatLengthMeanNotZero), 3))
CalStatLengthSumLength = str(CalStatLengthSumLength)
CalStatLengthNoOfFeaturesZero = str(int(CalStatLengthNoOfFeatures)-int(counterNotZero))
CalStatLengthMin = str(round((CalStatLengthMin),3))
CalStatLengthMax = str(round((CalStatLengthMax),3))
layer.ResetReading()
feature = layer.GetNextFeature()
varLength = 0
varLengthNotZero = 0
while feature:
length = feature.GetField('length_km')
varLength = varLength + ((length - float(CalStatLengthMean))**2)
if length > 0:
varLengthNotZero = varLengthNotZero + ((length - float(CalStatLengthMeanNotZero))**2)
feature.Destroy()
feature = layer.GetNextFeature()
CalStatLengthStdDev = str((varLength / int(CalStatLengthNoOfFeatures))**0.5)
CalStatLengthStdDev = str(round(float(CalStatLengthStdDev), 3))
CalStatLengthStdDevNotZero = str((varLengthNotZero / int(counterNotZero))**0.5)
CalStatLengthStdDevNotZero = str(round(float(CalStatLengthStdDevNotZero), 3))
layer.ResetReading()
feature = layer.GetNextFeature()
shp.Destroy()
#----------------------------------------------------------------------------------------------------
#QMessageBox.information(self.iface.mainWindow(),"info" ,"Statistics calculated successfully !")
def CalStatSymbology(self):
dlg = Form4Dialog()
global GradSymNoOfFeaturesSymbology
GradSymNoOfFeaturesSymbology=""
global GradSymNoOfFeaturesZeroSymbology
GradSymNoOfFeaturesZeroSymbology=""
global GradSymMinSymbology
GradSymMinSymbology=""
global GradSymMaxSymbology
GradSymMaxSymbology=""
global GradSymSumMagnitudeSymbology
GradSymSumMagnitudeSymbology=""
global GradSymMeanSymbology
GradSymMeanSymbology=""
global GradSymMeanNotZeroSymbology
GradSymMeanNotZeroSymbology=""
global GradSymStdDevSymbology
GradSymStdDevSymbology=""
global GradSymStdDevNotZeroSymbology
GradSymStdDevNotZeroSymbology=""
global GradSymListSymbology
GradSymListSymbology=""
extension = os.path.splitext(str(InputShpSymbologyName))[1]
if extension == ".shp" and ".shp" in InputShpSymbologyName and len(InputShpSymbologyName) > 4:
shp = ogr.Open(str(InputShpSymbologyName),1)
layer = shp.GetLayer(0)
GradSymNoOfFeaturesSymbology = str(layer.GetFeatureCount())
feature = layer.GetNextFeature()
counterNotZero = 0
GradSymSumMagnitudeSymbology = 0
GradSymListSymbology= []
while feature:
magnitude = feature.GetField('magnitude')
if magnitude > 0:
counterNotZero = counterNotZero + 1
GradSymListSymbology.append(int(magnitude))
GradSymMinSymbology = min(GradSymListSymbology)
GradSymMaxSymbology = max(GradSymListSymbology)
GradSymSumMagnitudeSymbology = GradSymSumMagnitudeSymbology + magnitude
feature.Destroy()
feature = layer.GetNextFeature()
GradSymMeanSymbology = str(round(float(GradSymSumMagnitudeSymbology / int(GradSymNoOfFeaturesSymbology)),3))
GradSymMeanNotZeroSymbology = str(round(float(GradSymSumMagnitudeSymbology / int(counterNotZero)),3))
GradSymSumMagnitudeSymbology = str(GradSymSumMagnitudeSymbology)
GradSymNoOfFeaturesZeroSymbology = str(int(GradSymNoOfFeaturesSymbology)-int(counterNotZero))
GradSymMinSymbology = str(GradSymMinSymbology)
GradSymMaxSymbology = str(GradSymMaxSymbology)
layer.ResetReading()
GradSymVar = 0
GradSymVarNotZero = 0
feature = layer.GetNextFeature()
while feature:
magnitude = feature.GetField('magnitude')
#feature = layer.GetNextFeature()
GradSymVar = GradSymVar + ((magnitude - float(GradSymMeanSymbology))**2)
if magnitude > 0:
GradSymVarNotZero = GradSymVarNotZero + ((magnitude - float(GradSymMeanNotZeroSymbology))**2)
feature.Destroy()
feature = layer.GetNextFeature()
GradSymStdDevSymbology = str(round(((GradSymVar / int(GradSymNoOfFeaturesSymbology))**0.5), 3))
GradSymStdDevNotZeroSymbology = str(round(((GradSymVarNotZero / int(counterNotZero))**0.5), 3))
layer.ResetReading()
shp.Destroy()
def CalStatNodeSymbology(self):
dlg = Form7Dialog()
global comboBoxSelectField_combotext
global GradSymNoOfFeaturesNodeSymbology
GradSymNoOfFeaturesNodeSymbology=""
global GradSymNoOfFeaturesZeroNodeSymbology
GradSymNoOfFeaturesZeroNodeSymbology=""
global GradSymMinNodeSymbology
GradSymMinNodeSymbology=""
global GradSymMaxNodeSymbology
GradSymMaxNodeSymbology=""
global GradSymSumMagnitudeNodeSymbology
GradSymSumMagnitudeNodeSymbology=""
global GradSymMeanNodeSymbology
GradSymMeanNodeSymbology=""
global GradSymMeanNotZeroNodeSymbology
GradSymMeanNotZeroNodeSymbology=""
global GradSymStdDevNodeSymbology
GradSymStdDevNodeSymbology=""
global GradSymStdDevNotZeroNodeSymbology
GradSymStdDevNotZeroNodeSymbology=""
global GradSymListNodeSymbology
GradSymListNodeSymbology=""
extension = os.path.splitext(str(InputShpNodeSymbologyName))[1]
if extension == ".shp" and ".shp" in InputShpNodeSymbologyName and len(InputShpNodeSymbologyName) > 4:
shp = ogr.Open(str(InputShpNodeSymbologyName),1)
layer = shp.GetLayer(0)
GradSymNoOfFeaturesNodeSymbology = str(layer.GetFeatureCount())
feature = layer.GetNextFeature()
counterNotZero = 0
GradSymSumMagnitudeNodeSymbology = 0
GradSymListNodeSymbology= []
while feature:
magnitude = feature.GetField(str(comboBoxSelectField_combotext))
#magnitude = feature.GetField('magnitude')
if magnitude > 0:
counterNotZero = counterNotZero + 1
GradSymListNodeSymbology.append(float(magnitude))
GradSymMinNodeSymbology = round(min(GradSymListNodeSymbology),3)
GradSymMaxNodeSymbology = round(max(GradSymListNodeSymbology),3)
GradSymSumMagnitudeNodeSymbology = GradSymSumMagnitudeNodeSymbology + magnitude
feature.Destroy()
feature = layer.GetNextFeature()
GradSymMeanNodeSymbology = str(round(float(GradSymSumMagnitudeNodeSymbology / int(GradSymNoOfFeaturesNodeSymbology)),3))
GradSymMeanNotZeroNodeSymbology = str(round(float(GradSymSumMagnitudeNodeSymbology / int(counterNotZero)),3))
GradSymSumMagnitudeNodeSymbology = str(GradSymSumMagnitudeNodeSymbology)
GradSymNoOfFeaturesZeroNodeSymbology = str(int(GradSymNoOfFeaturesNodeSymbology)-int(counterNotZero))
GradSymMinNodeSymbology = str(GradSymMinNodeSymbology)
GradSymMaxNodeSymbology = str(GradSymMaxNodeSymbology)
layer.ResetReading()
GradSymVar = 0
GradSymVarNotZero = 0
feature = layer.GetNextFeature()
while feature:
magnitude = feature.GetField(str(comboBoxSelectField_combotext))
#magnitude = feature.GetField('magnitude')
#feature = layer.GetNextFeature()
GradSymVar = GradSymVar + ((magnitude - float(GradSymMeanNodeSymbology))**2)
if magnitude > 0:
GradSymVarNotZero = GradSymVarNotZero + ((magnitude - float(GradSymMeanNotZeroNodeSymbology))**2)
feature.Destroy()
feature = layer.GetNextFeature()
GradSymStdDevNodeSymbology = str(round(((GradSymVar / int(GradSymNoOfFeaturesNodeSymbology))**0.5), 3))
GradSymStdDevNotZeroNodeSymbology = str(round(((GradSymVarNotZero / int(counterNotZero))**0.5), 3))
layer.ResetReading()
shp.Destroy()
def form2(self):
dlg = Form2Dialog()
#dlg.exec_()
dlg.show()
dlg.ui.CalStat.setEnabled(False)
global text_magnitude
text_magnitude = dlg.ui.Filter_LineEdit.text()
#result = dlg2.exec_()
QtCore.QObject.connect(dlg.ui.BrowseShapeInputFilter,QtCore.SIGNAL("clicked()"), self.InputShpFilter)
QtCore.QObject.connect(dlg.ui.BrowseShapeInputFilter,QtCore.SIGNAL("clicked()"), dlg.SetTextBrowseInputShapeFilter)
QtCore.QObject.connect(dlg.ui.BrowseShapeOutputFilter,QtCore.SIGNAL("clicked()"), self.OutputShpFilter)
QtCore.QObject.connect(dlg.ui.BrowseShapeOutputFilter,QtCore.SIGNAL("clicked()"), dlg.SetTextBrowseOutputShapeFilter)
#get stats
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), self.CalStatFilter)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.No_Of_Features)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.No_Of_FeaturesNotZero)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.Mean)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.MeanNotZero)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.MaxFlow)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.MinFlow)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.SumMagnitude)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.StdDev)
QtCore.QObject.connect(dlg.ui.CalStat,QtCore.SIGNAL("clicked()"), dlg.StdDevNotZero)
#dlg.exec_()
result = dlg.exec_()
# See if OK was pressed
if result == 1:
text_magnitude = dlg.ui.Filter_LineEdit.text()
#QMessageBox.information(self.iface.mainWindow(),"cmd" , text_magnitude)
Magnitude_combotext = dlg.ui.Magnitude_comboBox.currentText()
#QMessageBox.information(self.iface.mainWindow(),"cmd" , Magnitude_combotext)
if Magnitude_combotext == "less than <":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "magnitude >= '
elif Magnitude_combotext == "<=":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "magnitude > '
elif Magnitude_combotext == "equal to =":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "magnitude <> '
elif Magnitude_combotext == ">=":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "magnitude < '
elif Magnitude_combotext == "greater than >=":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "magnitude <= '
command2 = '"'
#command3 = '\"'
command = str(command1)+str(text_magnitude)+ str(command2)+" "+ str(OutputShpFilterName)+ " "+str(InputShpFilterName)
#QMessageBox.information(self.iface.mainWindow(),"info" ,str(command))
os.system(command)
if dlg.ui.Add2MapcheckBox.isChecked() == False:
message = "Flows "+str(Magnitude_combotext)+str(text_magnitude)+" filtered and "+str(OutputShpFilterName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
else:
if dlg.ui.comboBoxSelectSymbology.currentText() == "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == False:
self.iface.addVectorLayer(str(OutputShpFilterName), str(OutputShpFilterName), "ogr")
SuccessMessage = str(OutputShpFilterName) + " created successfully !"
QMessageBox.information(self.iface.mainWindow(), "info", SuccessMessage, "Close")
elif dlg.ui.comboBoxSelectSymbology.currentText() == "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == True:
layer = QgsVectorLayer(str(OutputShpFilterName), str(OutputShpFilterName), 'ogr')
#Use the currently selected layer
#layer = qgis.utils.iface.mapCanvas().currentLayer()
registry = QgsSymbolLayerV2Registry.instance()
lineMeta = registry.symbolLayerMetadata("SimpleLine")
markerMeta = registry.symbolLayerMetadata("MarkerLine")
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
#Line layer
lineLayer = lineMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'offset': '0', 'penstyle': 'solid', 'use_custom_dash': '0', 'joinstyle': 'bevel', 'capstyle': 'square'})
#Marker layer
#markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'interval': '3', 'rotate': '1', 'placement': 'interval', 'offset': '0'})
markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'rotate': '1', 'placement': 'centralpoint', 'offset': '0'})
subSymbol = markerLayer.subSymbol()
#Replace the default layer with our own SimpleMarker
subSymbol.deleteSymbolLayer(0)
triangle = registry.symbolLayerMetadata("SimpleMarker").createSymbolLayer({'name': 'filled_arrowhead', 'color': '255,0,0', 'color_border': '0,0,0', 'offset': '0,0', 'size': '3', 'angle': '0'})
subSymbol.appendSymbolLayer(triangle)
#Replace the default layer with our two custom layers
symbol.deleteSymbolLayer(0)
symbol.appendSymbolLayer(lineLayer)
symbol.appendSymbolLayer(markerLayer)
#Replace the renderer of the current layer
renderer = QgsSingleSymbolRendererV2(symbol)
layer.setRendererV2(renderer)
#
QgsMapLayerRegistry.instance().addMapLayer( layer )
SuccessMessage = str(OutputShpFilterName) + " created successfully !"
#QMessageBox.information(self.iface.mainWindow(), "info", QString(SuccessMessage), QString('Close'))
QMessageBox.information(self.iface.mainWindow(), "info", SuccessMessage, "Close")
else:
global GradSymNoOfFeatures
global GradSymNoOfFeaturesZero
global GradSymMin
global GradSymMax
global GradSymSumMagnitude
global GradSymMean
global GradSymMeanNotZero
global GradSymStdDev
global GradSymStdDevNotZero
global GradSymList
shp = ogr.Open(str(OutputShpFilterName),1)
layer = shp.GetLayer(0)
GradSymNoOfFeatures = str(layer.GetFeatureCount())
feature = layer.GetNextFeature()
counterNotZero = 0
GradSymSumMagnitude = 0
GradSymList= []
while feature:
magnitude = feature.GetField('magnitude')
if magnitude > 0:
counterNotZero = counterNotZero + 1
GradSymList.append(int(magnitude))
GradSymMin = min(GradSymList)
GradSymMax = max(GradSymList)
GradSymSumMagnitude = GradSymSumMagnitude + magnitude
feature.Destroy()
feature = layer.GetNextFeature()
GradSymMean = str(round(float(GradSymSumMagnitude / int(GradSymNoOfFeatures)),3))
GradSymMeanNotZero = str(round(float(GradSymSumMagnitude / int(counterNotZero)),3))
GradSymSumMagnitude = str(GradSymSumMagnitude)
GradSymNoOfFeaturesZero = str(int(GradSymNoOfFeatures)-int(counterNotZero))
GradSymMin = str(GradSymMin)
GradSymMax = str(GradSymMax)
layer.ResetReading()
GradSymVar = 0
GradSymVarNotZero = 0
feature = layer.GetNextFeature()
while feature:
magnitude = feature.GetField('magnitude')
#feature = layer.GetNextFeature()
GradSymVar = GradSymVar + ((magnitude - float(GradSymMean))**2)
if magnitude > 0:
GradSymVarNotZero = GradSymVarNotZero + ((magnitude - float(GradSymMeanNotZero))**2)
feature.Destroy()
feature = layer.GetNextFeature()
GradSymStdDev = str(round(((GradSymVar / int(GradSymNoOfFeatures))**0.5), 3))
GradSymStdDevNotZero = str(round(((GradSymVarNotZero / int(counterNotZero))**0.5), 3))
layer.ResetReading()
shp.Destroy()
registry = QgsSymbolLayerV2Registry.instance()
lineMeta = registry.symbolLayerMetadata("SimpleLine")
markerMeta = registry.symbolLayerMetadata("MarkerLine")
def validatedDefaultSymbol(geometryType):
symbol = QgsSymbolV2.defaultSymbol(geometryType)
if symbol is None:
if geometryType == QGis.Point:
symbol = QgsMarkerSymbolV2()
elif geometryType == QGis.Line:
symbol = QgsLineSymbolV2()
elif geometryType == QGis.Polygon:
symbol = QgsFillSymbolV2()
return symbol
#Create Symbology
def makeSymbologyForRange(layer, min ,max, label ,colour, alpha, width):
symbol = validatedDefaultSymbol(layer.geometryType())
if dlg.ui.comboBoxSelectSymbology.currentText() <> "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == True:
#Line layer
lineLayer = lineMeta.createSymbolLayer({'width': '0.5', 'color': '255,0,0', 'offset': '0', 'penstyle': 'solid', 'use_custom_dash': '0', 'joinstyle': 'bevel', 'capstyle': 'square'})
#Marker layer
markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'rotate': '1', 'placement': 'centralpoint', 'offset': '0'})
subSymbol = markerLayer.subSymbol()
#Replace the default layer with our own SimpleMarker
subSymbol.deleteSymbolLayer(0)
triangle = registry.symbolLayerMetadata("SimpleMarker").createSymbolLayer({'name': 'filled_arrowhead', 'color': '255,0,0', 'color_border': '255,255,255', 'offset': '0,0', 'size': '3', 'outline_width': '0.5', 'angle': '0'})
subSymbol.appendSymbolLayer(triangle)
#Replace the default layer with our two custom layers
symbol.deleteSymbolLayer(0)
symbol.appendSymbolLayer(lineLayer)
symbol.appendSymbolLayer(markerLayer)
symbol.setColor(colour)
symbol.setAlpha(alpha)
symbol.setWidth(width)
range = QgsRendererRangeV2(min, max, symbol, label)
elif dlg.ui.comboBoxSelectSymbology.currentText() <> "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == False:
symbol.setColor(colour)
symbol.setAlpha(alpha)
symbol.setWidth(width)
range = QgsRendererRangeV2(min, max, symbol, label)
return range
vlayer = QgsVectorLayer(str(OutputShpFilterName), str(OutputShpFilterName), 'ogr')
myTargetField = 'magnitude'
#Define base line symbol width and multiplier factor for graduated classes
global basesymbolwidth
global multipliersymbolwidth
if dlg.ui.comboBoxSelectSymbology.currentText() <> "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == True:
global basesymbolwidth
global multipliersymbolwidth
basesymbolwidth = 3.0
multipliersymbolwidth = 2.0
elif dlg.ui.comboBoxSelectSymbology.currentText() <> "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == False:
global basesymbolwidth
global multipliersymbolwidth
basesymbolwidth = 0.25
multipliersymbolwidth = 0.75
#Equal Interval
if dlg.ui.comboBoxSelectSymbology.currentText() == "Equal Interval":
GradSymNoOfClasses = dlg.ui.spinBoxClasses.value()
GradSymInterval = round(((int(GradSymMax) - int(GradSymMin)) / float(GradSymNoOfClasses)),0)
myRangeList = []
for i in range(GradSymNoOfClasses):
if i == 0:
classlabel = str(GradSymMin)+" - "+str(int(GradSymMin)+GradSymInterval)
myRangeList.append(makeSymbologyForRange( vlayer, int(GradSymMin), int(GradSymMin)+GradSymInterval, classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, basesymbolwidth ))
elif i == (GradSymNoOfClasses - 1):
classlabel = str(int(GradSymMin)+(GradSymInterval*i)+0.001)+" - "+str(GradSymMax)
myRangeList.append(makeSymbologyForRange( vlayer, (GradSymInterval*i)+0.001, int(GradSymMax), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
else:
classlabel = str(int(GradSymMin)+(GradSymInterval*i)+0.001)+" - "+str(int(GradSymMin)+GradSymInterval*(i+1))
myRangeList.append(makeSymbologyForRange( vlayer, int(GradSymMin)+(GradSymInterval*i)+0.001, int(GradSymMin)+GradSymInterval*(i+1), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
myRenderer = QgsGraduatedSymbolRendererV2( myTargetField, myRangeList )
vlayer.setRendererV2( myRenderer )
message = "Flows "+str(Magnitude_combotext)+str(text_magnitude)+" filtered and "+str(OutputShpFilterName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
QgsMapLayerRegistry.instance().addMapLayer( vlayer )
#Defined Interval
elif dlg.ui.comboBoxSelectSymbology.currentText() == "Defined Interval":
GradSymInterval = int(dlg.ui.lineEditInterval.text())
GradSymNoOfClasses = int((int(GradSymMax) - int(GradSymMin)) / GradSymInterval) + 1
myRangeList = []
for i in range(GradSymNoOfClasses):
if i == 0:
classlabel = str(GradSymMin)+" - "+str(GradSymInterval)
myRangeList.append(makeSymbologyForRange( vlayer, int(GradSymMin), GradSymInterval, classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, basesymbolwidth ))
elif i == (GradSymNoOfClasses - 1):
classlabel = str((GradSymInterval*i)+0.001)+" - "+str(GradSymMax)
myRangeList.append(makeSymbologyForRange( vlayer, (GradSymInterval*i)+0.001, int(GradSymMax), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
else:
classlabel = str((GradSymInterval*i)+0.001)+" - "+str(GradSymInterval*(i+1))
myRangeList.append(makeSymbologyForRange( vlayer, (GradSymInterval*i)+0.001, GradSymInterval*(i+1), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
myRenderer = QgsGraduatedSymbolRendererV2( myTargetField, myRangeList )
vlayer.setRendererV2( myRenderer )
message = "Flows "+str(Magnitude_combotext)+str(text_magnitude)+" filtered and "+str(OutputShpFilterName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
QgsMapLayerRegistry.instance().addMapLayer( vlayer )
#Standard Deviation
elif dlg.ui.comboBoxSelectSymbology.currentText() == "Standard Deviation":
if dlg.ui.comboBoxSelectStdDev.currentText() == "1/4 Std. Dev.":
GradSymInterval = float(GradSymStdDevNotZero) / 4
GradSymNoOfClasses = int((int(GradSymMax) - int(GradSymMin)) / GradSymInterval) + 1
classlabelStdDev = 0.25
elif dlg.ui.comboBoxSelectStdDev.currentText() == "1/2 Std. Dev.":
GradSymInterval = float(GradSymStdDevNotZero) / 2
GradSymNoOfClasses = int((int(GradSymMax) - int(GradSymMin)) / GradSymInterval) + 1
classlabelStdDev = 0.5
elif dlg.ui.comboBoxSelectStdDev.currentText() == "1 Std. Dev.":
GradSymInterval = float(GradSymStdDevNotZero)
GradSymNoOfClasses = int((int(GradSymMax) - int(GradSymMin)) / GradSymInterval) + 1
classlabelStdDev = 1.0
elif dlg.ui.comboBoxSelectStdDev.currentText() == "2 Std. Dev.":
GradSymInterval = float(GradSymStdDevNotZero) * 2
GradSymNoOfClasses = int((int(GradSymMax) - int(GradSymMin)) / GradSymInterval) + 1
classlabelStdDev = 2.0
myRangeList = []
for i in range(GradSymNoOfClasses):
if i == 0:
classlabel = str((i+1)*classlabelStdDev)+" Std. Dev. "+str(GradSymMin)+" - "+str(GradSymInterval)
myRangeList.append(makeSymbologyForRange( vlayer, int(GradSymMin), GradSymInterval, classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, basesymbolwidth ))
elif i == (GradSymNoOfClasses - 1):
classlabel = str((i+1)*classlabelStdDev)+" Std. Dev. "+str((GradSymInterval*i)+0.001)+" - "+str(GradSymMax)
myRangeList.append(makeSymbologyForRange( vlayer, (GradSymInterval*i)+0.001, int(GradSymMax), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
else:
classlabel = str((i+1)*classlabelStdDev)+" Std. Dev. "+str((GradSymInterval*i)+0.001)+" - "+str(GradSymInterval*(i+1))
myRangeList.append(makeSymbologyForRange( vlayer, (GradSymInterval*i)+0.001, GradSymInterval*(i+1), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
myRenderer = QgsGraduatedSymbolRendererV2( myTargetField, myRangeList )
vlayer.setRendererV2( myRenderer )
message = "Flows "+str(Magnitude_combotext)+str(text_magnitude)+" filtered and "+str(OutputShpFilterName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
QgsMapLayerRegistry.instance().addMapLayer( vlayer )
#Equal Size Classes
elif dlg.ui.comboBoxSelectSymbology.currentText() == "Equal Size Classes":
GradSymNoOfClasses = dlg.ui.spinBoxClasses.value()
GradSymNoOfFeaturesZero = int(GradSymNoOfFeaturesZero)
GradSymNoOfFeaturesInInterval = int( round(((int(GradSymNoOfFeatures)-int(GradSymNoOfFeaturesZero))/float(GradSymNoOfClasses)),0) )
myRangeList = []
GradSymList.sort()
for i in range(GradSymNoOfClasses):
if i == 0:
classlabel = str(GradSymMin)+" - "+str(GradSymList[(GradSymNoOfFeaturesInInterval*(i+1))-1])
myRangeList.append(makeSymbologyForRange( vlayer, int(GradSymMin), GradSymList[(GradSymNoOfFeaturesInInterval*(i+1))-1], classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, basesymbolwidth ))
elif i == (GradSymNoOfClasses - 1):
classlabel = str(GradSymList[GradSymNoOfFeaturesInInterval*i])+" - "+str(GradSymMax)
myRangeList.append(makeSymbologyForRange( vlayer, GradSymList[GradSymNoOfFeaturesInInterval*i], int(GradSymMax), classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
else:
classlabel = str(GradSymList[GradSymNoOfFeaturesInInterval*i])+" - "+str(GradSymList[(GradSymNoOfFeaturesInInterval*(i+1))-1])
myRangeList.append(makeSymbologyForRange( vlayer, GradSymList[GradSymNoOfFeaturesInInterval*i], GradSymList[(GradSymNoOfFeaturesInInterval*(i+1))-1], classlabel , QColor(0, 255-(255*i/GradSymNoOfClasses), 255*i/GradSymNoOfClasses), 1, (i+1)*multipliersymbolwidth ))
myRenderer = QgsGraduatedSymbolRendererV2( myTargetField, myRangeList )
vlayer.setRendererV2( myRenderer )
message = "Flows "+str(Magnitude_combotext)+str(text_magnitude)+" filtered and "+str(OutputShpFilterName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
QgsMapLayerRegistry.instance().addMapLayer( vlayer )
def form3(self):
dlg = Form3Dialog()
#dlg.exec_()
dlg.show()
dlg.ui.CalStatLength.setEnabled(False)
global text_length
text_length = dlg.ui.FilterLength_LineEdit.text()
#result = dlg2.exec_()
QtCore.QObject.connect(dlg.ui.BrowseShapeInputFilterLength,QtCore.SIGNAL("clicked()"), self.InputShpFilterLength)
QtCore.QObject.connect(dlg.ui.BrowseShapeInputFilterLength,QtCore.SIGNAL("clicked()"), dlg.SetTextBrowseInputShapeFilterLength)
QtCore.QObject.connect(dlg.ui.BrowseShapeOutputFilterLength,QtCore.SIGNAL("clicked()"), self.OutputShpFilterLength)
QtCore.QObject.connect(dlg.ui.BrowseShapeOutputFilterLength,QtCore.SIGNAL("clicked()"), dlg.SetTextBrowseOutputShapeFilterLength)
#get stats for flowline lengths
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), self.CalStatFilterLength)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.MeanLength)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.MeanLengthNotZero)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.MaxFlowLength)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.MinFlowLength)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.StdDevLength)
QtCore.QObject.connect(dlg.ui.CalStatLength,QtCore.SIGNAL("clicked()"), dlg.StdDevLengthNotZero)
result = dlg.exec_()
if result == 1:
text_length = dlg.ui.FilterLength_LineEdit.text()
Length_combotext = str(dlg.ui.Length_comboBox.currentText())
if Length_combotext == "shorter than <":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "length_km >= '
elif Length_combotext == "<=":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "length_km > '
elif Length_combotext == "equal to =":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "length_km <> '
elif Length_combotext == ">=":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "length_km < '
elif Length_combotext == "longer than >":
command1 = 'ogr2ogr -f "ESRI Shapefile" -where "length_km <= '
command2 = '"'
#command3 = '\"'
command = str(command1)+str(text_length)+ str(command2)+" "+ str(OutputShpFilterLengthName)+ " "+str(InputShpFilterLengthName)
#QMessageBox.information(self.iface.mainWindow(),"info" ,str(command))
os.system(command)
if dlg.ui.Add2MapcheckBox.isChecked() == False:
message = "Flows "+str(Length_combotext)+str(text_length)+" filtered and "+str(OutputShpFilterLengthName)+" created successfully !"
QMessageBox.information(self.iface.mainWindow(),"info" ,message)
else:
if dlg.ui.comboBoxSelectSymbology.currentText() == "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == False:
self.iface.addVectorLayer(str(OutputShpFilterLengthName), str(OutputShpFilterLengthName), "ogr")
SuccessMessage = str(OutputShpFilterLengthName) + " created successfully !"
QMessageBox.information(self.iface.mainWindow(), "info", SuccessMessage, "Close")
elif dlg.ui.comboBoxSelectSymbology.currentText() == "Single Symbol" and dlg.ui.ShowDirectioncheckBox.isChecked() == True:
layer = QgsVectorLayer(str(OutputShpFilterLengthName), str(OutputShpFilterLengthName), 'ogr')
#Use the currently selected layer
#layer = qgis.utils.iface.mapCanvas().currentLayer()
registry = QgsSymbolLayerV2Registry.instance()
lineMeta = registry.symbolLayerMetadata("SimpleLine")
markerMeta = registry.symbolLayerMetadata("MarkerLine")
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
#Line layer
lineLayer = lineMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'offset': '0', 'penstyle': 'solid', 'use_custom_dash': '0', 'joinstyle': 'bevel', 'capstyle': 'square'})
#Marker layer
#markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'interval': '3', 'rotate': '1', 'placement': 'interval', 'offset': '0'})
markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'rotate': '1', 'placement': 'centralpoint', 'offset': '0'})
subSymbol = markerLayer.subSymbol()
#Replace the default layer with our own SimpleMarker
subSymbol.deleteSymbolLayer(0)
triangle = registry.symbolLayerMetadata("SimpleMarker").createSymbolLayer({'name': 'filled_arrowhead', 'color': '255,0,0', 'color_border': '0,0,0', 'offset': '0,0', 'size': '3', 'angle': '0'})
subSymbol.appendSymbolLayer(triangle)
#Replace the default layer with our two custom layers
symbol.deleteSymbolLayer(0)
symbol.appendSymbolLayer(lineLayer)
symbol.appendSymbolLayer(markerLayer)
#Replace the renderer of the current layer
renderer = QgsSingleSymbolRendererV2(symbol)
layer.setRendererV2(renderer)
#
QgsMapLayerRegistry.instance().addMapLayer( layer )
SuccessMessage = str(OutputShpFilterLengthName) + " created successfully !"
#QMessageBox.information(self.iface.mainWindow(), "info", QString(SuccessMessage), QString('Close'))
QMessageBox.information(self.iface.mainWindow(), "info", SuccessMessage, "Close")
else:
global GradSymNoOfFeatures
global GradSymNoOfFeaturesZero
global GradSymMin
global GradSymMax
global GradSymSumMagnitude
global GradSymMean
global GradSymMeanNotZero
global GradSymStdDev
global GradSymStdDevNotZero
global GradSymList
shp = ogr.Open(str(OutputShpFilterLengthName),1)
layer = shp.GetLayer(0)
GradSymNoOfFeatures = str(layer.GetFeatureCount())
feature = layer.GetNextFeature()
counterNotZero = 0
GradSymSumMagnitude = 0
GradSymList= []
while feature:
magnitude = feature.GetField('magnitude')