world: carve Natural Earth with Natural Earth, not with our own country masks (#184) #185
No reviewers
Labels
No labels
blocked
claude-wip
map-report
map:is
map:se
needs-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
art/ismap!185
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-184-world-carve"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #184. Reported against the Greece pilot (#176) as grey wedges in the Gulf of Corinth,
then again — after the first version of this PR — as big chunks of Norway drawn as water
along its borders with Sweden and Finland. Both are the same root cause, and both are fixed
here. Follow-up: #186.
The bug, in both directions
background_landwas Natural Earth land minus the union of everymap_country_mask_0partition: a precise national geometry subtracted from a coarse global one. Measured
before this change:
segrfiplisIceland scores zero on both only because its mask is a 25 km buffered convex hull that
swallows Natural Earth's Iceland whole — not available to a country with land neighbours.
No mask geometry fixes this, and #176 proved it: extending Greece's mask with the WFD
coastal water bodies took the Gulf of Corinth window from 2 429 km² to 40, and the map still
showed a 1 km line straight through it, because coastal water reaches ~2 km and Natural
Earth's error in an open gulf is tens of kilometres.
The fix, part one — carve Natural Earth with Natural Earth
ne_10m_admin_0_countries: same scale as the land layer, same source geometry, one polygonper country with an ISO code. Subtracting that is exact, because it is subtracting a shape
from itself. Which countries get carved is still driven by
map_country_mask_0— the holetracks the data we have, countries go in and out one at a time — but only the country code
is read, never the geometry.
The fix, part two — 1:10m, because the residual scales with generalization
The carve is exact, but Natural Earth's idea of where a border runs is not the national
source's, and the strip between them gets carved with nothing to draw it. That is the Norway
bug. It is not fixable by better national geometry — the error is in the other operand — but
it shrinks with Natural Earth's scale:
sefigrpl~14 500 km² of land border drawn as water → ~3 300, about a 140 m strip, sub-pixel at every
zoom this layer draws. Tile budgets still pass.
Measured and rejected
A protection band along foreign borders — carve Natural Earth's country but stop short
near a neighbour — trades the two errors roughly 1:1 at every width and both scales. At 1:10m
with a 2 km band, Poland's unfilled land drops 1 930 → 626 km² while 3 034 km² of Natural
Earth land comes back inside Poland. Not in the config; the numbers are in the commit
message so nobody rediscovers it.
Verification
Rendered over CDP in real time (R127), the views from both bug reports: the Gulf of Corinth is
water with no wedge and no line; the Athens coast at z10 has no fringe; the Sweden/Norway
border meets Sweden's cover cleanly with Norway's fjords properly resolved; Poland's eastern
border is clean.
make acceptancegreen apart from the pre-existing Poland buildings R120timeout (#166, fails identically on
main). Go build/vet/test green.Four tests, because the checks this replaces could not fail
The old carve check — "no background land overlaps the mask" — is tautologically true:
background_landis Natural Earth minus the mask. It passed for five countries while themap was visibly wrong.
-99for some disputed states; an unmatched country is silently never carved), and nobackground land is left inside an imported country.
Earth says is its own, so it agreed with Natural Earth's opinion of the border and was
blind to the Norway bug. R146 asks how much Natural Earth land we carved that the country's
own boundary disclaims. That is the one place the national mask geometry is still worth
reading — as a check, not an input.
cost minutes against 1:10m geometry: background + carve must add back up to Natural Earth
land. Live: 145 515 244 + 1 326 411 = 146 841 655 km², exact to the km², 0.4 s. It still
catches what it was written for — an experimental 1 m grid size on
ST_DifferencecostNew Zealand 3 813 km², Papua New Guinea 198 and Japan 91, nowhere near any carve,
because a grid size snaps the inputs too. Caught, measured, reverted.
Also in here
The shapefile loader could not read Natural Earth's admin-0 file at all: its
.dbfisNUL-padded rather than space-padded — 15 917 cells — and Postgres rejects a NUL inside
text outright (SQLSTATE 22021), so the whole COPY died on a file that is not malformed.
sanitizeDBFTextstrips the padding and replaces invalid UTF-8, with a unit test.Follow-ups
question ("Natural Earth says land, our country says nothing") with opposite right answers,
and only a land+territorial-waters polygon can separate them. Includes the analysis of
inverting the background (base = land, draw Natural Earth water), which fixes borders
structurally but moves the same ambiguity to the coast.
probably concentrated somewhere specific and may be Poland's own mask rather than Natural
Earth. Localisation query in #186.