# Plugin to export waypoints from georeferenced photos?



## rob211 (May 14, 2015)

I know that ExifTool can *extract* GPS information from a geolocated image and write it to a .gpx or .kml file. IOW, export a waypoint from an image or a route from a series of images.

Is there a plugin for Lr than does this? I suppose I could use the plugin for running ExifTool, but since my ExifTool expertise is rather limited, I thought perhaps someone had produced something similar, or something that could export a track from a series of images.


----------



## johnbeardy (May 14, 2015)

Not that I know of. Technically it's not that difficult.


----------



## rob211 (May 14, 2015)

Yeah, I'll try using your plugin I'm demo'ing to do it. The track construction is a tougher nut, but somebody somewhere has probably done it, or I could use one of my nav apps to just construct it out of a set of waypoints. Thanks


----------



## johnbeardy (May 14, 2015)

My plugin? The Capture Time to Exif one won't help - though it might help you develop more Exiftools skills.

I wouldn't be surprised if someone has done something, though I've never seen anyone doing anything like that. LR certainly exposes the GPS data to the SDK (API) which has a good XML generating capability, and I recently did some work on importing KML and GPX tracklogs into LR, so if I had a few hours I could probably knock something together. If I had a few hours though....

John


----------



## rob211 (May 14, 2015)

It will be a good exercise in learning exiftool for me. I haven't figured out if there's a standard way to reference a photo in a waypoint either, although I can see where a URL could be added. I think the geocache people use photo waypoints in one form or another, maybe through KML though. I'll check around.


----------



## johnbeardy (May 15, 2015)

OK, it didn't take me as long as I feared, and I learnt a couple of tricks too.

So the following code creates a GPX file on your desktop called selections.gpx with trackpoints for each selected photo which has GPS data (ignoring those with no GPS). The big question is whether the GPX file can be parsed by whatever you're using to read it, and while I tested it by reading it back into LR Map, it'll probably need the odd tweak.

BTW do you know of http://regex.info/blog/lightroom-goodies/gps ?

John



```
--[[

Creates a GPX file on the desktop

SETUP INSTRUCTIONS
Use Notepad or textEdit and temporarily save this file onto your desktop and call it "KML from selected photos.lua".

Now you need to create a scripts folder:
    In Lightroom, choose Lightroom > Preferences (Mac OS) or Edit > Preferences (Windows).
    Choose the Preset tab and select Show Lightroom Presets folder.
    Create a folder in the Lightroom folder called Scripts.
    Copy the "Title case keywords.lua" script into the Scripts folder.
    Quit and reopen Lightroom. 
You should now see a little scripts menu to the right of the Help menu. It has a single item Title case keywords.
--]]

local LrPathUtils = import 'LrPathUtils'
local LrXml = import 'LrXml'    
local LrTasks = import 'LrTasks'
LrProgressScope = import 'LrProgressScope'
local progressTitle = "Saving XML file to Collection"


local SEP 
if MAC_ENV then SEP = '/' else SEP = '\\' end
xmlFileStr = LrPathUtils.getStandardFilePath( 'desktop' ) ..SEP..  'selections.gpx'    
local xmlBuilder = LrXml.createXmlBuilder(false) -- true to omit XML declaration

function WriteLog (  txt)
        Hnd = io.open(xmlFileStr, "a")
        Hnd:write (txt  .. '\n')
        Hnd:close ()        
end
 

LrTasks.startAsyncTask( function()    
    local catalog = import "LrApplication".activeCatalog()    
    photos = catalog:getTargetPhotos()    
    myProgressScope = LrProgressScope ({title  = progressTitle, caption = "Saving selection file" })        
    gpxAttrs =  {version="1.1",  
            creator="John Beardsworth's GPX from selected photos.lua",
            xmlns="http://www.topografix.com/GPX/1/1"
            }
    xmlBuilder:beginBlock('gpx' , gpxAttrs  )        
    xmlBuilder:beginBlock('trk' )    
    xmlBuilder:beginBlock('trkseg' )    
    for i, photo in ipairs(photos ) do 
        myProgressScope:setCaption ("Saving file "  ..  i .. " / "..  #photos   )
        myProgressScope:setPortionComplete( i /#photos)        
        local gps  = photo:getRawMetadata("gps")
        if gps ~= nil then
        xmlBuilder:beginBlock('trkpt' , {lat=gps.latitude, lon=gps.longitude}  )        
        xmlBuilder:endBlock('trkpt')
        end
    end
    myProgressScope:done()    
    xmlBuilder:endBlock('trkseg')
    xmlBuilder:endBlock('trk')
    xmlBuilder:endBlock('gpx')
    xmlString = xmlBuilder:serialize()
    
    xmlFile = io.open(xmlFileStr , "w")        
    WriteLog (xmlString)                            
    xmlFile:close ()    
end)
```


----------



## rob211 (May 15, 2015)

That rocks! Thank you SO much.

Now I just gotta title my photos so that I can transfer that to the waypoints (I seem to recall there may be character limits, etc). It might work better as different waypoints, though, rather than as a track. I dunno, I didn't think it through before, and consider the sequence of the waypoints. The track that Garmin Basecamp showed with three waypoints looked to be the sequence of my choice of pictures, which usually works. Just do a custom rearrangement of the photos in the order you wish to travel, and bam, you've got it. I'm kinda surprised no one has done an application that does this, considering that there are lots of geotagging applications already. Maybe I just missed 'em. Adding titles for waypoint names will work, although maybe not for points on a route.

This worked in Garmin Basecamp, as noted, and also in Google Earth. So thanks again. Do you mind if I share this with some folks?


----------



## johnbeardy (May 15, 2015)

Feel free, but maybe wait a while - there's bound to be a bug in it, or something we hadn't thought of including.


----------



## rob211 (May 15, 2015)

johnbeardy said:


> Feel free, but maybe wait a while - there's bound to be a bug in it, or something we hadn't thought of including.



Maybe that's why I wanted to share it...


----------



## johnbeardy (May 16, 2015)

Anyway, feel free.


----------

