-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClipdata.vb
2849 lines (2653 loc) · 137 KB
/
Clipdata.vb
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
Imports System.IO
Imports GMap.NET
Imports GMap.NET.WindowsForms
Imports GMap.NET.WindowsForms.Markers
Imports GMap.NET.WindowsForms.ToolTips
Imports System.Text
Imports System.Net
Imports DotSpatial.Data
Imports DotSpatial.Topology
Imports System.Linq
Imports System.Drawing.Imaging
Public Class ClipDataForm
Public AppPath As String = Application.StartupPath() & "\"
Public strPath As String = ""
Public Event updatemap(sender As System.Object, e As System.EventArgs)
Public selectedmarker As GMapMarker = Nothing
Public markerIsSelected As Boolean = False
Public isMouseDown As Boolean
Public firstmarkerset As Boolean
Public filename_data As New List(Of SourceData)
Public MarkerVisible As Boolean = True 'Red Cross Marker GMapNet
Public maploaded As Boolean = False
Public startDataset As SourceData = Nothing
Public SetStartDatasetName As String = "Greater Toronto Area"
Public formfullyloaded As Boolean = False 'set to true after form is fully loaded
Public dataselall As Boolean = True '..true, if all datasets are to be exported, false if user made selection
Public hash As HashSet(Of String) = New HashSet(Of String) 'this could be Long, but LBSN_Guids may be strings!
Public hashUser As HashSet(Of String) = New HashSet(Of String)
Public hashTags As HashSet(Of String) = New HashSet(Of String)
'Filter Usersettings
Public Filterusers As Boolean = False
Public UserIDFilterListHash As HashSet(Of String) = New HashSet(Of String)
'Public values for data filter
Public Operator1, Operator2 As Integer
Public SearchTitle1, SearchTags1, SearchDesc1, SearchTitle2, SearchTags2, SearchDesc2, SearchTitle3, SearchTags3, SearchDesc3 As Boolean
Public searchFullWords As Boolean = True
Public DataFiltering As Boolean = False
Public noboundary As Boolean = False
'Global Declaration of PhotosPerDayLists for speed (used in case of temporal transponse)
Public PhotosPerDayLists As Dictionary(Of String, List(Of String)) = New Dictionary(Of String, List(Of String))(System.StringComparer.OrdinalIgnoreCase)
'global variables for speed in point-in-polygon test
' int polyCorners = how many corners the polygon has (no repeats)
' float polyX[] = horizontal coordinates of corners
' float polyY[] = vertical coordinates of corners
' float x, y = point to be tested
Public polyCorners As Integer 'Contains all point coordinates of selected shapefile(s)
Public polyX() As Double
Public polyY() As Double
Public xP As Double
Public yP As Double
Public b_xMax, b_xMin, b_yMax, b_yMin As Double
Dim featuresShape As New List(Of List(Of PointLatLng)) 'Feature-List with Point-Lists
Public ShapefilePoly As IFeatureSet = Nothing
Public Shapecount As Integer = 1
Public Singleextract As Boolean = False
' float constant[] = storage for precalculated constants (same size as polyX)
' float multiple[] = storage for precalculated multipliers (same size as polyX)
Public constant() As Double
Public multiple() As Double
'Source of data ("LBSN" or "Flickr")
Public DSMapping As sourcetype
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
maploaded = False
MarkerVisible = True
Dim strFileName As String = ""
Dim folderDialogBox As New FolderBrowserDialog()
filename_data.Clear()
strPath = Me.TextBox1.Text.Replace("...", Application.StartupPath())
If Not (Directory.Exists(strPath)) Then
MsgBox("Folder does not exist.")
Exit Sub
Else
If Not strPath.EndsWith("\") Then
strPath = strPath & "\"
End If
End If
Me.Refresh()
'Load files from subdirectories
Dim files As String()
Dim filename As String
Dim di As New DirectoryInfo(strPath)
Dim filenamepath As String
' Get a reference to each directory in that directory.
Dim diArrTemp As DirectoryInfo() = di.GetDirectories()
Dim diArr As New List(Of DirectoryInfo)
For Each directTemp As DirectoryInfo In diArrTemp
If Not directTemp.Name.StartsWith("0") Then
diArr.Add(directTemp)
End If
Next
Dim leftpart As String
' Populate Combobox.
Dim dri As DirectoryInfo
Dim currentSourceData As New SourceData
If File.Exists(strPath & "02_UserData\00_Index\UserGeocodeIndex.txt") Then
HelperFunctions.UserGeocodeIndex_Path = strPath & "02_UserData\00_Index\UserGeocodeIndex.txt"
'MsgBox(strPath & "02 _UserData\00_Index\UserGeocodeIndex.txt")
End If
If File.Exists(strPath & "02_UserData\00_Index\UserGeocodeIndex_inclCountry.txt") Then
HelperFunctions.UserGeocodeIndex_PathCC = strPath & "02_UserData\00_Index\UserGeocodeIndex_inclCountry.txt"
'MsgBox(strPath & "02 _UserData\00_Index\UserGeocodeIndex.txt")
End If
'Load Multifolder
For Each dri In diArr
currentSourceData = New SourceData
If File.Exists(strPath & dri.Name & "\settings.txt") Then
'Load Sourcetype Mapping (Column Names & Numbers)
Dim sourcetype_string As String
sourcetype_string = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "sourcetype")
If sourcetype_string = "" Then
sourcetype_string = "flickr"
End If
Dim sourcetype_path As String = strPath & "01_Config\sourcemapping_" & sourcetype_string & ".txt"
If File.Exists(sourcetype_path) Then
DSMapping = HelperFunctions.LoadSourceTypeMapping(sourcetype_path)
Else
MsgBox("Could not find SourceTypeMapping for given Type '" & sourcetype_string & "'")
Exit Sub
End If
currentSourceData.TotalPhotos = 0
currentSourceData.filename = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "profilename")
currentSourceData.bottomlat = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "bottomlat")
currentSourceData.leftlong = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "leftlong")
currentSourceData.toplat = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "toplat")
currentSourceData.rightlong = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "rightlong")
If HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "querytype") = "upload_time" Then
currentSourceData.fromDate = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "minuploaddate")
currentSourceData.toDate = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "maxuploaddate")
Else
currentSourceData.fromDate = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "mintakendate")
currentSourceData.toDate = HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "maxtakendate")
End If
If HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "maxperfile") = "" Then
currentSourceData.photosPerFile = 50000
Else
currentSourceData.photosPerFile = Val(HelperFunctions.GetSettingItem(strPath & dri.Name & "\settings.txt", "maxperfile"))
End If
files = Directory.GetFiles(strPath & dri.Name & "\")
'Set StartItem to Greater Toronto Area, if exists
If currentSourceData.filename = SetStartDatasetName Then startDataset = currentSourceData
For Each filename In files
filenamepath = filename
filename = filename.Substring(filename.LastIndexOf("\"c) + 1)
If filename.Length > 13 Then
If filename.Substring(filename.Length - 13) = "_settings.txt" Then
filename = "settings.txt"
End If
End If
If Not (filename = "GridCoordinates.txt") And Not (filename.Substring(0, 3) = "log") And Not filename.Contains("settings") Then
currentSourceData.datafiles.Add(filenamepath)
If InStr(currentSourceData.photosPerFile.ToString, filename) Then
currentSourceData.TotalPhotos = currentSourceData.TotalPhotos + currentSourceData.photosPerFile
Else
leftpart = Strings.Left(filename, filename.LastIndexOf("_"))
currentSourceData.TotalPhotos = currentSourceData.TotalPhotos + Val(Strings.Right(leftpart, Strings.Len(leftpart) - leftpart.LastIndexOf("_") - 1))
End If
End If
Next
filename_data.Add(currentSourceData)
End If
Next dri
'Load Single Folder (if no subfolders are found)
If diArr.Count = 0 Then
currentSourceData = New SourceData
If File.Exists(strPath & "settings.txt") Then
currentSourceData.filename = HelperFunctions.GetSettingItem(strPath & "settings.txt", "profilename")
currentSourceData.bottomlat = HelperFunctions.GetSettingItem(strPath & "settings.txt", "bottomlat")
currentSourceData.leftlong = HelperFunctions.GetSettingItem(strPath & "settings.txt", "leftlong")
currentSourceData.toplat = HelperFunctions.GetSettingItem(strPath & "settings.txt", "toplat")
currentSourceData.rightlong = HelperFunctions.GetSettingItem(strPath & "settings.txt", "rightlong")
Else
currentSourceData.filename = "World"
currentSourceData.bottomlat = -90
currentSourceData.leftlong = -180
currentSourceData.toplat = 90
currentSourceData.rightlong = 180
End If
files = Directory.GetFiles(strPath)
For Each filename In files
filenamepath = filename
filename = filename.Substring(filename.LastIndexOf("\"c) + 1)
If filename.Length > 13 Then
If filename.Substring(filename.Length - 13) = "_settings.txt" Then
filename = "settings.txt"
End If
End If
If Not (filename = "GridCoordinates.txt") And Not (filename.Substring(0, 3) = "log") And Not (filename = "settings.txt") Then
currentSourceData.datafiles.Add(filenamepath)
End If
Next
filename_data.Add(currentSourceData)
End If
If startDataset Is Nothing Then
startDataset = filename_data(0)
End If
Dim countFiles As Integer = 0
Dim countPhotos As Long = 0
For Each datafilesList As SourceData In filename_data
countFiles = countFiles + datafilesList.datafiles.Count
countPhotos = countPhotos + datafilesList.TotalPhotos
Next
If Not countFiles = 0 Then
Me.Label1.Text = "Number of files: " & countFiles & " (" & Math.Round(countPhotos, 0).ToString("N0") & " Photos)"
Me.Refresh()
If startDataset IsNot Nothing Then
Me.TextBox6.Text = startDataset.bottomlat
Me.TextBox3.Text = startDataset.leftlong
Me.TextBox5.Text = startDataset.toplat
Me.TextBox2.Text = startDataset.rightlong
Me.TextBox9.Text = startDataset.filename & "_Clip"
RaiseEvent updatemap(Button3, System.EventArgs.Empty)
maploaded = True
End If
End If
savesettings()
End Sub
Private Sub ClipDataForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.RadioButton1.Checked = True
Me.min_date.Enabled = False
Me.max_date.Enabled = False
Label15.ForeColor = SystemColors.InactiveCaptionText
Label24.ForeColor = SystemColors.InactiveCaptionText
RadioButton3.ForeColor = SystemColors.InactiveCaptionText
RadioButton4.ForeColor = SystemColors.InactiveCaptionText
RadioButton3.Checked = False
RadioButton4.Checked = False
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Me.updatemap
Dim centerlat, centerlong, toplat, bottomlat, leftlong, rightlong As Double
If TextBox6.Text = "" Or CheckBox2.Checked = True Then
toplat = 50.8475729536539
bottomlat = 10.8333059836425
rightlong = -63.6328125
leftlong = -129.375
centerlong = Math.Min(leftlong + (rightlong - leftlong) / 2, 180) 'Add half the distance to leftlong
centerlat = Math.Min(bottomlat + (toplat - bottomlat) / 2, 90) 'Add half the distance to bottomlat
Else
toplat = Val(Replace(TextBox5.Text, ",", "."))
bottomlat = Val(Replace(TextBox6.Text, ",", "."))
rightlong = Val(Replace(TextBox2.Text, ",", "."))
leftlong = Val(Replace(TextBox3.Text, ",", "."))
TextBox5.Text = toplat
TextBox6.Text = bottomlat
TextBox2.Text = rightlong
TextBox3.Text = leftlong
centerlong = Math.Min(leftlong + (rightlong - leftlong) / 2, 180)
centerlat = Math.Min(bottomlat + (toplat - bottomlat) / 2, 90)
End If
With GMapControl1
'.SetCurrentPositionByKeywords("USA")
.MapType = GMap.NET.MapType.BingMap
.MinZoom = 1
.MaxZoom = 25
.Zoom = 10
.Manager.Mode = GMap.NET.AccessMode.ServerAndCache
.Position = New GMap.NET.PointLatLng(centerlat, centerlong)
.DragButton = MouseButtons.Left
.CanDragMap = True
End With
'Reset Map and Draw Selection Rectangle
GMapControl1.Overlays.Clear()
Dim overlayOne As New GMapOverlay(GMapControl1, "OverlayOne")
Dim MarkerOverlay As New GMapOverlay(GMapControl1, "Marker")
Dim points As New List(Of PointLatLng)
Dim polygon_red As New GMapPolygon(points, "Rectangle")
HelperFunctions.InitialDrawMarkers(centerlat, centerlong, toplat, bottomlat, leftlong, rightlong, points, polygon_red, startDataset, overlayOne, MarkerOverlay)
'Draw all other markers / Draws rectangles for each loaded dataset
Dim i As Integer = 0
For Each x As SourceData In filename_data
If Not IsNothing(x.toDate) Then
'First Draw red & grey rectangles
centerlong = Math.Min(x.leftlong + (x.rightlong - x.leftlong) / 2, 180) 'Addiere halben Abstand zu leftlong
centerlat = Math.Min(x.bottomlat + (x.toplat - x.bottomlat) / 2, 90) 'Addiere halben Abstand zu bottomlat
i = i + 1
toplat = x.toplat
bottomlat = x.bottomlat
rightlong = x.rightlong
leftlong = x.leftlong
points = New List(Of PointLatLng)
points.Add(New PointLatLng(toplat, leftlong))
points.Add(New PointLatLng(toplat, rightlong))
points.Add(New PointLatLng(bottomlat, rightlong))
points.Add(New PointLatLng(bottomlat, leftlong))
points.Add(New PointLatLng(toplat, leftlong))
Dim polygon_grey As GMapPolygon = Nothing
polygon_red = New GMapPolygon(points, x.filename)
polygon_red.Fill = New SolidBrush(Color.FromArgb(0, Color.White))
polygon_red.Stroke = New Pen(Color.Red, 0.25)
MarkerOverlay.Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerCross(New PointLatLng(centerlat, centerlong)))
MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1).ToolTip = New GMapToolTip(MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1))
MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1).ToolTipText = x.filename & Environment.NewLine & "Period: " & x.fromDate & " to " & x.toDate & Environment.NewLine & Math.Round(x.TotalPhotos, 0).ToString("N0") & " Photos"
If Not IsNothing(polygon_grey) Then overlayOne.Polygons.Add(polygon_grey)
If Not IsNothing(polygon_red) Then overlayOne.Polygons.Add(polygon_red)
GMapControl1.Overlays.Add(MarkerOverlay)
End If
Next
For Each x As SourceData In filename_data
If Not IsNothing(x.toDate) Then
'then Draw all blue rectangles
If x.toDate.Length >= 4 And Val(x.toDate.Substring(x.toDate.Length - 4)) = 2017 Then
centerlong = Math.Min(x.leftlong + (x.rightlong - x.leftlong) / 2, 180) 'Addiere halben Abstand zu leftlong
centerlat = Math.Min(x.bottomlat + (x.toplat - x.bottomlat) / 2, 90) 'Addiere halben Abstand zu bottomlat
'tooltip = New GMapToolTip(Markers)
i = i + 1
toplat = x.toplat
bottomlat = x.bottomlat
rightlong = x.rightlong
leftlong = x.leftlong
points = New List(Of PointLatLng)
points.Add(New PointLatLng(toplat, leftlong))
points.Add(New PointLatLng(toplat, rightlong))
points.Add(New PointLatLng(bottomlat, rightlong))
points.Add(New PointLatLng(bottomlat, leftlong))
points.Add(New PointLatLng(toplat, leftlong))
Dim polygon_blue As GMapPolygon = Nothing
polygon_blue = New GMapPolygon(points, x.filename)
polygon_blue.Fill = New SolidBrush(Color.FromArgb(0, Color.White))
polygon_blue.Stroke = New Pen(Color.Blue, 0.25)
MarkerOverlay.Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerCross(New PointLatLng(centerlat, centerlong)))
MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1).ToolTip = New GMapToolTip(MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1))
MarkerOverlay.Markers.Item(MarkerOverlay.Markers.Count - 1).ToolTipText = x.filename & Environment.NewLine & "Period: " & x.fromDate & " to " & x.toDate & Environment.NewLine & Math.Round(x.TotalPhotos, 0).ToString("N0") & " Photos"
If Not IsNothing(polygon_blue) Then overlayOne.Polygons.Add(polygon_blue)
GMapControl1.Overlays.Add(MarkerOverlay)
End If
End If
Next
If i = 0 Then
noboundary = True
GMapControl1.SetZoomToFitRect(New GMap.NET.RectLatLng(New GMap.NET.PointLatLng(toplat, leftlong), New GMap.NET.SizeLatLng(New GMap.NET.PointLatLng(toplat - bottomlat, rightlong - leftlong))))
End If
End Sub
Private Sub GMapControl1_MouseDown(sender As Object, e As MouseEventArgs) Handles GMapControl1.MouseDown
isMouseDown = True
For Each m As GMapMarker In GMapControl1.Overlays(1).Markers
If m.IsMouseOver = True Then
selectedmarker = m
markerIsSelected = True
End If
Next
If markerIsSelected = False Then selectedmarker = Nothing
End Sub
Private Sub GMapControl1_MouseMove(sender As Object, e As MouseEventArgs) Handles GMapControl1.MouseMove
Dim rectbottomleft As PointLatLng
Dim recttopright As PointLatLng
Dim latDist, longDist As Double
If (e.Button = MouseButtons.Left) And isMouseDown = True And markerIsSelected = True Then
selectedmarker.Position = GMapControl1.FromLocalToLatLng(e.X, e.Y)
GMapControl1.Overlays(2).Polygons.Clear()
rectbottomleft.Lat = GMapControl1.Overlays(1).Markers.Item(0).Position.Lat
rectbottomleft.Lng = GMapControl1.Overlays(1).Markers.Item(0).Position.Lng
recttopright.Lat = GMapControl1.Overlays(1).Markers.Item(1).Position.Lat
recttopright.Lng = GMapControl1.Overlays(1).Markers.Item(1).Position.Lng
Dim pointsRect As New List(Of PointLatLng)
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
Dim polygon2 As New GMapPolygon(pointsRect, "RectangleSel")
polygon2.Fill = New SolidBrush(Color.FromArgb(50, Color.Red))
polygon2.Stroke = New Pen(Color.Red, 0.25)
GMapControl1.Overlays(2).Polygons.Add(polygon2)
If Val(rectbottomleft.Lat) < Val(recttopright.Lat) Then
TextBox6.Text = rectbottomleft.Lat
TextBox5.Text = recttopright.Lat
Else
TextBox6.Text = recttopright.Lat
TextBox5.Text = rectbottomleft.Lat
End If
If Val(rectbottomleft.Lng) < Val(recttopright.Lng) Then
TextBox3.Text = rectbottomleft.Lng
TextBox2.Text = recttopright.Lng
Else
TextBox3.Text = recttopright.Lng
TextBox2.Text = rectbottomleft.Lng
End If
latDist = ((Val(TextBox5.Text) - Val(TextBox6.Text)) * 60 * 1852) / 1000 'Distanz zwischen den zwei Lat-Werten in km
longDist = ((Val(TextBox2.Text) - Val(TextBox3.Text)) * 48 * 1852) / 1000 'Distanz zwischen den zwei Long-Werten in km
TextBox7.Text = Math.Round(longDist, 2).ToString & " km"
TextBox8.Text = Math.Round(latDist, 2).ToString & " km"
ElseIf (e.Button = MouseButtons.Right) And isMouseDown = True And markerIsSelected = False Then
If firstmarkerset = False Then
GMapControl1.Overlays(1).Markers.Clear()
GMapControl1.Overlays(1).Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(New PointLatLng(GMapControl1.FromLocalToLatLng(e.X, e.Y).Lat, GMapControl1.FromLocalToLatLng(e.X, e.Y).Lng)))
GMapControl1.Overlays(1).Markers.Add(New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(New PointLatLng(GMapControl1.FromLocalToLatLng(e.X, e.Y).Lat, GMapControl1.FromLocalToLatLng(e.X, e.Y).Lng)))
firstmarkerset = True
End If
GMapControl1.Overlays(1).Markers.Item(1).Position = GMapControl1.FromLocalToLatLng(e.X, e.Y)
GMapControl1.Overlays(2).Polygons.Clear()
rectbottomleft.Lat = GMapControl1.Overlays(1).Markers.Item(0).Position.Lat
rectbottomleft.Lng = GMapControl1.Overlays(1).Markers.Item(0).Position.Lng
recttopright.Lat = GMapControl1.Overlays(1).Markers.Item(1).Position.Lat
recttopright.Lng = GMapControl1.Overlays(1).Markers.Item(1).Position.Lng
Dim pointsRect As New List(Of PointLatLng)
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
Dim polygon2 As New GMapPolygon(pointsRect, "RectangleSel")
polygon2.Fill = New SolidBrush(Color.FromArgb(50, Color.Red))
polygon2.Stroke = New Pen(Color.Red, 0.25)
GMapControl1.Overlays(2).Polygons.Add(polygon2)
If Val(rectbottomleft.Lat) < Val(recttopright.Lat) Then
TextBox6.Text = rectbottomleft.Lat
TextBox5.Text = recttopright.Lat
Else
TextBox6.Text = recttopright.Lat
TextBox5.Text = rectbottomleft.Lat
End If
If Val(rectbottomleft.Lng) < Val(recttopright.Lng) Then
TextBox3.Text = rectbottomleft.Lng
TextBox2.Text = recttopright.Lng
Else
TextBox3.Text = recttopright.Lng
TextBox2.Text = rectbottomleft.Lng
End If
latDist = Math.Round(((Val(TextBox5.Text) - Val(TextBox6.Text)) * 60 * 1852) / 1000) 'Distance between two lat-values (simple calculation, not accurate. Should substitute with GetDistanceBetweenPoints (Haversine Formula)
longDist = Math.Round(((Val(TextBox2.Text) - Val(TextBox3.Text)) * 48 * 1852) / 1000) 'Distance between two lat-values (simple calculation, not accurate. Should substitute with GetDistanceBetweenPoints (Haversine Formula)
TextBox7.Text = Math.Round(longDist, 2).ToString & " km"
TextBox8.Text = Math.Round(latDist, 2).ToString & " km"
End If
End Sub
Private Sub GMapControl1_MouseUp(sender As Object, e As MouseEventArgs) Handles GMapControl1.MouseUp
isMouseDown = False
selectedmarker = Nothing
markerIsSelected = False
firstmarkerset = False
End Sub
Private Sub GMapControl1_MouseLeave(sender As Object, e As EventArgs) Handles GMapControl1.MouseLeave
isMouseDown = False
selectedmarker = Nothing
markerIsSelected = False
firstmarkerset = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Dim rectbottomleft As PointLatLng
Dim recttopright As PointLatLng
GMapControl1.Overlays(2).Polygons.Clear()
rectbottomleft.Lat = GMapControl1.FromLocalToLatLng(GMapControl1.DisplayRectangle.Left, GMapControl1.DisplayRectangle.Bottom).Lat
rectbottomleft.Lng = GMapControl1.FromLocalToLatLng(GMapControl1.DisplayRectangle.Left, GMapControl1.DisplayRectangle.Bottom).Lng
recttopright.Lat = GMapControl1.FromLocalToLatLng(GMapControl1.DisplayRectangle.Top, GMapControl1.DisplayRectangle.Right).Lat
recttopright.Lng = GMapControl1.FromLocalToLatLng(GMapControl1.DisplayRectangle.Top, GMapControl1.DisplayRectangle.Right).Lng
Dim pointsRect As New List(Of PointLatLng)
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, recttopright.Lng))
pointsRect.Add(New PointLatLng(rectbottomleft.Lat, rectbottomleft.Lng))
pointsRect.Add(New PointLatLng(recttopright.Lat, rectbottomleft.Lng))
Dim polygon2 As New GMapPolygon(pointsRect, "RectangleSel")
polygon2.Fill = New SolidBrush(Color.FromArgb(50, Color.Red))
polygon2.Stroke = New Pen(Color.Red, 0.25)
GMapControl1.Overlays(2).Polygons.Add(polygon2)
End Sub
Private Sub TextBox3_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
'Add Validating
End Sub
Private Sub TextBox2_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
'Add Validating
End Sub
Private Sub TextBox6_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
'Add Validating
End Sub
Private Sub TextBox5_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs)
'Add Validating
End Sub
Private Sub searchexport(export As Boolean)
Dim InputDir As String = TextBox1.Text.Replace("...", Application.StartupPath())
Dim outputname As String = TextBox9.Text
Dim outputdir As String = AppPath & "02_Output\01_ClippedData\" & outputname & "\"
Dim filenamepath As String
Dim newfilenamepath As String = Nothing
Dim visMap As New Bitmap(visualForm.PictureBox1.Width, visualForm.PictureBox1.Height)
Dim statImage As Bitmap
Dim photocollection As Boolean = CheckBox30.Checked
Dim userOriginExport As Boolean = CheckBox29.Checked
Dim UserLocationGeocodeDict As Dictionary(Of String, KeyValuePair(Of Double, Double)) = New Dictionary(Of String, KeyValuePair(Of Double, Double))(System.StringComparer.OrdinalIgnoreCase) 'Dictionary of String-Location to lat/lng values
Dim maptouristslocals As Boolean = CheckBox32.Checked
Dim mapPhotosFromLocals As Boolean = CheckBox33.Checked
Dim mapPhotosFromTourists As Boolean = CheckBox19.Checked
Dim PhotoIDc As String = ""
Dim Tagsc As Long = 0
Dim UserIDc As String = Nothing
Dim Views As Integer = 0
Dim PhotoURL As String = ""
Dim NoClip As Boolean = CheckBox2.Checked
Dim NoStatistics As Boolean = CheckBox16.Checked
Dim filtertext1 As String = ""
Dim filtertext2 As String = ""
Dim filtertext3 As String = ""
Dim retainfolderstructure As Boolean = CheckBox27.Checked
Dim estimateUnique As Boolean = False
Dim estPhotosBase As Long = 0
Dim estHashtagBase As Long = 0
Dim rectbottomleft, recttopright As PointLatLng
Dim outputfile As System.IO.TextWriter = Nothing
Dim countlines As Long = 0
Dim countlines_sich As Long = 0
Dim countnewfiles As Integer = 0
Dim header_line As String = Nothing
Dim header_line_written As Boolean = False
Dim minDate As System.DateTime = min_date.Value
Dim maxDate As System.DateTime = max_date.Value
Dim UDate, PDate As System.DateTime 'Upload date, PhotoDate
Dim settingsExportOnly As Boolean = CheckBox34.Checked
Dim timetransponse As Boolean = CheckBox36.Checked 'whether data output to yyyy-MM-dd or not
Dim dirCreatedHash As New HashSet(Of String) 'contains list of yyyy-values to remember which years (timetransponse) were already created
Dim keyCreatedHash As New HashSet(Of String) 'Contains keys of yyyy-mm-dd for check before add
Dim GroupByTime As String = "yyyy-MM-d"
Dim exportSequentialPNG As Boolean = CheckBox37.Checked 'If true: export PNG after each datafile was processed = each day, month or year, depending on structure of loaded data)
Dim seqFileNumber As Integer = 0
Dim printDate As Boolean = True 'enable for printing date (based on filename) (only on seqImage export)
Dim drawBiasGraph As Boolean = CheckBox38.Checked 'if enabled, bias graph will be drawn on temporal sequence
Dim temporalUserOriginCountDictionary_Country As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)(System.StringComparer.OrdinalIgnoreCase) 'Dictionary of Number of users per time-increment per origin string
Dim temporalUniqueUserIDCount As New HashSet(Of String)
'If Datasource from LBSN: define which sourcetypes should be exported
If DSMapping.name = "lbsn" Then
Dim DataSourceExportTypes As New List(Of Integer)
'define list of sources to be exported
'1 = Instagram, 2 = Flickr, 3 = Twitter
If CheckBox48.Checked = True Then
DataSourceExportTypes.Add(2)
End If
If CheckBox47.Checked = True Then
DataSourceExportTypes.Add(1)
End If
If CheckBox48.Checked = True Then
DataSourceExportTypes.Add(3)
End If
End If
'Initialize UserOriginCountDictionary based on total available Origin Countries
If drawBiasGraph Then
For Each a As KeyValuePair(Of String, KeyValuePair(Of String, String)) In HelperFunctions.UserOriginCountryDict
temporalUserOriginCountDictionary_Country.Add(a.Value.Key, 0)
Next
End If
'Initialize Graphics/Point Map
Dim grap As Drawing.Graphics = Drawing.Graphics.FromImage(visMap)
grap.Clear(Drawing.Color.Pink)
visMap.MakeTransparent(Color.Pink)
visualForm.PictureBox1.Visible = True
visualForm.ComboBox2.Enabled = False
Label5.Visible = True
If CheckBox15.Checked Then
'Precalc Coordinates for Selected Area
Label5.Text = "Precalculating index ..."
Me.Refresh()
visualForm.precalcValues(visualForm.PictureBox1.Height, visualForm.PictureBox1.Width)
Me.Refresh()
End If
visualForm.startalpha = Val(visualForm.TextBox1.Text)
visualForm.stepInc = visualForm.NumericUpDown1.Value
visualForm.TextBox1.Enabled = False
visualForm.NumericUpDown1.Enabled = False
visualForm.ComboBox2.Enabled = False
visualForm.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
'Prepare list of datasets to be exported, based on the users selection
'This is the List of Row-Names, update if row names have changed!
Dim dataSelList As New List(Of String)
If Not dataselall = True Then
If CheckBox3.Checked = True Then
dataSelList.Add(DSMapping.latitude_colName)
dataSelList.Add(DSMapping.longitude_colName)
End If
If CheckBox4.Checked = True Then dataSelList.Add(DSMapping.post_title_colName)
If CheckBox5.Checked = True Then dataSelList.Add(DSMapping.post_thumbnail_url_colName)
If CheckBox6.Checked = True Then dataSelList.Add(DSMapping.post_guid_colName)
If CheckBox7.Checked = True Then dataSelList.Add(DSMapping.username_colName)
If CheckBox8.Checked = True Then dataSelList.Add(DSMapping.user_guid_colName)
If CheckBox9.Checked = True Then dataSelList.Add(DSMapping.post_create_date_colName)
If CheckBox10.Checked = True Then dataSelList.Add(DSMapping.post_publish_date_colName)
If CheckBox11.Checked = True Then dataSelList.Add(DSMapping.post_view_count_colName)
If CheckBox12.Checked = True Then dataSelList.Add(DSMapping.tags_colName)
'If CheckBox13.Checked = True Then dataSelList.Add("MTags")
'If CheckBox40.Checked = True Then dataSelList.Add("Accuracy")
'If CheckBox39.Checked = True Then dataSelList.Add("Description")
'If CheckBox41.Checked = True Then dataSelList.Add("License")
'If CheckBox42.Checked = True Then dataSelList.Add("GeoContext")
End If
'userExport preparations
UserLocationGeocodeDict.Clear()
Dim localusercount As Long = 0
If userOriginExport = True Or CheckBox31.Checked = True Or maptouristslocals = True Or mapPhotosFromLocals = True Or mapPhotosFromTourists = True Then
HelperFunctions.LoadUserLocationGeocodeIndex()
End If
If drawBiasGraph = True Then
'load User Country/Continent list from UserGeocodeIndex_inclCountry.txt
HelperFunctions.LoadUserLocationGeocodeIndex(True)
End If
If timetransponse Then
PhotosPerDayLists.Clear()
dirCreatedHash.Clear()
keyCreatedHash.Clear()
If RadioButton12.Checked Then
GroupByTime = "yyyy-MM-d"
ElseIf RadioButton11.Checked Then
GroupByTime = "yyyy-MM"
Else
GroupByTime = "yyyy"
End If
End If
'Check for Advanced Filter Criteria
If Not CheckBox26.Checked = True And Not TextBox10.Text = String.Empty Then
DataFiltering = True
searchFullWords = CheckBox28.Checked
filtertext1 = TextBox10.Text.ToLower
SearchTags1 = CheckBox17.Checked
SearchTitle1 = CheckBox18.Checked
SearchDesc1 = CheckBox43.Checked
If Not TextBox11.Text = String.Empty Then
filtertext2 = TextBox11.Text.ToLower
SearchTags2 = CheckBox20.Checked
SearchTitle2 = CheckBox21.Checked
SearchDesc2 = CheckBox44.Checked
If RadioButton2.Checked = True Then
Operator1 = 1 'And
ElseIf RadioButton5.Checked = True Then
Operator1 = 2 'or
Else
Operator1 = 3 'not
End If
If Not TextBox12.Text = String.Empty Then
filtertext3 = TextBox12.Text.ToLower
SearchTags3 = CheckBox23.Checked
SearchTitle3 = CheckBox24.Checked
SearchDesc3 = CheckBox45.Checked
If RadioButton9.Checked = True Then
Operator1 = 1 'And
ElseIf RadioButton7.Checked = True Then
Operator1 = 2 'or
Else
Operator1 = 3 'not
End If
End If
End If
End If
hash.Clear()
hashUser.Clear()
hashTags.Clear()
Label5.Text = ""
Label6.Text = ""
Label13.Visible = False
Label14.Visible = False
rectbottomleft.Lat = Val(TextBox6.Text)
rectbottomleft.Lng = Val(TextBox3.Text)
recttopright.Lat = Val(TextBox5.Text)
recttopright.Lng = Val(TextBox2.Text)
'Prepare Shapefile-Search (optional)
Dim ShapefileSearch As Boolean = False
Dim ShapefilePoly As Shapefile = Nothing
If Not TextBox4.Text = "" Then
Try
ShapefilePoly = Shapefile.OpenFile(TextBox4.Text)
Catch e As System.Exception
MsgBox(e.Message)
Exit Sub
End Try
ShapefileSearch = True
End If
'Prepare Multiple iterations for multiple features in shapefile (optional)
' 1 feature: For shapenumber As Integer = 0 To 0 --> (no repetition)
Dim repeat As Integer = Shapecount - 1
If Shapecount > 1 Then Label44.Visible = True
'Run at least once, multiple times for multiple shapes in feature
For shapenumber As Integer = 0 To repeat
Dim ProgressText As String = ""
If repeat > 0 Then
Label44.Text = "Shape " & shapenumber + 1 & " of " & Shapecount
End If
Me.Refresh()
If ShapefileSearch = True Then
polyY = Nothing
polyX = Nothing
constant = Nothing
multiple = Nothing
Dim x As Long = 0
'add coordinates of current shape to List for precalculation of raycasting/dotspatial.intersect
For Each pointLatLng As PointLatLng In featuresShape(shapenumber)
ReDim Preserve polyY(x)
ReDim Preserve polyX(x)
polyY(x) = pointLatLng.Lat
polyX(x) = pointLatLng.Lng
x = x + 1
Next
'ReDim PolyCorners Constant for size of Polycorners
ReDim constant(x)
ReDim multiple(x)
polyCorners = x
'Pre-Calculate Polygon Selection Values for raycasting
If CheckBox14.Checked = True Then
precalc_values()
End If
End If
'Reset variables after each feature in shapefile is processed
Dim i As Integer = 0
Dim filename_data_sel As New List(Of SourceData)
Dim filename_data_sel_CompletelyWithin As New List(Of SourceData)
Dim count_filelist_sel As Integer = 0
Dim SpatialSkip As Boolean = False 'is true when dataset completely within selection, no point-based query necessary
'First check if datasets are concerned by user selected area
'''''Dataset selection start''''''
For Each DataSet As SourceData In filename_data
Dim fs_data As New FeatureSet(FeatureType.Polygon)
' create a geometry from data_set extent
Dim vertices As New List(Of Coordinate)()
vertices.Add(New Coordinate(DataSet.leftlong, DataSet.bottomlat))
vertices.Add(New Coordinate(DataSet.leftlong, DataSet.toplat))
vertices.Add(New Coordinate(DataSet.rightlong, DataSet.toplat))
vertices.Add(New Coordinate(DataSet.rightlong, DataSet.bottomlat))
Dim geom As New Polygon(vertices)
' add the dataset-geometry to the featureset.
Dim data_feature As IFeature = fs_data.AddFeature(geom)
If NoClip = True OrElse DataSet.filename = "World" Then
'Filename = "World" is used when no settings.txt found / no boundary available (e.g. as is the case for temporal file structure)
filename_data_sel.Add(DataSet)
count_filelist_sel = count_filelist_sel + DataSet.datafiles.Count
ElseIf ShapefileSearch = False Or mapPhotosFromLocals = True Or mapPhotosFromTourists = True Then
Dim fs_SelBox As New FeatureSet(FeatureType.Polygon)
' create a geometry from data_set extent
Dim vertices_Selbox As New List(Of Coordinate)()
vertices_Selbox.Add(New Coordinate(rectbottomleft.Lng, rectbottomleft.Lat))
vertices_Selbox.Add(New Coordinate(rectbottomleft.Lng, recttopright.Lat))
vertices_Selbox.Add(New Coordinate(recttopright.Lng, recttopright.Lat))
vertices_Selbox.Add(New Coordinate(recttopright.Lng, rectbottomleft.Lat))
Dim geom_Selbox As New Polygon(vertices_Selbox)
' add the dataset-geometry to the featureset.
Dim SelBox_feature As IFeature = fs_SelBox.AddFeature(geom_Selbox)
'Check intersection
If SelBox_feature.Intersects(data_feature) Then
filename_data_sel.Add(DataSet)
count_filelist_sel = count_filelist_sel + DataSet.datafiles.Count
If SelBox_feature.Contains(data_feature) Then
filename_data_sel_CompletelyWithin.Add(DataSet) 'Based on this list, datasets can be added to the output without detailed point-in-polygon test
End If
End If
Else 'if Shapefilesearch (and no maplocaluser-search)
Dim f As Feature = ShapefilePoly.Features(shapenumber)
If f IsNot Nothing Then
If f.Intersects(data_feature) Then
filename_data_sel.Add(DataSet)
count_filelist_sel = count_filelist_sel + DataSet.datafiles.Count
If f.Contains(data_feature) Then
filename_data_sel_CompletelyWithin.Add(DataSet) 'Based on this list, datasets can be added to the output without detailed point-in-polygon test
End If
End If
End If
End If
Next
'''''Dataset selection end''''''
If filename_data_sel.Count = 0 Then
MsgBox("No data exists for this boundary.")
Exit Sub
End If
ProgressBar1.Value = 0
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = count_filelist_sel
countnewfiles = countnewfiles + 1
If retainfolderstructure = False Then
If timetransponse = False Then
newfilenamepath = outputdir & outputname
Else
newfilenamepath = outputdir
End If
If export = True Or userOriginExport = True Then
If Not (Directory.Exists(outputdir)) Then
Directory.CreateDirectory(outputdir)
End If
If export = True And timetransponse = False Then outputfile = System.IO.File.CreateText(newfilenamepath & "_" & countnewfiles & "." & DSMapping.fileExtension)
End If
End If
Label6.Visible = True
'Now check each dataset for photos lying within the selection boundary + temporal constraints
For Each dataSource As SourceData In filename_data_sel
If retainfolderstructure = True AndAlso export = True Then
Dim split As String() = dataSource.datafiles(0).Split("\") 'Split Full Path into segments
Dim parentFolder As String = split(split.Length - 2)
outputdir = AppPath & "02_Output\01_ClippedData\" & outputname & "\" & parentFolder & "\"
newfilenamepath = outputdir & parentFolder
If Not (Directory.Exists(outputdir)) Then
Directory.CreateDirectory(outputdir)
End If
If File.Exists(Path.GetDirectoryName(dataSource.datafiles(0)) & "\settings.txt") Then
'File.Copy(Path.GetDirectoryName(dataSource.datafiles(0)) & "\settings.txt", outputdir & "\settings.txt")
HelperFunctions.TransferSettings(Path.GetDirectoryName(dataSource.datafiles(0)) & "\settings.txt", outputdir & "\settings.txt")
End If
If settingsExportOnly = False And timetransponse = False Then outputfile = System.IO.File.CreateText(newfilenamepath & "_" & countnewfiles & "." & DSMapping.fileExtension) 'create first file container for data
End If
If settingsExportOnly = False Then 'skip export of datafiles if only settings export selected (if true, will created empty folder structure with settings.txt's)
SpatialSkip = False
If NoClip OrElse filename_data_sel_CompletelyWithin.Contains(dataSource) OrElse mapPhotosFromLocals = True OrElse mapPhotosFromTourists = True Then SpatialSkip = True
For Each filename As String In dataSource.datafiles
Using fp As New FastPix(visMap)
Dim line As Long = 0
filenamepath = filename
filename = filename.Substring(filename.LastIndexOf("\"c) + 1)
If File.Exists(filenamepath) Then
i = i + 1
Label5.Text = "Processing file " & filename & " (" & i & " of " & count_filelist_sel.ToString & ")."
Me.Refresh()
'Start Reading File
Dim objReader As New System.IO.StreamReader(filenamepath, Encoding.UTF8)
Dim result As String() = Nothing
Dim sourceID As Integer = 0
Dim resultLat, resultLng As Double
Dim linetext As String
Dim linetextArr As String() = Nothing
Dim dateColumn As Integer = 0
Dim headerline_arr As String()
Dim headerline_arr_sel As New List(Of String)
Dim c As Integer = 0
linetext = objReader.ReadLine()
line = line + 1
'Define Headerline
header_line = linetext
headerline_arr = header_line.Split(",")
For Each d As String In headerline_arr
If dataSelList.Contains(d) Then headerline_arr_sel.Add(d) 'Add Items to Export-Selection if user has selected them
If RadioButton1.Checked = False Or timetransponse = True Then
If d = DSMapping.post_create_date_colName Then
If RadioButton3.Checked = True Then dateColumn = c
End If
If d = DSMapping.post_publish_date_colName Then
If RadioButton3.Checked = False Then dateColumn = c
End If
End If
c = c + 1
Next
If dateColumn = 0 AndAlso (RadioButton1.Checked = False Or timetransponse = True) Then
MsgBox("Could not find Date Column in Input Data.")
Exit Sub
End If
'Re-Define Headerline if only specific data is to be exported
If dataselall = False Then
header_line = "ID"
For Each DataRow As String In dataSelList 'for each row-name in list of selected-for-export datarows
header_line = header_line & "," & DataRow
Next
End If
'Reset User Origin Dictionaries per temporal increment (= per file)
If drawBiasGraph Then
temporalUniqueUserIDCount.Clear()
For Each a As String In temporalUserOriginCountDictionary_Country.Keys.ToList()
temporalUserOriginCountDictionary_Country(a) = 0
Next
End If
Do While objReader.Peek() <> -1
line = line + 1
linetext = objReader.ReadLine()
'Dim t As New FileIO.TextFieldParser(New System.IO.StringReader("thestringinside"))
'we'll split data up to the first position where Quotes might ocur (title, content)
linetextArr = Split(linetext, ",", DSMapping.nonQuotedColumns)
If DataFiltering = True And (SearchDesc1 = True Or SearchTitle1 = True) AndAlso (linetextArr.Length >= DSMapping.nonQuotedColumns - 1) AndAlso Not linetextArr(DSMapping.nonQuotedColumns - 1) = "" Then
'It requires about 10x computing to split quoted fields, we only do this if really necessary
'We'll use TextFieldParser to get the fields after 13, if user searches for specific terms
Dim linetextArr2 As String()
Using fieldReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(New System.IO.StringReader(linetextArr(DSMapping.nonQuotedColumns - 1)))
'MsgBox(linetextArr(DSMapping.nonQuotedColumns - 1))
fieldReader.TextFieldType = FileIO.FieldType.Delimited
fieldReader.SetDelimiters(DSMapping.delimiter)
fieldReader.HasFieldsEnclosedInQuotes = True
fieldReader.TrimWhiteSpace = True
'we do not need to read all data into fields, only what is required
While Not fieldReader.EndOfData
linetextArr2 = fieldReader.ReadFields()
End While
End Using
linetextArr = linetextArr.Concat(linetextArr).ToArray()
End If
'we need at least 11 columns, otherwise skip the row
If linetextArr.Length >= DSMapping.tags_colNr Then
If DSMapping.name = "lbsn" Then sourceID = Val(linetextArr(DSMapping.origin_id_colNr)) 'ID
resultLat = Val(linetextArr(DSMapping.latitude_colNr)) 'Lat
resultLng = Val(linetextArr(DSMapping.longitude_colNr)) 'Long
If DSMapping.name = "lbsn" And sourceID = 1 Then
PhotoIDc = linetextArr(DSMapping.post_url_colNr).Substring(linetextArr(DSMapping.post_url_colNr).LastIndexOf("/"c) + 1) 'PhotoShortcode
Else
PhotoIDc = linetextArr(DSMapping.post_guid_colNr) 'PhotoID
End If
UserIDc = linetextArr(DSMapping.user_guid_colNr) 'UserID (String!)
If timetransponse Then
If DSMapping.name = "flickr" Then
PDate = DateTime.Parse(linetextArr(DSMapping.post_create_date_colNr))
ElseIf DSMapping.name = "lbsn" Then
PDate = DateTime.Parse(linetextArr(DSMapping.post_publish_date_colNr))
End If
End If
If photocollection Then
If IsNothing(DSMapping.post_view_count_colNr) Or sourceID = 1 Then
Views = Val(linetextArr(DSMapping.post_like_count_colNr))
Else
Views = Val(linetextArr(DSMapping.post_view_count_colNr)) 'Views
End If
PhotoURL = linetextArr(DSMapping.post_thumbnail_url_colNr) 'URL
End If
If linetextArr.Length < 14 Then
'Unselect if no data exists
SearchDesc1 = False
SearchDesc2 = False
SearchDesc3 = False
End If