' --------------------------------------------------------------- ' This script extracts XMP GPS coordinates and ' creates a Google Earth KML file from the information ' found in the EXIF data. ' ' Search for @User to find the places in the script where YOU ' have to change something. ' --------------------------------------------------------------- Option Explicit ' @User: Change this to match the install location of Google Earth on your machine Const GE_PATHANDFILENAME = "C:\Program Files\Google\Google Earth\GoogleEarth.exe" ' This is the template used to create the KML file Const KML_TEMPLATE_HEADER = "" + _ "" + vbNewLine + _ "" + vbNewLine + _ "" + vbNewLine + _ " KML File produced by photools.com IMatch"+ vbNewLine + _ " #MYPLACEMARK" + vbNewLine + _ ""+ vbNewLine + _ "" + vbNewLine Const KML_TEMPLATE_LOCATION = "" + _ " "+ vbNewLine + _ " #NAME#"+ vbNewLine + _ " #DESC#"+ vbNewLine + _ " "+ vbNewLine + _ " #LONG#,#LAT#,#ALT#"+ vbNewLine + _ " "+ vbNewLine + _ " "+ vbNewLine ' @User: Here you can control what GE shows as the name and the description of the placemark Const NAME_TEMPLATE = "{Image.Name}" Const DESC_TEMPLATE = "Image Location{Image.Name}" + _ "Date and Time{Image.XMP.http://ns.adobe.com/exif/1.0/exif:DateTimeOriginal}" + _ "
" Sub Main ' Hier worden alle variabelen geïnitialiseerd Dim db As Database Set db = Application.ActiveDatabase ' Decalaratie van variabele met de huidige selectie Dim iset As Images Set iset = db.ActiveSelection ' declaratie van de overige variabelen Dim i As Image Dim clong As String Dim clat As String Dim calt As String Dim klmTotal As String Dim counter As Integer counter = 0 ' Open een dialoogvenster en vraag info van de gebruiker Begin Dialog UserDialog 610,238,"Google Earth (TM) KML File Generator" ' %GRID:10,7,1,1 Text 20,7,580,35,"This script uses the GPS data contained in the XMP record for your image to produce a Google Earth KML file. The script then launches Google Earth and displays the placemark.",.Text1 OKButton 350,203,110,21 CancelButton 470,203,110,21 OptionGroup .GroupType OptionButton 20,56,310,14,"Create a temporary KML file",.RadioTTemp OptionButton 20,77,580,14,"Create a KML file with the name of the image file and in the same folder as the image ",.RadioTPersistent CheckBox 20,112,500,14,"Launch Google Earth",.CheckLaunch Text 20,140,580,42,"Note: Make sure the script has been updated to use the folder and file name where Google Earth is installed on your computer.",.Text2 End Dialog Dim dlg As UserDialog ' toon het dialoogvenster dlg.GroupType = 0 dlg.CheckLaunch = 1 If Dialog(dlg) >= 0 Then Exit Sub End If ' hier overlopen we alle namen in het programma For Each i In iset ' haal hoogte, lengte - en breedtegraad uit het programma calt = db.ParseVariables("{Image.GPS.Altitude}",i) clong = db.ParseVariables("{Image.GPS.Longitude}",i) clat = db.ParseVariables("{Image.GPS.Latitude}",i) ' toon de info op het scherm Debug.Print i.FileName & ": " & clong & ", " & clat & ", " & calt If (clong <> "") And (clat <> "") Then ' Make sure we have GPS data counter = counter + 1 ' haal de template op, vervang hierin de LAT, LONG en ALT Dim kml As String kml = KML_TEMPLATE_LOCATION kml = Replace(kml,"#LONG#",clong) kml = Replace(kml,"#LAT#",clat) kml = Replace(kml,"#ALT#",calt) ' Replace the #NAME# tag in the template Dim fname As String fname = "" fname = db.ParseVariables(fname,i) kml = Replace(kml,"#NAME#",fname) ' Replace the #DESC# tag in the template Dim desc As String desc = "" desc = desc + DESC_TEMPLATE desc = desc + "


" desc = desc + "Created with photools.com IMatch desc = desc + "" desc = desc + "]]>" desc = db.ParseVariables(desc,i) kml = Replace(kml,"#DESC#",desc) klmTotal = klmTotal & vbNewLine & kml & vbNewLine End If Next i If counter > 0 Then Dim outputname As String If dlg.GroupType = 0 Then ' Use a temporary file name outputname = Environ("TEMP")+"\imatch.kml" Else ' Create a static KML file in the same folder as the image file Dim t2() As String t2 = Split(i.FileName,".") If UBound(t2) > 0 Then outputname = t2(0) & ".kml" Else outputname = i.FileName + ".kml" End If End If Dim theFile As String theFile = Replace(KML_TEMPLATE_HEADER, "#MYPLACEMARK",klmTotal) Open outputname For Output As #1 Print #1,theFile Close #1 If dlg.CheckLaunch = 1 Then Application.ShellExecute "open",GE_PATHANDFILENAME,""""+outputname+"""" End If Else MsgBox "None of the files had GPS data in them!" End If End Sub