stag and sgeo: turn a folder of photos into a CSV of GPS points and a map

stag and sgeo: turn a folder of photos into a CSV of GPS points and a map

sfile can already read the GPS out of your photos — the geotagging decoders landed in commit b368998 (EXIF GPS, XMP, QuickTime, GeoTIFF, EXR, PSD, CR3; 26 of 26 fixtures pass, cross-checked against exiftool 13.50). Two new tools sit on top of that decoder and answer the next two questions: where was everything taken? and show me on a map.

stag scans a directory and writes one CSV row per file: filename, format, latitude, longitude, altitude, datum, timestamp, and which decoder found it. sgeo takes the same directory and plots every point on an OpenStreetMap image, with the OSM attribution drawn on the image itself.

Build

git clone https://github.com/cnmcdee/sfile
cd sfile
make all        # sfile + scar
make stag sgeo  # needs libpng and libcurl dev packages

Both tools are in the repo now (commit 3f72568 added them, with docs in docs/stag-sgeo.md); the decoders they depend on landed after them in b368998, so a fresh clone builds everything with no caveats.

stag: a folder of photos in, a CSV out

$ stag photos/ geotags.csv
stag: 4 file(s), 4 geotagged -> geotags.csv

Real output from a test run over four JPEGs with EXIF GPS (San Francisco, Tokyo, Paris, New York):

file,format,latitude,longitude,altitude,datum,timestamp,source
nyc.jpg,JPEG image,40.712800,-74.006000,10.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
paris.jpg,JPEG image,48.856600,2.352200,0.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
sf.jpg,JPEG image,37.774929,-122.419418,12.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
tokyo.jpg,JPEG image,35.676200,139.650300,0.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)

Coordinates are decimal degrees, datum is WGS-84, timestamps are ISO YYYY-MM-DD HH:MM:SS. Files with no GPS still get a row, with the coordinate fields left empty, so the CSV stays a faithful inventory of the directory. With no output file given, stag writes geotags.csv in the current directory. It finds the sfile binary via $SFILE, then PATH, then alongside itself.

sgeo: the same folder as a map

$ sgeo photos/ map.png
sgeo: 4 file(s), 4 geotagged, zoom 2, 1024x256, 4 tile(s) -> map.png

The same four photos, plotted on real OpenStreetMap tiles:

World map with four markers: San Francisco, New York, Paris and Tokyo, plotted by sgeo on OpenStreetMap tiles
Four geotagged photos plotted by sgeo — San Francisco, New York, Paris, Tokyo — on OpenStreetMap tiles, zoom 2. The attribution plaque is drawn on the image by sgeo itself.

sgeo picks a zoom level that fits all the points, fetches the tiles from tile.openstreetmap.org with libcurl, stitches them with libpng, and draws a marker per file plus the attribution plaque the OSM licence requires. A single point gives a zoomed-in map of just that place; a folder with no geotagged files exits non-zero and writes no file, instead of handing you a blank map.

How it works, and the honest limits

Both tools share a small client (src/geotag_client.c) that runs sfile on each file and parses the Geotagging: block out of its output — the decoders do the hard work, stag and sgeo are just tabulation and plotting. The test suite (tests/run_tests.sh) covers the multi-file directory, a single point, a no-geotag directory, an empty directory, and the default output filenames, using a local fake tile server so the tests run offline; the map above was produced the same way but against the live tile server.

Limits worth knowing: sgeo needs the network at run time unless you point $SGEO_TILE_BASE at a local tile server, and it fetches from the public OSM tile server, so don’t hammer it — cache tiles if you’re mapping thousands of photos. stag only reports what the decoders can read; a format with no geotagging support in sfile yet simply yields an empty row.

Source and full docs: github.com/cnmcdee/sfile — see docs/stag-sgeo.md and the stag/sgeo section of the README.

Linux Rocks Every Day
Decode any of these formats with sfile — a unified header decoder for the 831 formats documented on this blog.
Geotagged photos? stag lists every GPS point as CSV and sgeo plots them on a map — both in sfile.