"""Builds grenzen-welt.json and grenzen.json, the map data of the figure „Grenzen“ on benjaminmoritz.de/geschichte/ (the world, and Europe enlarged below it), from the GeoJSON files of historical-basemaps by André Ourednik (https://github.com/aourednik/historical-basemaps, licence GNU GPL 3.0). This script and both results are licensed under the GNU GPL 3.0 as well (see LIZENZ-GPL-3.0.txt). Copyright of the data: André Ourednik and contributors; changes and this script: Benjamin Moritz, 2026. Without any warranty (sections 15 and 16 of the licence). python3 grenzen_rechnen.txt (a Python script, kept as .txt so that every server shows it as text) What it changes compared with the original files (14.11.2026); all snapshots from 5000 BC on: - World (grenzen-welt.json): Equal Earth projection, latitude 58° S to 84° N, width 640, simplified to about 1 unit and rounded to whole units; areas smaller than 3 square units fall away. Also the outline of the Europe frame. - Europe (grenzen.json): a frame fitted to longitude -12 to 45 and latitude 33 to 72, Lambert azimuthal equal-area projection centred on 15° E, 52° N, width 640, simplified to about 0.8 units, rounded to whole units; areas smaller than 4 square units fall away. Snapshots identical inside the frame to the one before are left out; the one before then carries both years (y, y2). Kept per area: NAME, SUBJECTO and BORDERPRECISION. The coastline of the background comes from world_2010.geojson. """ import hashlib import json import math import os import sys import warnings from shapely.geometry import box, shape from shapely.ops import transform, unary_union warnings.filterwarnings("ignore", category=DeprecationWarning) W = 640 # -- Europe: Lambert azimuthal equal-area ------------------------------------------------------------------------------ LON0, LAT0 = math.radians(15), math.radians(52) def laea(lon, lat): lam, phi = math.radians(lon), math.radians(lat) k = math.sqrt(2 / (1 + math.sin(LAT0) * math.sin(phi) + math.cos(LAT0) * math.cos(phi) * math.cos(lam - LON0))) return (k * math.cos(phi) * math.sin(lam - LON0), k * (math.cos(LAT0) * math.sin(phi) - math.sin(LAT0) * math.cos(phi) * math.cos(lam - LON0))) def laea_inv(x, y): rho = math.hypot(x, y) if rho == 0: return math.degrees(LON0), math.degrees(LAT0) c = 2 * math.asin(rho / 2) phi = math.asin(math.cos(c) * math.sin(LAT0) + y * math.sin(c) * math.cos(LAT0) / rho) lam = LON0 + math.atan2(x * math.sin(c), rho * math.cos(LAT0) * math.cos(c) - y * math.sin(LAT0) * math.sin(c)) return math.degrees(lam), math.degrees(phi) _c = [laea(x, y) for x in (-12, 15, 45) for y in (33, 72)] + [laea(-12, 52), laea(45, 52)] EX0, EX1 = min(c[0] for c in _c), max(c[0] for c in _c) EY0, EY1 = min(c[1] for c in _c), max(c[1] for c in _c) ES = W / (EX1 - EX0) EH = round((EY1 - EY0) * ES) def proj_eu(x, y, z=None): pts = [laea(a, b) for a, b in zip(x, y)] return [(p[0] - EX0) * ES for p in pts], [(EY1 - p[1]) * ES for p in pts] # -- World: Equal Earth ------------------------------------------------------------------------------------------------ A1, A2, A3, A4, M = 1.340264, -0.081106, 0.000893, 0.003796, math.sqrt(3) / 2 def ee(lon, lat): t = math.asin(M * math.sin(math.radians(lat))) t2 = t * t t6 = t2 ** 3 x = 2 * math.sqrt(3) * math.radians(lon) * math.cos(t) / (3 * (9 * A4 * t6 * t2 + 7 * A3 * t6 + 3 * A2 * t2 + A1)) y = t * (A4 * t6 * t2 + A3 * t6 + A2 * t2 + A1) return x, y LAT_S, LAT_N = -58, 84 WXM = ee(180, 0)[0] WY1, WY0 = ee(0, LAT_N)[1], ee(0, LAT_S)[1] WS = W / (2 * WXM) WH = round((WY1 - WY0) * WS) def proj_w(x, y, z=None): pts = [ee(a, b) for a, b in zip(x, y)] return [(p[0] + WXM) * WS for p in pts], [(WY1 - p[1]) * WS for p in pts] VIEWS = { "eu": {"clip": box(-40, 20, 75, 82), "proj": proj_eu, "w": W, "h": EH, "tol": 0.8, "min": 4, "file": "grenzen.json"}, "w": {"clip": box(-180, LAT_S, 180, LAT_N), "proj": proj_w, "w": W, "h": WH, "tol": 1.0, "min": 3, "file": "grenzen-welt.json"}, } def clean(g): return g if g.is_valid else g.buffer(0) def path(geom, minimum): out = [] polys = [geom] if geom.geom_type == "Polygon" else list(getattr(geom, "geoms", [])) for p in polys: if p.geom_type != "Polygon" or p.area < minimum: continue for ring in [p.exterior] + list(p.interiors): pts, prev = [], None for x, y in list(ring.coords)[:-1]: # whole units, repeated points dropped q = (round(x), round(y)) if q != prev: pts.append(q) prev = q if len(pts) >= 3: out.append("M" + "L".join(f"{x},{y}" for x, y in pts) + "Z") return "".join(out) def project(geom, v): s = clean(geom) if not s.intersects(v["clip"]): return None s = clean(s.intersection(v["clip"])) if s.is_empty: return None s = clean(transform(v["proj"], s)).intersection(box(0, 0, v["w"], v["h"])) return None if s.is_empty else s.simplify(v["tol"], preserve_topology=True) def year_of(name): n = name[len("world_"):-len(".geojson")] return -int(n[2:]) if n.startswith("bc") else int(n) def frame(features, v): out = [] for ft in features: if not ft.get("geometry"): continue s = project(shape(ft["geometry"]), v) if s is None: continue d = path(s, v["min"]) if not d: continue p = ft["properties"] c = s.representative_point() out.append({"n": (p.get("NAME") or "").strip(), "s": (p.get("SUBJECTO") or "").strip(), "b": p.get("BORDERPRECISION") or 1, "a": round(s.area), "c": [round(c.x), round(c.y)], "d": d}) out.sort(key=lambda r: -r["a"]) return out def europe_outline(): """The Europe frame drawn on the world map: its edges in the Lambert plane, back to longitude and latitude.""" pts = [] for k in range(41): pts.append((EX0 + (EX1 - EX0) * k / 40, EY1)) for k in range(41): pts.append((EX1, EY1 - (EY1 - EY0) * k / 40)) for k in range(41): pts.append((EX1 - (EX1 - EX0) * k / 40, EY0)) for k in range(41): pts.append((EX0, EY0 + (EY1 - EY0) * k / 40)) ll = [laea_inv(x, y) for x, y in pts] xs, ys = proj_w([a for a, _b in ll], [b for _a, b in ll]) return "M" + "L".join(f"{x:.1f},{y:.1f}" for x, y in zip(xs, ys)) + "Z" def main(folder, commit): files = sorted((f for f in os.listdir(folder) if f.startswith("world_") and f.endswith(".geojson")), key=year_of) files = [f for f in files if -5000 <= year_of(f)] feats = {f: json.load(open(os.path.join(folder, f), encoding="utf-8"))["features"] for f in files} land_all = clean(unary_union([clean(shape(ft["geometry"])) for ft in json.load(open(os.path.join(folder, "world_2010.geojson"), encoding="utf-8"))["features"] if ft.get("geometry")])) for key, v in VIEWS.items(): land = project(land_all, v) frames, last = [], None for f in files: fr = frame(feats[f], v) h = hashlib.sha256(json.dumps(fr).encode()).hexdigest() if h == last: # the same inside the frame: the snapshot before stands for both years frames[-1]["y2"] = year_of(f) continue last = h frames.append({"y": year_of(f), "f": f, "p": fr}) out = {"w": v["w"], "h": v["h"], "src": "https://github.com/aourednik/historical-basemaps", "commit": commit, "licence": "GNU GPL 3.0", "land": path(land, v["min"]), "frames": frames} if key == "w": out["box"] = europe_outline() with open(v["file"], "w", encoding="utf-8") as fh: json.dump(out, fh, ensure_ascii=False, separators=(",", ":")) print(v["file"], len(frames), "frames,", os.path.getsize(v["file"]) // 1024, "KB, height", v["h"]) if __name__ == "__main__": main(sys.argv[1], sys.argv[2])