EXIF GPS properties - Dylan's Ride Blog

Some occasional musings on mountain bike rides and walks in North Yorkshire, with odd bit of discussion on mapping technology thrown in for good measure

EXIF GPS properties
24/04/2007

I'm parsing Exif data in images for ShareMyRoutes. I'd already written code to parse most of the well known properties, but could find out how to extract embedded lat/longs. Some cameras can add GPS location to photos, and post processing by applications like Picassa can add them. This is really useful, but I couldn't find an example. So, if anybody is having the same problem, here's a skeleton of how to extract these properties. Obviously, in the real world, you'd need to clean the code up, and check the values are populated, but for the sake of simplity this has been left out.

 

'which file to read

Dim FileName As String = "d:\temp\exif\PC300008.JPG"

 

GetBitmap =

 

 

Dim GetBitmap As System.Drawing.BitmapDirectCast(System.Drawing.Bitmap.FromFile(FileName), System.Drawing.Bitmap)Dim propItem As Drawing.Imaging.PropertyItemDim latSign, lonSign As String

 

Dim latitude, longitude As Decimal

propItem = GetBitmap.GetPropertyItem(1)

 

 

 

If propItem.Value Is DBNull.Value = False Then

 

 

Dim intlen = propItem.Value.LengthDim bytValue(intlen) As Byte

bytValue = propItem.Value

 

'get the sign for the lat

latSign = Trim(ByteToString(propItem.Value))

 

End If

propItem = GetBitmap.GetPropertyItem(2)

 

If propItem.Value Is DBNull.Value = False Then

 

 

Dim intlen = propItem.Value.LengthDim bytValue(intlen) As Byte

bytValue = propItem.Value

 

Dim latDD, latMM, latSS As Decimal

latDD = BitConverter.ToInt32(bytValue, 0)

latMM = BitConverter.ToInt32(bytValue, 8)

latSS = BitConverter.ToInt32(bytValue, 16) / 100

latitude = DDMMSStoDecDeg(lonDD, lonMM, lonSS, lonSign)

 

 

End If

propItem = GetBitmap.GetPropertyItem(3)

 

If propItem.Value Is DBNull.Value = False Then

 

 

Dim intlen = propItem.Value.LengthDim bytValue(intlen) As Byte

bytValue = propItem.Value

 

'get the sign for the lat

lonSign = Trim(ByteToString(propItem.Value))

 

End If

propItem = GetBitmap.GetPropertyItem(4)

 

If propItem.Value Is DBNull.Value = False Then

 

 

Dim intlen = propItem.Value.LengthDim bytValue(intlen) As Byte

bytValue = propItem.Value

 

 

Dim lonDD, lonMM, lonSS As Decimal

lonDD = BitConverter.ToInt32(bytValue, 0)

lonMM = BitConverter.ToInt32(bytValue, 8)

lonSS = BitConverter.ToInt32(bytValue, 16) / 100

longitude =

 

 

 

 

 DDMMSStoDecDeg(lonDD, lonMM, lonSS, lonSign)End IfEnd Sub

Private Function DDMMSStoDecDeg(ByVal DD As Decimal, ByVal MM As Decimal, ByVal SS As Decimal, ByVal sign As String) As Decimal

 

Dim decDeg As Decimal

decDeg = ((SS / 3600) + (MM / 60) + DD)

 

If sign = "E" Or sign = "S" Then

decDeg = decDeg * -1

 

End If

 

 

 

Return decDegEnd Function

private sub ReadGPSdata

Comments

Post a comment

Sorry, comments on this posting are now closed.