Click here to Skip to main content
15,896,492 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I urgently need a VERY small, VERY simple vb.net program to get the longitude, latitude and altitude from all JPGs in a folder, and then export them all to a csv file.

I could not get exifworks to work correctly, maybe someone can fix and simplyfy it?

I just need to extract 3 properties from an image file. I assumed that it would be very simple for an experienced person. My problem is that I am a beginner.

regards,
Jozi68
Posted
Updated 8-Feb-11 3:46am
v3
Comments
Sandeep Mewara 8-Feb-11 9:34am    
Share what you have tried, surely someone would help.
Jozi68 9-Feb-11 5:52am    
I think I got it right. Code is pasted below. However, I don't know how to interpret the altitude. I get an answer of 56844, and it should be: 1386.439.
Also, my string is being concatenated, I'm not sure why.

[ Dim byte_property_id As Byte()
Dim EorW As String
Dim NorS As String
Dim prop_type As String
Dim TheImageUsed As System.Drawing.Bitmap
Dim PropertyIDarray() As Integer
Dim TheProperty As Integer
Dim counter As Integer
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
Dim Altitude As Double
Dim LAT As String
Dim LON As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim TheString As String

TheString = readProps("c:\tmp\IMG_0090_____test.jpg")

MsgBox(TheString)

End Sub

Public Function readProps(ByVal TheJPG As String) As String

Dim TheString As String

TheImageUsed = New System.Drawing.Bitmap(TheJPG)
PropertyIDarray = TheImageUsed.PropertyIdList
For Each Me.TheProperty In PropertyIDarray
counter = counter + 1
byte_property_id = TheImageUsed.GetPropertyItem(TheProperty).Value
prop_type = TheImageUsed.GetPropertyItem(TheProperty).Type
If TheProperty = 1 Then
'Latitude North or South
NorS = System.Text.Encoding.ASCII.GetString(byte_property_id)
ElseIf TheProperty = 2 Then
'Latitude degrees minutes and seconds (rational)
degrees = System.BitConverter.ToInt32(byte_property_id, 0) / System.BitConverter.ToInt32(byte_property_id, 4)
minutes = System.BitConverter.ToInt32(byte_property_id, 8) / System.BitConverter.ToInt32(byte_property_id, 12)
seconds = minutes - Int(minutes)
minutes = Int(minutes)
seconds = 60 * seconds
LAT = CStr(degrees) & "d " & CStr(minutes) & ":" & CStr(Int(seconds))
ElseIf TheProperty = 3 Then
'Longitude East or West
EorW = System.Text.Encoding.ASCII.GetString(byte_property_id)
ElseIf TheProperty = 4 Then
'Longitude degrees minutes and seconds (rational)
degrees = System.BitConverter.ToInt32(byte_property_id, 0) / System.BitConverter.ToInt32(byte_property_id, 4)
minutes = System.BitConverter.ToInt32(byte_property_id, 8) / System.BitConverter.ToInt32(byte_property_id, 12)
seconds = minutes - Int(minutes)
minutes = Int(minutes)
seconds = 60 * seconds
LON = CStr(degrees) & "d " & CStr(minutes) & ":" & CStr(Int(seconds))
ElseIf TheProperty = 6 Then
Altitude = System.BitConverter.ToInt32(byte_property_id, 0)
End If

Next TheProperty

TheString = (LAT + " " + NorS + " " + LON + " " + EorW + " " + CStr(Altitude))

Return TheString

End Function]

I have an Exif reader class here on CP:

An extensible ExifReader class with customizable tag handlers[^]

All the sample code is in C#, but you should be able to easily write a VB app that will get just the longitude/latitude properties out of your images.
 
Share this answer
 
Comments
Jozi68 8-Feb-11 10:04am    
Thanx Nishant for your reply, I can unfortunately not open your project file, perhaps because I am using VS2005?
Nish Nishant 8-Feb-11 10:08am    
Yeah, unfortunately you will need VS 2010.

Or you can add the source files manually to a new VS 2005 C# library project and then see if you can build that.

Another option would be to download Visual C# 2010 Express.
Jozi68 9-Feb-11 3:04am    
I downloaded Visual C# 2010 and ran your project. I can see that a lot of work went into it; and it works beautifully. Unfortunately my vb.net skills are limited, and my c# skills are non-existent. I spent a lot of time trying to figure out how it works, but without success.
Thank you very much anyway, I appreciate you're willingness to help.
Nish Nishant 9-Feb-11 8:51am    
Ok, I was hoping you'd just be able to access my compiled DLL from your VB code. It would only have been 5-6 lines of code. Too bad, and good luck with your project.
Sergey Alexandrovich Kryukov 8-Feb-11 16:41pm    
Very useful, I voted to the article as well.
--SA
You will likely not find anyone that will write code for you on this site, at least not for free, and certainly not without payment up front. Hire a programmer if your need is that urgent, and you can't do it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Feb-11 16:39pm    
Tell the, tell... a 5,
--SA
Jozi68 9-Feb-11 3:06am    
Did you assume that I expect someone to write the entire application for me?
Did you perhaps vote based on that assumption?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900