docs: stag/sgeo usage, CSV format, map + attribution, build caveat

- docs/stag-sgeo.md: building (make stag sgeo; make all blocked on
  uncommitted src/geotag.c), sfile lookup order, media-extension scan
  set, CSV columns + empty-coords rule, real stag/sgeo output against
  the decoder build of sfile (SF/Tokyo EXIF GPS), OSM attribution and
  the runtime tile-fetch dependency, test suite (8/8).
- README.md: stag/sgeo section + Layout/Building entries.
This commit is contained in:
Muse committed 2026-12-02 09:18:42 +00:00
1 parent 720523151a
commit 3f725687e2
2 files changed
+288

No files matched your search

+47
View File
@@ -153,11 +153,20 @@ first line.
```
make # builds ./sfile (gcc, -O2 -Wall -Wextra, no exotic deps)
make stag sgeo # builds the geotag tools (see below)
make table # regenerate src/formats.h from tools/all_formats.cpp
make test # run the per-format test loop over samples/
make install # install to /usr/local/bin (PREFIX=... to change)
```
> **For now, build the geotag tools with `make stag sgeo`, not
> `make`.** The `all` target builds `sfile` too, and `sfile`
> currently needs `src/geotag.c` — the geotagging-decoder file,
> still uncommitted work in the decoder job's clone — so `make`
> fails in a fresh clone. `make stag sgeo` does not touch `sfile`
> and works. Once the decoders land, `make` builds everything
> again.
## Usage
```
@@ -196,6 +205,9 @@ values) is fixed in `tools/overrides.json` and the table regenerated.
sfile/
src/sfile.c the engine (generic; no per-format code)
src/scar.c file carver built on the format table
src/stag.c geotag CSV tabulator (see below)
src/sgeo.c geotag map plotter (see below)
src/geotag_client.c the stag/sgeo <-> sfile seam (runs sfile, parses "Geotagging:")
src/footers.h footer/trailer signatures used by scar
src/formats.h generated format table (do not edit by hand)
src/formats.json the table as JSON (source of truth for tests)
@@ -206,9 +218,12 @@ sfile/
tools/get_sample_urls.py extracts sample_urls.json from the raw pages
tools/extract_cpp.py extracts all_formats.cpp from the raw pages
tests/run_tests.py the per-format test loop
tests/run_tests.sh the stag/sgeo test suite (8 checks, fake sfile + local tile server)
tests/test_scar.py synthetic-image test for scar (make test-scar)
tests/results.json latest test results
docs/scar.md scar usage, carving decisions, limits
docs/stag-sgeo.md stag/sgeo usage, CSV format, map + attribution, network dependency
docs/geotag-contract.md the sfile <-> stag/sgeo geotag seam (what sfile prints, what the client accepts)
samples/ one real sample file per format + manifests
```
@@ -227,6 +242,38 @@ $ scar image.dd # carves into ./carved/, prints a report table
See `docs/scar.md` for a full example run (real output), how carving
decisions are made, and the limits.
## Geotags: stag and sgeo
`stag` scans a directory of photos/videos and writes one CSV row per
file (`file,format,latitude,longitude,altitude,datum,timestamp,source`);
every scanned file gets a row, with empty geo fields when no location
was found. `sgeo` plots the geotagged files on an OpenStreetMap image
(one red marker each, attribution baked onto the PNG). Both run the
`sfile` binary and parse its `Geotagging:` section — they never parse
containers themselves; the seam is `docs/geotag-contract.md`.
```console
$ make stag sgeo # build (not `make` — see docs/stag-sgeo.md)
$ stag photos/ # -> geotags.csv in the cwd
$ sgeo photos/ # -> map.png in the cwd (fetches OSM tiles at runtime)
```
Real output (San Francisco + Tokyo EXIF GPS, via the decoder build
of sfile):
```text
file,format,latitude,longitude,altitude,datum,timestamp,source
plain.jpg,JPEG image,,,,,,
sf_real.jpg,JPEG image,37.774929,-122.419418,12.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
tokyo_real.jpg,JPEG image,35.676200,139.650300,,WGS-84,,EXIF GPS IFD (JPEG APP1 segment)
```
`sgeo` needs network access to tile.openstreetmap.org when it runs,
and the `© OpenStreetMap contributors` attribution drawn on the image
must stay there. See `docs/stag-sgeo.md` for the full usage, the CSV
format and the empty-coords rule, the test suite
(`tests/run_tests.sh`, 8/8 pass), and the build caveat.
## Sources
Format reference code: https://fileformat.vpscoder.com (849 task pages).
+241
View File
@@ -0,0 +1,241 @@
# stag / sgeo — geotags as CSV, geotags on a map
`stag` scans a directory of photos and videos and writes one CSV row
per file with whatever location `sfile` recovered from it. `sgeo`
plots the geotagged files from a directory on an OpenStreetMap image.
Both are thin clients over `sfile`: they run the `sfile` binary on
each file and parse the `Geotagging:` section it prints — they never
parse image or video containers themselves. The exact seam — what
`sfile` prints and what the client parser accepts — is
`docs/geotag-contract.md`.
## Building
```console
$ make stag sgeo
```
`stag` needs only libm; `sgeo` links libpng and libcurl
(`-lpng -lcurl -lm`), so the libpng and libcurl development packages
must be installed. Both need a built `sfile` binary at *runtime*, not
at build time (see [Finding sfile](#finding-sfile)).
> **For now, build with `make stag sgeo`, not `make`.** The pushed
> Makefile's `all` target builds `sfile` too, and `sfile` currently
> needs `src/geotag.c` — the geotagging-decoder file, which is still
> uncommitted work in the decoder job's clone. In a fresh clone
> `make` fails with:
>
> ```console
> $ make
> make: *** No rule to make target 'src/geotag.c', needed by 'sfile'. Stop.
> ```
>
> `make stag sgeo` does not touch `sfile` and works in a fresh clone
> (verified Dec 2, 2026). Once the geotagging decoders land, `make`
> builds everything again.
## Finding sfile
`stag`/`sgeo` locate the `sfile` binary in this order:
1. `$SFILE`, if set — it must be executable, otherwise the tool fails
loudly instead of guessing.
2. `sfile` on `PATH`.
3. `sfile` in the same directory as the `stag`/`sgeo` binary.
If no `sfile` can be run, the tool stops with
`stag: cannot run sfile on '...' (set $SFILE or put sfile on PATH)`
and exit code 1.
## What gets scanned
One directory, non-recursive. Only regular files with a media
extension are scanned (case-insensitive), sorted by filename;
dotfiles are skipped:
```text
jpg jpeg png gif webp tif tiff heic heif avif jxl bmp dib
mp4 m4v mov mkv webm avi m2ts mts 3gp 3g2 mpg mpeg wmv flv f4v ogv
```
Everything else is skipped: text files, subdirectories, dotfiles.
Note that a previous `sgeo` run's `map.png` sitting in the same
directory *is* a PNG, so it is scanned and gets an empty row — see
the real example below.
## stag
```console
$ stag [dir] [outfile]
```
`dir` defaults to `.`, `outfile` defaults to `geotags.csv` in the
current directory. Exit code 0 on success, 1 on a usage error, an
unreadable directory, an unwritable outfile, or an un-runnable
`sfile`. A summary goes to stderr, e.g.
`stag: 4 file(s), 2 geotagged -> geotags.csv`.
### CSV format
Header:
```text
file,format,latitude,longitude,altitude,datum,timestamp,source
```
One row per scanned file, in filename order. Fields:
| column | content |
| --- | --- |
| `file` | filename only (no directory); quoted when it contains a comma, quote, or newline |
| `format` | format name from sfile's `Format:` line, e.g. `JPEG image`; `unknown` if sfile could not identify the file |
| `latitude` / `longitude` | signed decimal degrees, 6 decimals; empty when no geotag was found |
| `altitude` | metres above sea level, 3 decimals; empty when no altitude was recovered |
| `datum` | datum as recorded, usually `WGS-84`; defaults to `WGS-84` when a location was found and no datum was printed; empty when no geotag |
| `timestamp` | UTC timestamp from `gps_datetime_utc`, passed through verbatim; empty when unknown |
| `source` | where the location came from, e.g. `EXIF GPS`; `unknown` when no `source:` line was seen; empty when no geotag |
**The empty-coords rule:** every scanned file gets a row, even one
with no location at all. A missing geotag means empty
latitude/longitude/altitude/datum/timestamp/source — never a missing
row, never a zero coordinate. (0, 0) is a real place in the Gulf of
Guinea; an empty field is "not recorded".
### Real example
Two JPEGs with EXIF GPS tags written by exiftool (San Francisco and
Tokyo), one plain JPEG with no GPS, plus the `map.png` from an
earlier `sgeo` run in the same directory — run with the decoder
build of sfile (`SFILE=/opt/sfile/sfile`):
```console
$ SFILE=/opt/sfile/sfile ./stag /tmp/realgeo /tmp/realgeo-fresh.csv
stag: 4 file(s), 2 geotagged -> /tmp/realgeo-fresh.csv
$ cat /tmp/realgeo-fresh.csv
file,format,latitude,longitude,altitude,datum,timestamp,source
plain.jpg,JPEG image,,,,,,
real.png,PNG image,,,,,,
sf_real.jpg,JPEG image,37.774929,-122.419418,12.000,WGS-84,2024-05-01 12:34:56,EXIF GPS IFD (JPEG APP1 segment)
tokyo_real.jpg,JPEG image,35.676200,139.650300,,WGS-84,,EXIF GPS IFD (JPEG APP1 segment)
```
What sfile printed for the San Francisco file (the input stag
parsed — note the ISO timestamp; the decoder normalises EXIF
`YYYY:MM:DD` to dashes, see `docs/geotag-contract.md`):
```text
Geotagging:
source: EXIF GPS IFD (JPEG APP1 segment)
gps_latitude: 37.774929 (37°46'29.74"N)
gps_longitude: -122.419418 (122°25'09.90"W)
gps_altitude_m: 12.000 (above sea level)
gps_datum: WGS-84
gps_datetime_utc: 2024-05-01 12:34:56
```
The synthetic suite (`tests/run_tests.sh`) also covers the fallback
forms the client accepts — raw EXIF GPS tags in sfile's header table
instead of a `Geotagging:` section — where the source defaults to
`unknown` and the timestamp keeps its EXIF colons:
```text
file,format,latitude,longitude,altitude,datum,timestamp,source
PARIS.JPG,JPEG image,48.856600,2.352200,,WGS-84,,EXIF GPS
nyc.jpg,JPEG image,40.712800,-74.006000,10.000,WGS-84,2024:06:15 08:30:00,unknown
plain.jpg,JPEG image,,,,,,
sf.jpg,JPEG image,37.774929,-122.419418,12.000,WGS-84,2024-05-01 12:34:56,EXIF GPS
tokyo.jpg,JPEG image,35.676200,139.650300,,WGS-84,,XMP
```
## sgeo
```console
$ sgeo [dir] [outfile]
```
`dir` defaults to `.`, `outfile` defaults to `map.png` in the
current directory. The map is built from OpenStreetMap raster tiles
fetched at runtime (see [Network dependency](#network-dependency))
and stitched with libpng. The zoom is computed from the points'
bounding box — a single point, or several at the same spot, uses
zoom 15 — and zoomed out until the tile count fits (at most 100
tiles). One red filled circle (radius 7 px) is drawn per geotagged
file. Exit code 0 on success.
### Real example
Same directory as the `stag` example above, against the live tile
server:
```console
$ SFILE=/opt/sfile/sfile ./sgeo /tmp/realgeo /tmp/realgeo-fresh.png
sgeo: 4 file(s), 2 geotagged, zoom 2, 1024x256, 4 tile(s) -> /tmp/realgeo-fresh.png
$ file /tmp/realgeo-fresh.png
/tmp/realgeo-fresh.png: PNG image data, 1024 x 256, 8-bit/color RGB, non-interlaced
```
San Francisco and Tokyo are far apart, so the zoom drops to 2 and
the image is 1024x256 from 4 tiles.
### No geotags
If no file in the directory has a location, `sgeo` prints an error
to stderr, exits 1, and writes **no file**:
```console
$ sgeo /tmp/nogeo /tmp/nogeo.png
sgeo: no geotagged files found in '/tmp/nogeo' -- nothing to plot
$ ls /tmp/nogeo.png
ls: cannot access '/tmp/nogeo.png': No such file or directory
```
### Attribution
The string `© OpenStreetMap contributors` is drawn **on the image
itself** — a white plaque with black text, bottom-left — using a
small self-contained 5x7 bitmap font, so no ImageMagick or other
tool is needed at runtime. The OpenStreetMap tile usage policy
requires this attribution wherever the tiles are shown; because it
is baked into the PNG, the map stays attributed wherever the file
goes. Do not crop it off.
### Network dependency
`sgeo` fetches tiles from `https://tile.openstreetmap.org` **when it
runs** (libcurl); no tiles are bundled with the tool or the repo, and
the User-Agent identifies the tool, per the OSM tile usage policy.
That means `sgeo` needs network access to tile.openstreetmap.org at
runtime — offline it fails on the tile fetch — and it makes one HTTP
request per tile (4 in the example above). `$SGEO_TILE_BASE`
overrides the tile base URL; the tests use it to point at a local
tile server.
## Tests
`tests/run_tests.sh` (run from the repo root) exercises both tools
end to end with a fake `sfile` (`tests/bin/sfile`, canned GPS values
dispatched on filename) and a local tile server
(`tests/tile_server.py`, via `$SGEO_TILE_BASE`), so the suite is
offline. Eight checks, all passing:
```console
$ ./tests/run_tests.sh
PASS: stag multi-file CSV byte-for-byte
PASS: sgeo multi-file map (4 markers + attribution)
PASS: sgeo single-point map (1 marker)
PASS: stag no-geotag CSV
PASS: sgeo no-geotag: non-zero, message, no file
PASS: stag empty-dir CSV (header only)
PASS: sgeo empty-dir: non-zero, no file
PASS: default outfiles geotags.csv / map.png
stag/sgeo tests: ALL PASS
```
Cases covered: a multi-file directory (CSV byte-for-byte against
`tests/expected_geotags.csv`, map with 4 markers plus the
attribution plaque), a single point, a no-geotag directory (stag
rows are empty, sgeo fails with no file), an empty directory (stag
header only, sgeo fails with no file), and the default outfiles
(`geotags.csv` / `map.png` in the cwd). The real-file path against
the decoder build of sfile is shown in the examples above.