@rembish/iso-topojson 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Creative Commons Attribution 4.0 International (CC BY 4.0)
2
+
3
+ Copyright (c) 2026 Alex Rembish
4
+
5
+ You are free to:
6
+ Share — copy and redistribute the material in any medium or format
7
+ Adapt — remix, transform, and build upon the material for any purpose
8
+
9
+ Under the following terms:
10
+ Attribution — You must give appropriate credit, provide a link to the
11
+ license, and indicate if changes were made.
12
+
13
+ Full license text: https://creativecommons.org/licenses/by/4.0/legalcode
14
+
15
+ ---
16
+
17
+ Attribution for source data:
18
+
19
+ - Natural Earth (https://www.naturalearthdata.com/) — public domain
package/README.md ADDED
@@ -0,0 +1,164 @@
1
+ # iso-topojson
2
+
3
+ Public-domain TopoJSON world map with **247 polygons** keyed by [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.
4
+
5
+ No existing open-source solution covers this cleanly — `world-atlas` merges overseas territories into their sovereign states and uses ISO numeric codes, not alpha-2.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @rembish/iso-topojson
11
+ ```
12
+
13
+ ## CDN
14
+
15
+ ```
16
+ https://unpkg.com/@rembish/iso-topojson/iso-a2.json
17
+ https://unpkg.com/@rembish/iso-topojson/iso-a2-markers.json
18
+ ```
19
+
20
+ ## Files
21
+
22
+ | File | Size | Description |
23
+ |------|------|-------------|
24
+ | `iso-a2.json` | 203 KB | Full-detail TopoJSON, 247 polygon features |
25
+ | `iso-a2-markers.json` | 246 KB | Compact variant: tiny territories (< 500 km²) replaced with Point markers |
26
+
27
+ In `iso-a2-markers.json` the ~50 smallest territories (Maldives, Malta, Liechtenstein, most Caribbean islands, etc.) appear as `Point` geometries with `"marker": true` in their properties. Bouvet Island, Heard Island, and US Minor Outlying Islands are point markers in this variant only — they are omitted from the full file. All other features share the same properties schema.
28
+
29
+ ## Usage
30
+
31
+ ### JavaScript
32
+
33
+ ```js
34
+ const topology = await fetch(
35
+ "https://unpkg.com/@rembish/iso-topojson/iso-a2.json"
36
+ ).then(r => r.json());
37
+ ```
38
+
39
+ ### D3.js — polygons only
40
+
41
+ ```js
42
+ import { feature } from "topojson-client";
43
+
44
+ const allFeatures = Object.values(topology.objects)
45
+ .flatMap(obj => feature(topology, obj).features);
46
+
47
+ const projection = d3.geoNaturalEarth1();
48
+ const path = d3.geoPath(projection);
49
+
50
+ svg.selectAll("path")
51
+ .data(allFeatures)
52
+ .join("path")
53
+ .attr("d", path)
54
+ .attr("fill", d => colorByCode(d.properties.iso_a2));
55
+ ```
56
+
57
+ ### D3.js — markers file (polygons + point circles)
58
+
59
+ ```js
60
+ import { feature } from "topojson-client";
61
+
62
+ const topology = await fetch(
63
+ "https://unpkg.com/@rembish/iso-topojson/iso-a2-markers.json"
64
+ ).then(r => r.json());
65
+
66
+ const allFeatures = Object.values(topology.objects)
67
+ .flatMap(obj => feature(topology, obj).features);
68
+
69
+ const polygons = allFeatures.filter(
70
+ f => f.geometry.type === "Polygon" || f.geometry.type === "MultiPolygon"
71
+ );
72
+ const markers = allFeatures.filter(f => f.geometry.type === "Point");
73
+
74
+ // Draw polygon features
75
+ svg.selectAll("path")
76
+ .data(polygons)
77
+ .join("path")
78
+ .attr("d", path)
79
+ .attr("fill", d => colorByCode(d.properties.iso_a2));
80
+
81
+ // Draw point markers
82
+ svg.selectAll("circle")
83
+ .data(markers)
84
+ .join("circle")
85
+ .attr("r", 3)
86
+ .attr("cx", d => projection(d.geometry.coordinates)[0])
87
+ .attr("cy", d => projection(d.geometry.coordinates)[1])
88
+ .attr("fill", d => colorByCode(d.properties.iso_a2));
89
+ ```
90
+
91
+ ## Feature Properties
92
+
93
+ | Property | Type | Description |
94
+ |----------|------|-------------|
95
+ | `iso_a2` | `string` | ISO 3166-1 alpha-2 code — primary key |
96
+ | `iso_a3` | `string \| null` | ISO 3166-1 alpha-3 code |
97
+ | `iso_n3` | `number \| null` | ISO 3166-1 numeric code |
98
+ | `name` | `string` | Common English name |
99
+ | `sovereign` | `string` | Sovereign state name (same as `name` for independent countries) |
100
+ | `type` | `string` | `"country"`, `"territory"`, `"disputed"`, or `"dependency"` |
101
+ | `marker` | `boolean` | `true` if this feature is a Point marker (markers file only) |
102
+ | `area_km2` | `number` | Area in km² (markers file only, for classified features) |
103
+
104
+ ## Coverage
105
+
106
+ All 249 ISO 3166-1 alpha-2 entries with a meaningful geographic polygon are included, plus Kosovo (`XK`, quasi-ISO). Overseas territories, Crown dependencies, and special administrative regions are **separate polygons**, not merged into their sovereign state:
107
+
108
+ - French overseas departments and territories (GF, GP, MQ, RE, YT, PM, BL, MF, NC, PF, TF, WF)
109
+ - British Overseas Territories (AI, BM, FK, GI, GG, GS, IO, IM, JE, KY, MS, SH, TC, VG)
110
+ - US territories (AS, GU, MP, PR, VI)
111
+ - Dutch Caribbean (AW, BQ, CW, SX)
112
+ - Australian territories (CC, CX, NF)
113
+ - Danish territories (FO, GL)
114
+ - Norwegian territories (SJ)
115
+ - Chinese SARs (HK, MO)
116
+ - Disputed / quasi-ISO (EH, PS, TW, XK)
117
+ - And many more…
118
+
119
+ Bouvet Island (BV), Heard Island (HM), and US Minor Outlying Islands (UM) appear as Point markers in `iso-a2-markers.json` only.
120
+
121
+ ## Build
122
+
123
+ Prerequisites: **Python 3.12+**, **Node.js** (for `npx mapshaper`).
124
+
125
+ ```bash
126
+ make all
127
+ ```
128
+
129
+ Full pipeline:
130
+
131
+ 1. **venv** — creates `.venv` and installs Python dependencies
132
+ 2. **check** — lint (`ruff`, `black`), type-check (`mypy`), tests (`pytest`, ≥ 80% coverage)
133
+ 3. **download** — fetches Natural Earth 10m shapefiles
134
+ 4. **build** — assembles 247 GeoJSON features via direct matches, subunit extractions, admin-1 merges, island bbox extractions, and disputed-area overlays → `output/merged.geojson`
135
+ 5. **simplify** — runs `mapshaper` at **3% vertex retention** → `output/iso-a2.json` (203 KB)
136
+ 6. **markers** — replaces polygons < 500 km² with centroid point markers → `output/iso-a2-markers.json` (246 KB)
137
+ 7. **validate** — checks all expected codes are present and valid
138
+ 8. **dist** — copies both files to the repo root
139
+
140
+ ### Tuning simplification
141
+
142
+ ```bash
143
+ make simplify SIMPLIFY=5% # more detail (larger file)
144
+ make simplify SIMPLIFY=1% # more compression (smaller file)
145
+ ```
146
+
147
+ ## Viewer
148
+
149
+ ```bash
150
+ make serve
151
+ # → http://localhost:8000/viewer.html
152
+ ```
153
+
154
+ Renders all features coloured by type (country / territory / disputed / dependency). Toggle between Full and Markers variants. Hover for iso_a2, name, sovereign, type, and area.
155
+
156
+ ## Data Sources
157
+
158
+ | Source | License | Use |
159
+ |--------|---------|-----|
160
+ | [Natural Earth 10m](https://www.naturalearthdata.com/) | Public domain | Base polygons |
161
+
162
+ ## License
163
+
164
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) — derived from [Natural Earth](https://www.naturalearthdata.com/) (public domain).