Sub AddImagesToJourney(iJourney_ID As Int, strFolder As String)
Dim i As Int
Dim n As Int
Dim strSQL As String
Dim strSQL2 As String
Dim dMinDistance As Double
Dim dLowestDistance As Double
Dim oRS As ResultSet
Dim oRS2 As ResultSet
Dim oRS3 As ResultSet
Dim lstFilesFolders As List
Dim lstFiles As List
Dim strFile As String
Dim mapImageFilesInJourney As Map
Dim arrLatLng(2) As Float
Dim arrSplitString() As String
Dim lDateTime As Long
lstFilesFolders.Initialize
lstFiles.Initialize
mapImageFilesInJourney.Initialize
strSQL = "select min(latitude), min(longitude), max(latitude), max(longitude) from journey_recordings where journey_id = ? and not latitude is null and not longitude is null"
oRS = cMP.cConn.SQLNon_Clinical.ExecQuery2(strSQL, Array As String(iJourney_ID))
oRS.Position = 0
strSQL = "select image_file from journey_recordings where journey_id = ? and not image_file is null"
oRS2 = cMP.cConn.SQLNon_Clinical.ExecQuery2(strSQL, Array As String(iJourney_ID))
Do While oRS2.NextRow
mapImageFilesInJourney.Put(oRS2.GetString2(0), 0)
Loop
If strFolder.Length = 0 Then
strFolder = File.DirRootExternal & "/DCIM/Camera"
End If
'there are some 1282 pictures and videos in this folder
lstFilesFolders = File.ListFiles(strFolder)
For i = 0 To lstFilesFolders.Size - 1
strFile = lstFilesFolders.Get(i)
If File.IsDirectory(strFolder, strFile) = False Then
If strFile.EndsWith(".mp4") Or strFile.EndsWith(".jpg") Then
If strFile.StartsWith("20") Then
If cFunctions.CInt(strFile.SubString2(0, 4)) > 2025 Then
'As image files taken during the journey, can be matched on date-time data
'-------------------------------------------------------------------------
If mapImageFilesInJourney.ContainsKey(strFile) = False Then
lstFiles.Add(strFile)
End If
End If
End If
End If
End If
Next
If lstFiles.Size = 0 Then Return
strSQL = "select date_time, latitude, longitude from journey_recordings where journey_id = ?"
oRS3 = cMP.cConn.SQLNon_Clinical.ExecQuery2(strSQL, Array As String(iJourney_ID))
strSQL2 = "update journey_recordings set image_file = ? where journey_id = ? and date_time = ?"
For i = 0 To lstFiles.Size - 1
strFile = lstFiles.Get(i)
If strFile.EndsWith(".mp4") Then
Dim rs As ResumableSub = GetVideoLocation(File.Combine(strFolder, strFile))
Wait For (rs) Complete (strVideoLatLng As String)
If strVideoLatLng.SubString(1).Contains("-") Then
arrSplitString = Regex.Split("-", strVideoLatLng)
arrLatLng(0) = arrSplitString(0)
arrLatLng(1) = 0 - arrSplitString(1).SubString2(0, arrSplitString(1).Length - 2)
Else
arrSplitString = Regex.Split("+", strVideoLatLng)
arrLatLng(0) = arrSplitString(0)
arrLatLng(1) = arrSplitString(1).SubString2(0, arrSplitString(1).Length - 2)
End If
Else
Exif.Initialize(strFolder, strFile)
Exif.getLatLong(arrLatLng)
End If
If arrLatLng(0) > oRS.GetDouble2(0) Then
If arrLatLng(0) < oRS.GetDouble2(2) Then
If arrLatLng(1) > oRS.GetDouble2(1) Then
If arrLatLng(1) < oRS.GetDouble2(3) Then
oRS3.Position = -1
dMinDistance = 1000000
Do While oRS3.NextRow
Dim rs As ResumableSub = MapUtilities.DistVincenty2(oRS3.GetDouble2(1), oRS3.GetDouble2(2), arrLatLng(0), arrLatLng(1))
Wait For (rs) Complete (dDistance As Double)
If dDistance < dMinDistance Then
dMinDistance = dDistance
lDateTime = oRS3.GetLong2(0)
dLowestDistance = dDistance
End If
Loop
If dLowestDistance < 3 Then
n = n + 1
Log(strFile & ": dLowestDistance: " & dLowestDistance & ", lDateTime: " & lDateTime)
cMP.cConn.SQLNon_Clinical.ExecNonQuery2(strSQL2, Array As String(strFile, iJourney_ID, lDateTime))
End If
End If
End If
End If
End If
Next
Log("n: " & n)
End Sub