chore: Halkyon Learn moves into apps/learn
Its server, client, app and curator, and the tools that write its assets (maps, Anki fixtures, icons), as they are; paths are fixed in the commits that follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
11abd9afce
commit
649499be23
1 changed files with 0 additions and 0 deletions
69
apps/learn/tool/maps/japan_prefectures.py
Normal file
69
apps/learn/tool/maps/japan_prefectures.py
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Builds the app's map of Japan's prefectures from Natural Earth.
|
||||
|
||||
Natural Earth's vector data is in the public domain. This script downloads
|
||||
its Admin 1 (states, provinces) layer at 1:10m, release v5.1.2, checks the
|
||||
download against the hash recorded below, keeps Japan's 47 prefectures, and
|
||||
reduces them to a compact outline for display (outlines.py): Douglas-Peucker
|
||||
simplification (0.006 degrees), islands too small to see dropped (each
|
||||
prefecture keeps its largest), coordinates rounded to 4 decimals. The result
|
||||
is an approximation, not survey-accurate data.
|
||||
|
||||
Each region is named by its ISO 3166-2 code (JP-01 ... JP-47), with Natural
|
||||
Earth's English and Japanese names.
|
||||
|
||||
Run from the repository root with Python 3 and no other packages:
|
||||
|
||||
python3 tool/maps/japan_prefectures.py
|
||||
|
||||
It rewrites halkyon_learn_flutter/assets/maps/japan_prefectures.geojson.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from outlines import download, polygons_of, reduce # noqa: E402
|
||||
|
||||
SOURCE = (
|
||||
"https://raw.githubusercontent.com/nvkelso/natural-earth-vector/"
|
||||
"v5.1.2/geojson/ne_10m_admin_1_states_provinces.geojson"
|
||||
)
|
||||
SOURCE_SHA256 = "22d0e3ad85eb3e27f17cabf8ba2d50e554fbc27a87796ff891d958185da62fb5"
|
||||
TARGET = Path("halkyon_learn_flutter/assets/maps/japan_prefectures.geojson")
|
||||
|
||||
TOLERANCE = 0.006 # degrees
|
||||
MIN_AREA = 0.0005 # square degrees; smaller islands are dropped
|
||||
DECIMALS = 4
|
||||
|
||||
|
||||
def main():
|
||||
source = json.loads(download(SOURCE, SOURCE_SHA256))
|
||||
features = []
|
||||
for feature in source["features"]:
|
||||
properties = feature["properties"]
|
||||
if properties.get("adm0_a3") != "JPN":
|
||||
continue
|
||||
features.append({
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"code": properties["iso_3166_2"],
|
||||
"name": properties["name"],
|
||||
"name_ja": properties["name_ja"],
|
||||
},
|
||||
"geometry": reduce(polygons_of(feature["geometry"]), TOLERANCE,
|
||||
MIN_AREA, DECIMALS),
|
||||
})
|
||||
features.sort(key=lambda feature: feature["properties"]["code"])
|
||||
codes = [feature["properties"]["code"] for feature in features]
|
||||
if codes != [f"JP-{n:02d}" for n in range(1, 48)]:
|
||||
sys.exit(f"Expected the 47 prefectures JP-01 ... JP-47, got {codes}")
|
||||
TARGET.write_text(json.dumps(
|
||||
{"type": "FeatureCollection", "features": features},
|
||||
ensure_ascii=False, separators=(",", ":")) + "\n", encoding="utf-8")
|
||||
print(f"Wrote {TARGET} ({TARGET.stat().st_size} bytes)", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue