How to Convert Your Photo Library to PhotoKML for Easy Mapping

How to Convert Your Photo Library to PhotoKML for Easy Mapping

Mapping your photos with PhotoKML makes it simple to visualize where images were taken, share location-based albums, or import into mapping tools like Google Earth. This guide walks through a clear, prescriptive workflow to convert a photo library (local or cloud) into PhotoKML files ready for mapping.

What you’ll need

  • A photo library (local folders or exported from cloud services).
  • Photos with GPS metadata (EXIF). If some images lack GPS, see step 2.
  • A computer (Windows, macOS, or Linux).
  • One of these tools:
    • ExifTool (free, command-line) — extract and write metadata.
    • GeoSetter (Windows, GUI) or GeoTag (macOS) — optionally add/adjust geotags.
    • PhotoKML converter script or KML creator (instructions below use a simple Python script).
  • Google Earth or any KML-compatible map viewer for final review.

Step 1 — Export or gather photos

  1. For cloud libraries (Google Photos, iCloud, Dropbox): export photos to a local folder with metadata preserved. Use the service’s export feature; ensure “include metadata” is enabled.
  2. For local libraries (Photos app, Lightroom): export originals or copies with metadata preserved. In Lightroom, choose “Original” or include metadata in export settings.

Step 2 — Ensure GPS metadata is present

  • Check a sample photo’s EXIF metadata:
    • On macOS: Preview → Tools → Show Inspector → GPS.
    • On Windows: Right-click → Properties → Details → GPS.
    • Or run:

    bash

    exiftool IMG1234.jpg
  • If GPS data is missing:
    • If you have a GPX track from your phone/trip, you can batch-match timestamps with tools (GeoSetter, or ExifTool with –geotag).
    • Manually add locations using GeoSetter (Windows) or a GUI geotagger on macOS.
    • For few photos, manually drop pins in Google Earth and note coordinates.

Step 3 — Normalize timestamps (if using GPX matching)

  • Ensure camera clocks match phone/GPS device times (account for time zone and daylight savings).
  • If needed, compute an offset and apply with ExifTool:

bash

exiftool ”-alldates+=00:00:30” -r /path/to/photos

(Adjust the offset format as hh:mm:ss.)

Step 4 — Create PhotoKML entries

Use the Python script below to generate a KML file that references your photos. Save as makephotokml.py and run it from the directory containing your photos or point it to the folder.

python

#!/usr/bin/env python3 # make_photokml.py — simple PhotoKML generator import os import sys from xml.sax.saxutils import escape import subprocess import json def get_exif(filepath): try: out = subprocess.check_output([‘exiftool’, ’-j’, ’-GPSLatitude’, ’-GPSLongitude’, ’-Title’, filepath], stderr=subprocess.DEVNULL) data = json.loads(out)[0] lat = data.get(‘GPSLatitude’) lon = data.get(‘GPSLongitude’) title = data.get(‘Title’) or os.path.basename(filepath) return lat, lon, title except Exception: return None, None, os.path.basename(filepath) def to_decimal(gps): if gps is None: return None # exiftool returns decimal degrees or like “12 deg 34’ 56.00” N” try: return float(gps) except: # crude parser for D M S format parts = gps.replace(‘deg’,).replace(”‘”,).replace(’”’,).split() if len(parts) >= 3: d,m,s = parts[:3] return float(d) + float(m)/60 + float(s)/3600 return None def build_kml(entries, outname=‘photos.kml’): header = ”‘<?xml version=“1.0” encoding=“UTF-8”?> PhotoKML”’ footer = ‘’ placemarks = [] for lat,lon,title,href in entries: if lat is None or lon is None: continue pm = f”’ {escape(title)} <![CDATA[{escape(href)}” width=“640”/>]]> {lon},{lat},0 ”’ placemarks.append(pm) with open(outname,‘w’,encoding=‘utf-8’) as f: f.write(header + ’ ‘.join(placemarks) + footer) print(“Wrote”, outname) def main(folder): files = [f for f in os.listdir(folder) if f.lower().endswith((’.jpg’,’.jpeg’,’.png’))] entries = [] for fn in files: path = os.path.join(folder,fn) lat,lon,title = get_exif(path) lat = to_decimal(lat); lon = to_decimal(lon) entries.append((lat,lon,title,fn)) build_kml(entries) if name == main: folder = sys.argv[1] if len(sys.argv)>1 else ’.’ main(folder)
  • Requirements: exiftool installed and on PATH. The script embeds image filenames as relative links—if you later move photos, update paths accordingly.

Step 5 — Host photos or use embedded thumbnails

  • For Google Earth desktop, local relative paths work. For web-based viewers, host images on a web server or cloud (same folder structure) and edit the KML to use full HTTPS URLs in the src.
  • Optionally create small thumbnails and reference those in the KML to speed loading.

Step 6 — Load and review in Google Earth

  1. Open Google Earth Pro or Google Earth Web.
  2. Import the generated KML/KMZ.
  3. Check placemark positions and click thumbnails to confirm images display correctly. Adjust any incorrect geotags and regenerate if needed.

Step 7 — Package as KMZ (optional)

  • KMZ is a zipped KML plus image files for portability.
  • On macOS/Linux:

bash

zip -r photos.kmz photos.kml *.jpg *.png
  • On Windows: select files, Send to → Compressed (zipped) folder, rename .zip to .kmz.

Tips & best practices

  • Backup originals before batch editing EXIF.
  • Use thumbnails for large libraries to avoid heavy KMZ files.
  • Include useful placemark names (date, location) in EXIF Title or use a CSV-to-KML step for richer metadata.
  • For automated recurring exports, script the process and include timestamp normalization.

If you’d like, I can generate a tailored script for Windows-only, macOS-only, or a version that uploads images to a cloud host and outputs HTTPS links for web KML.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *