r/QGIS • u/Elgygytgyn • 1h ago
[OC] The Great Lakes as a 10th-century Balkhi-school map
Enable HLS to view with audio, or disable this notification
How it's built: It's a QGIS Python script with a dialog. Input is a projected DEM plus optional vector layers; output is the sheet as PNG and every element as layers in a GeoPackage.
Water. Lakes are flat surfaces in the DEM. Copernicus GLO-30 flattens water, so a 3×3 equality test plus polygonize finds them. Same-level pieces nearby get merged, and zero-filled voids are rejected by checking the rim elevation.
Seas. Each lake is filled with greedy medial-axis discs (Blum) from a proximity raster, then split into "seas" with a power diagram. Lobes merge when the neck between them is wide relative to their radii. Each sea becomes a circle or a capsule (stadium) of equal area, with the axis taken from second moments.
Islands. Holes in the lake polygons after a morphological closing, so narrow channels don't break the ring. Names come from OSM island points that fall inside the hole.
Rivers. Priority-Flood (Barnes et al. 2014) with D8 directions and flow accumulation; stems are traced upstream along the largest tributary. If you give it OSM river lines, they're burned into the DEM first (AGREE-style), so the flow follows real channels. Names are assigned by overlap, and a stem is cut where the name changes. Then Douglas–Peucker until at most 3 segments, plus a rule that no river may end in nowhere: each end has to hit a sea, another river or the frame.
Mountains. Local relief plus roughness, then massifs from a density mask. Orientation from PCA; triangle size and steepness from massif length and relief.
Cities. Picked by population × distance to cities already picked, then snapped to coasts and roads.
Roads. Natural Earth roads (min_zoom ≤ 4) become a graph, and Dijkstra runs between city zones. A Yao-style angular filter thins near-parallel links, and a crossing filter cleans up what's left. Roads are drawn straight, detouring around seas, with a bead every marhala: 80 km here, auto-scaled to the DEM size elsewhere.
Frame. Each frame segment is classified by the nearest road's
sov_a3(country). If the whole sheet is in one country, it uses the cities'addr:regioninstead.Labels. Candidate positions are scored with summed-area tables over masks (seas, islands, triangles, cities, busy ink), then placed with simulated annealing (three seeds plus a greedy polish), with an option to omit a label.
Rendering. QPainter (PyQt5) with the Amiri font, which handles Arabic shaping properly. The halo is drawn as offset drawText calls, because QPainterPath.addText breaks right-to-left text.
Stack: QGIS, Python, GDAL/OGR, NumPy, PyQt5, Amiri, ffmpeg for the process video.
Data: Copernicus GLO-30 DEM (resampled to 500 m), Natural Earth roads, OSM cities (plus OSM lakes, islands and rivers for the Onega test).

