Reputation: 5761
I'm writing some image processing code, and I'm pulling out the GPS coordinates, however they are in some sort of integer array that I can't figure out how to convert to Degree/Minute/Second or Decimal form.
Lat: (38,0,0,0,1,0,0,0,54,0,0,0,1,0,0,0,168,73,5,0,16,39,0,0)
Lng: (77,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,60,122,0,0,16,39,0,0)
According to windows the D/M/S version of this is:
VB.NET code would be most helpful but I could probably convert it from any language.
Upvotes: 3
Views: 2518
Reputation: 20838
Here is code that works in C# using .NET calls (should be trivial to do in VB)
Double deg = (Double)BitConverter.ToInt32(data,0)/ BitConverter.ToInt32(data,4);
Double min = (Double)BitConverter.ToInt32(data,8)/ BitConverter.ToInt32(data,12);
Double sec = (Double)BitConverter.ToInt32(data,16)/ BitConverter.ToInt32(data,20);
The format is documented here http://en.wikipedia.org/wiki/Geotagging
Upvotes: 3
Reputation: 104
The arrays are laid out in the follow form:
bytes(0 -> 3) / bytes(4 -> 7) = degree
(bytes(8 -> 11) / bytes(12 -> 15)) / 60= minute
(bytes(16 -> 19) / bytes(20 -> 23)) / 3600 = second
*Note - Each byte(x -> y)
quantity is the summation of the range.
The below will decode the given lat array into a decimal form.
Dim coord(5) As Decimal
Dim j As Integer = 0
Dim coordinate As Decimal
For i As Integer = 0 To lat.Length - 1
coord(j) = coord(j) + lat(i)
'If i is a multiple of 4, goto the next index
If ((i + 1) Mod 4 = 0) And i <> 0 Then
j += 1
End If
Next
coordinate = (coord(0) / coord(1)) + ((coord(2) / coord(3))) / 60 + ((coord(4) / coord(5)) / 3600)
Just change the referenced array to decode lng.
Upvotes: 0