Files
Muse 934c336667 sgeo --trip: draw the journey as an ordered polyline with time labels
Reads a stag CSV, orders the geotagged rows by their parsed
timestamp (ISO and EXIF-colon forms sort together), and draws the
trip on an OSM map: blue line with white halo, direction arrowhead
per leg, red marker per stop, MM-DD HH:MM label per timestamped
stop. Rows without a timestamp go last in CSV order; rows without
coordinates are skipped. Reuses sgeo tile/zoom/marker code via
shared fetch_tiles/draw_attribution helpers. Tests: 11/11 in
tests/run_tests.sh (3 new trip cases + tests/check_trip.py).
Docs: docs/trip-path.md.
2026-12-02 09:36:30 +00:00

6.5 KiB

sgeo --trip: draw the journey as a path on the map

sgeo --trip <csv> [outfile] reads a stag CSV and draws the trip it records: the geotagged rows in timestamp order, connected as an ordered polyline on an OpenStreetMap image — not just markers. Each stop gets a red marker, each leg a blue line with a white halo and an arrowhead showing the direction of travel, and each timestamped stop a time label (MM-DD HH:MM, UTC, as stag printed it) next to its marker.

Usage

$ make sgeo
$ stag photos/                 # -> geotags.csv in the cwd
$ sgeo --trip geotags.csv      # -> trip.png in the cwd
$ sgeo --trip geotags.csv day1.png

outfile defaults to trip.png in the current directory. The map is built from OpenStreetMap raster tiles fetched at runtime, exactly like sgeo's directory mode (same zoom choice from the points' bounding box, same tile budget, same attribution plaque baked onto the image). $SGEO_TILE_BASE overrides the tile base URL; the tests use it to point at a local tile server. No sfile binary is needed: the input is the CSV itself, so --trip works on a CSV made anywhere — by stag, by hand, or by a spreadsheet — as long as it has stag's columns.

Exit code 0 on success; 1 if the CSV cannot be read, has a bad header, or has no geotagged rows (no output file is written then), 2 on a usage error.

CSV input expectations

The header must start with stag's columns:

file,format,latitude,longitude,altitude,datum,timestamp,source

Rows are parsed as real CSV (quoted fields, with "" for a quote inside, are handled, so filenames containing commas work). Only the latitude, longitude and timestamp columns matter:

column how --trip uses it
latitude / longitude the stop's position; empty means "no geotag" and the row is skipped (the CSV's empty-coords rule)
timestamp the stop's time, for ordering and the label; empty means "time unknown" and the stop goes last, in CSV order, with no label
the rest ignored (file appears in warnings only)

A row with garbage coordinates (non-numeric, or latitude outside ±90 / longitude outside ±180) is warned about on stderr and skipped; the count is reported at the end. A row with fewer than 7 fields is malformed and skipped the same way.

Timestamp ordering

Rows are ordered by their timestamp, not by their position in the file — a CSV in filename order is almost never in time order, and drawing file order would draw the wrong journey. The timestamp is parsed, not compared as text, so the two forms stag emits sort together:

  • ISO, as the decoder prints it: 2024-05-01 12:34:56 (or date-only 2024-05-01, which labels as 05-01 and sorts at midnight)
  • EXIF-colon, as the fallback path passes it through: 2024:06:15 08:30:00

(A text comparison would put every YYYY:MM:DD row after every YYYY-MM-DD row, whatever the dates — : sorts after -.) Rows with equal timestamps, and all rows with no timestamp, keep CSV order, so the path is deterministic. A time-only value (no date) cannot be ordered and is treated as no timestamp.

Labels show MM-DD HH:MM (date-only: MM-DD). The year is omitted: a trip path fits on one map, and the year is in the CSV. Times are UTC, as stag prints them.

What is drawn, in order

  1. The legs, in timestamp order: a blue line (radius 2) with a white halo (radius 4) so the path reads over any tile.
  2. One arrowhead per leg, at the leg's midpoint, pointing along the direction of travel (legs shorter than 80 px get none — the arrow would touch the markers).
  3. One red marker per stop (the same marker as directory mode), drawn on top of the line.
  4. One time label per timestamped stop: a white plaque with black text, upper-right of the marker, flipped to the left (or below) at the image edge. Untimestamped stops get a marker but no label.
  5. The © OpenStreetMap contributors attribution plaque, last, so it is never covered up.

A single geotagged row draws just its marker and label, like directory mode with one point.

Example

Five photos around San Francisco, in the CSV in filename order (c.jpg first, a.jpg second — deliberately not time order), one with no timestamp, one with no geotag at all:

$ cat trip.csv
file,format,latitude,longitude,altitude,datum,timestamp,source
c.jpg,JPEG image,37.784900,-122.379400,,WGS-84,2024-05-01 10:00:00,EXIF GPS
a.jpg,JPEG image,37.774900,-122.419400,,WGS-84,2024-05-01 08:00:00,EXIF GPS
d.jpg,JPEG image,37.754900,-122.439400,,WGS-84,2024-05-01 11:00:00,EXIF GPS
b.jpg,JPEG image,37.804900,-122.409400,,WGS-84,2024:05:01 09:00:00,EXIF GPS
e.jpg,JPEG image,37.794900,-122.439400,,WGS-84,,EXIF GPS
plain.jpg,JPEG image,,,,,,
$ sgeo --trip trip.csv trip.png
sgeo: 6 row(s) in 'trip.csv', 5 point(s), 4 with timestamps, zoom 13, 768x768, 9 tile(s) -> trip.png

The drawn path is 08:00 (downtown) → 09:00 (Telegraph Hill) → 10:00 (over the Bay) → 11:00 (Castro) → the untimestamped stop (Presidio Heights) last — not the file's c → a → d → b → e order. The b.jpg leg proves the mixed-format sort: its EXIF-colon 2024:05:01 09:00:00 slots between the two ISO timestamps, where a text sort would have put it after all of them. The same map rendered against live OSM tiles is the feature image of the follow-up article on fileformat.vpscoder.com (see the stag/sgeo article there).

Limits

  • A trip crossing the antimeridian (±180°) draws the long way around the map: the polyline connects the projected points directly, with no wrap. (Directory mode has the same shape of limitation for markers at opposite edges.)
  • In a dense cluster, time labels can overlap each other or a leg: labels are placed per-marker with no collision avoidance. Split the CSV if the labels collide.
  • The path is a straight line between consecutive stops (great-circle segments are not drawn); for a day's photos the difference is invisible at these zooms.
  • Only the first location per file is used: the CSV has one row per file, so a file with several locations contributes its first block, as stag records it (see docs/geotag-contract.md, "first source wins").

Tests

tests/run_tests.sh covers --trip with a synthetic CSV (the example above, against the local tile server) plus a single-point CSV and the failure cases — see tests/check_trip.py, which re-implements the projection and checks the markers land on their projected points, the blue line follows the timestamp-ordered legs (and not the file-order hops), and every timestamped marker has a label plaque. Eleven checks in the suite, all passing.