2
\$\begingroup\$

I'm working on GeoTagger, a tool for geotagging photos based on the user's GPS position in the time of taking the photo (currently it uses GPS data from https://www.moves-app.com/).

The process involves adding EXIF GPS metadata to photo files.

One of the problems I'm having is with Lightroom: when the metadata of photos that have been imported to a Lightroom catalog are modified from the outside, then Lightroom offers only two options:

  1. To replace the catalog metadata by re-importing all metadata from the file (thereby losing any edits made to the photo in Lightroom).
  2. To override the file's metadata with the version cached in Lightroom (thereby removing the added tags).

I need a third option: make it so that the externally added/modified tags are added to Lightroom catalog without messing with any of the existing ones. Or a reliable/documented way to update the catalog directly. Is this possible to achieve?

\$\endgroup\$
6
  • \$\begingroup\$ As lightroom uses an SQLite database, you can probably edit it directly with an SQLite editor but that sounds a lot geeky. \$\endgroup\$
    – Olivier
    Commented Aug 12, 2016 at 10:08
  • \$\begingroup\$ This might be the only option. Do you know if there's some documentation for the database scheme LR uses? \$\endgroup\$ Commented Aug 12, 2016 at 10:10
  • 1
    \$\begingroup\$ Jeffrey Friedl has plenty of usefull tools : regex.info/blog/lightroom-goodies \$\endgroup\$
    – Olivier
    Commented Aug 12, 2016 at 10:20
  • \$\begingroup\$ Thanks! I know my way around SQLite, but am wondering if the direct in-DB manipulation is at least semi-supported and documented. \$\endgroup\$ Commented Aug 12, 2016 at 10:25
  • 1
    \$\begingroup\$ If you save your edits into sidecar files (which is a good idea anyway), they will not get lost. You remove the file from LR catalog, and add it back; LR will read the new metadata, and apply the edits from the sidecar file. Note though that some metadata affects the edit results - like lens used -> corrections applied; etc. \$\endgroup\$
    – Aganju
    Commented Aug 12, 2016 at 11:52

5 Answers 5

2
\$\begingroup\$

If you change the LR settings to save your edits into sidecar files (which is a good idea anyway), they will not get lost.

  1. You remove the file from LR catalog, then
  2. add it back; LR will read the new metadata, and apply the edits from the sidecar file.

Note though that some metadata affects the edit results - like lens used -> corrections applied; etc.

\$\endgroup\$
2
\$\begingroup\$

The Save Metadata to Files / Read Metadata from File functions will do what you require.

Lightroom provides a facility for writing library metadata out to XMP files alongside the original images, so it ought to be possible to write your program to look at those sidecar files and edit the existing data.

Metadata can be written out to files using the intuitively-named "Save Metadata to Files" command in the Metadata menu. The resulting XMP file is external to both the library as well as the original image's internal metadata. Individual XMP fields can then be manipulated programmatically (e.g. the exif:GPSLatitude field). This avoids overwriting current metadata with old metadata at any point, and will also preserve edits made to the images in Lightroom as well as any metadata that was manually entered in the library. After editing the XMP, Lightroom can read the changes back into the library with the menu item "Read Metadata from File".

Caveat 1: Saving the library metadata out to the XMP file will overwrite an existing file in the same location. This is a good thing. This means that there isn't an easy way to have two sets of metadata in different states. As a programmer, having two metadata states may be handy for some fun tricks, but as a photographer I can personally say that I would much rather have the peace of mind that there only exists one state.

Caveat 2: The Lightroom API (as of ver. 6) does not appear to provide a convenient way of saving the current library metadata out to files before operating on them, nor a way of reading new metadata into the library when your program finishes. This means that there is no simple way to programmatically guarantee that your code will be operating on metadata files which share their state with the metadata in the Lightroom catalog. My impression is that this is a safeguard to keep Lightroom's library metadata state at the top of the hierarchy, as for many users the library will represent the authoritative state of the data.

The workaround: You may need to resign yourself to asking the user to manually save out the metadata before your program runs, and instructing the user to read in the updated metadata after completion. I am not a LR plugin programmer myself, but I have used several plugins which use this pattern, so it may well be what is necessary. Luckily this isn't a huge hassle in normal use, as the menu items "Save Metadata to File" and "Read Metadata from Files" are only one click away in the Metadata menu, and will probably just be used once after selecting all of the images to be included in the operation.

\$\endgroup\$
1
\$\begingroup\$

I don't know a direct way to do so.

You can look at Jeffrey Friedl's tools, maybe some might help you : http://regex.info/blog/lightroom-goodies.

If you like your code, take a look at the SDK guide from Adobe :

\$\endgroup\$
1
\$\begingroup\$

Can't you do this via LR-5's Map module?

Click "Map" , then in the footer bar of the map module: click the icon with the zig-zag line, then click "Load Tracklog", Load your GPX file, correct any time-zone offset, click "Auto-tag selected photos". (These are all context menu items of the Zig-Zag Icon)

Another, more laborious alternative is to import the files twice, into different folders. Then, in the Map module, in the film strip, click the photo that contains GPS data to be imported, then click those photos lacking these GPS metadata, then click "Sync Metadata...", click checkboxes for the GPS coordinates. Optionally, delete photos from the second folder, now unneeded.

I don't know if this covers your requirements (I am aware of your question being more general), but maybe it still helps.

\$\endgroup\$
1
  • \$\begingroup\$ Super helpful, thanks @knb. I actually didn't know that Lightroom works with GPX. The Sync Metadata feature also sounds interesting. \$\endgroup\$ Commented Aug 14, 2016 at 10:26
1
\$\begingroup\$

For Geotagging specifically, if you first add the geotags, then import into LR, LR will retain the data and incorporate it. If you attempt to change the data after importing, LR tends to complain.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.