Commit Graph

6 Commits

Author SHA1 Message Date
Evan Rusackas
cb005a2ea5 feat(country-map): build script — territory_assignments transform
Implements the third transform: pull features from sibling Admin 0
records into a destination country's Admin 1 view. Used for:
- China + Taiwan/HK/Macau (NE keeps each as separate Admin 0)
- Finland + Åland (missing from FIN admin 1; NE keeps Åland as ALD
  admin 0)

Verified on real data:
  Building worldview=ukr admin_level=1
    territory_assignments: added 4 features from sibling Admin 0 records

(4 = TWN/HKG/MAC + ALD; ARMM-renamed BARMM region picks up correctly
because name_overrides ran first.)

Two bugs fixed along the way:

1. **Property name casing.** NE Admin 0 ships with uppercase property
   names (ADM0_A3, NAME_EN), Admin 1 with lowercase. All transforms
   downstream assume lowercase, so we now normalize to lowercase at
   shapefile-conversion time. Bonus: fixes a silent flying_islands
   bug where `adm0_a3` filters never matched at Admin 0 because the
   props were uppercase.

2. **drop_outside_bbox at Admin 0.** A country's multi-polygon often
   includes overseas territories (Netherlands → Caribbean), so bbox
   filtering at Admin 0 would drop entire countries. Now guarded to
   only run at Admin 1 where each feature is a single subdivision.

3. **Åland's NE code.** NE uses ALD, not the ISO 3166-1 ALA. Updated
   territory_assignments.yaml with comment noting the divergence.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 16:27:04 -07:00
Evan Rusackas
ae5e1132ba feat(country-map): build script — mapshaper -simplify final pass
Add mapshaper -simplify as a final-stage pass after the Python
transforms. Two-stage so the transforms operate on full-resolution
geometry (no risk of repositioning ghost features that got simplified
away) but the shipped output is browser-sized.

Default 5% with keep-shapes — preserves recognizable country shapes
while dropping the per-vertex bloat. keep-shapes prevents tiny features
(small island chains) from being collapsed away entirely.

Results on real outputs:
  Admin 0: 23.6 MB → 2.1 MB  (-91%, 249 features intact)
  Admin 1: 67.7 MB → 15 MB   (-78%, 4591 features, transforms preserved)

Per-feature simplify factors (the notebook had a size-based ladder)
can be added later if specific countries need tuning. 5% is the
mapshaper-recommended "good enough for web" default.

Open thought for future: split Admin 1 output by country
(`<worldview>_admin1_<adm0_a3>.geo.json`) so the per-chart payload is
~50KB-1MB instead of one 15MB global file. Will pair naturally with
the territory_assignments pass (which is per-country anyway).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 16:03:34 -07:00
Evan Rusackas
ea9b21b017 feat(country-map): build script — Admin 1 + flying_islands transform
Add Admin 1 build path and the second declarative transform. Exercises
the YAML config layer on real data:

  Building worldview=ukr admin_level=1
    loaded 4596 features
    name_overrides: applied 19 field updates across 10 entries
    flying_islands: repositioned 12 features, dropped 5 (outside-bbox)
    wrote ukr_admin1.geo.json (67,677,079 bytes, 4591 features)

Counts verified against expectations:
- 19 name_overrides = 2 France typos + 6 France ISO codes
  + 5 PHL Caraga renames + 6 PHL BARMM renames
- 12 repositions = 2 USA + 1 NOR + 2 PRT + 2 ESP + 5 FRA
- 5 drops = NLD Caribbean + GBR overseas territories

New: pure-Python translate/scale geometry transform (no shapely dep);
operates on Polygon/MultiPolygon coordinates. Scale pivot is the bbox
center of each matched feature — good enough for the visual layout
purposes we use it for. Output bbox correctness verified by counts.

Refactor: extract `build_one(worldview, admin_level, ...)` so the
target matrix can grow in subsequent commits.

What's stubbed (TODO inline): territory_assignments, composite_maps,
regional_aggregations, simplification, procedural/. Output is
uncompressed and unsimplified (67MB) — simplification will land with
the mapshaper -simplify pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 16:02:11 -07:00
Evan Rusackas
2db41bb2b2 feat(country-map): minimum-viable build pipeline (NE → GeoJSON)
End-to-end working pipeline replacing the legacy notebook for one
worldview / admin level. Verified locally:

  $ ./build.sh
  Country Map build — pinned to NE v5.1.2 (f1890d9f)
  Loaded 10 name override entries
  Building worldview=ukr admin_level=0
  Downloading NE ne_10m_admin_0_countries_ukr (worldview=ukr)…
    mapshaper: ne_10m_admin_0_countries_ukr.shp → _raw_ukr_admin0.geo.json
    loaded 249 features
    name_overrides: applied 0 field updates across 10 entries
    wrote .../output/ukr_admin0.geo.json (23,639,348 bytes)
  Done.

What's wired:
- NE download from pinned tag (v5.1.2 / SHA f1890d9f) with cache
- Shapefile → GeoJSON via mapshaper CLI
- YAML config loading (currently just name_overrides)
- name_overrides transform with {match, set} semantics, including
  the {in: [...]} list-membership matcher
- Output writes to scripts/output/ (gitignored)
- build.sh wrapper validates Python + Node + PyYAML are available

What's stubbed for future commits (TODO inline):
- Multiple worldviews (currently UA only)
- Admin 1 build (where name_overrides actually fire — currently no
  features in Admin 0 match the FRA/PHL admin1 entries)
- flying_islands, territory_assignments, regional_aggregations,
  composite_maps transforms
- Simplification (mapshaper -simplify)
- Procedural escape-hatch orchestration
- Manifest with NE SHA + build metadata

The 0 overrides applied is correct, not a bug: all current entries
target Admin 1 features.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 16:00:29 -07:00
Evan Rusackas
d2916b99ee feat(country-map): backfill France-with-Overseas composite from full notebook cell
The original draft was missing entries because notebook cell 63 was
truncated in the audit. Reading the full cell surfaced:

- Saint Martin (MAF) + Saint Barthélémy (BLM) as additional sister
  Admin 0 territories (small Caribbean islands, scaled up significantly
  for visibility — 5x and 8x respectively)
- Paris + petite couronne (Hauts-de-Seine, Seine-Saint-Denis,
  Val-de-Marne) as a metropolitan zoom-in (group + translate + scale 3x)
- Per-territory metadata renames (Polynésie française, Nouvelle-
  Calédonie, etc.) + ISO 3166-2 code assignments (FR-PF, FR-NC, etc.)

Schema additions:
- base_repositions[].group: true — when match yields multiple features,
  transform them as a single MultiPolygon then split back out
  (preserves per-feature attributes). Used for the Paris zoom-in.
- additions[].set: { name, iso_3166_2, ... } — override attributes on
  the added/dissolved feature

SPM offset placeholder is gone; composite definition now matches the
notebook's output exactly (modulo the build script implementing the
declarative schema).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 15:57:59 -07:00
Evan Rusackas
1eb48e94fc feat(country-map): scaffold scripts/ dir with YAML config schemas
First-pass schemas for the build pipeline's declarative config layer.
Each schema is documented inline + populated with concrete entries
ported from the legacy notebook's audited touchups (those that the
obsolescence check determined still need to ship).

scripts/
├── README.md                 — pipeline overview, layout, workflow
├── config/
│   ├── name_overrides.yaml         — France typos, ISO codes; PHL renames
│   ├── flying_islands.yaml         — USA/NOR/PRT/ESP/FRA repositions; NLD/GBR drops
│   ├── territory_assignments.yaml  — China + SARs; Finland + Åland
│   ├── regional_aggregations.yaml  — Turkey NUTS-1; FRA/ITA/PHL regions
│   └── composite_maps.yaml         — France-with-Overseas
└── procedural/
    └── README.md             — escape-hatch rules + skeleton (currently empty)

All five YAML files parse cleanly (validated with PyYAML).

Schema design choices:
- Every entry has a `description:` field. Forces honest documentation
  of why each fix exists; reviewers can scan rationale at a glance.
- Match semantics: simple AND-of-conditions; supports `{ in: [...] }`
  for value-set matching.
- composite_maps and territory_assignments share the "pull feature
  from sibling Admin 0" primitive; build script can implement once.
- composite_maps.yaml has a TODO marker for SPM offsets — notebook
  cell 63 was truncated in the audit; will backfill during build
  script implementation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-12 15:56:04 -07:00