With -pn, give area covered by more than one polygon to the earliest

Consistent snapping keeps the borders of polygons in a layer from crossing,
but where rounding turned a narrow polygon between two others inside out
(for example, a Census block thinner than a pixel whose two sides cross
when rounded to tile coordinates), the area it covered is covered by both of
its neighbors, and snapping can't decide which of them it belongs to.

So after cleaning the polygons of each layer, find the ones that overlap:
two polygons that share an edge in the same direction both cover the area
beside it (neighbors that tile exactly traverse their shared border in
opposite directions), and where their borders don't share any edges, a
vertex of one is strictly inside the other. Then remove each overlapping
area from all but the polygon with the lowest sequence number, using the
layer's hot pixels so the result stays consistent with the rest.

For Dane County Census blocks at -D8 -d8 -pt -pn, this reduces the
overlapping pixels at z8, z9, and z10 from 41, 61, and 61 to 7, 8, and 16,
without changing the gaps much or taking noticeably longer, and with no
self-intersecting polygons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQ6vQUJtmGZnqz7RmVYQaJ
This commit is contained in:
Claude
2026-12-01 01:11:29 +00:00
parent b8e8542dfa
commit 082487b594
7 changed files with 278 additions and 7 deletions
+6 -1
View File
@@ -48,7 +48,12 @@
[x - 0.5, x + 0.5) by [y - 0.5, y + 0.5), as in Hobby's snap rounding,
rather than as closed squares, because edges passing diagonally through
pixel corners otherwise zigzagged through the same pixels in different
orders in different polygons, and could cross each other. For Dane County Census blocks at -D8 -d8 -pt -pn, this
orders in different polygons, and could cross each other. Then, where
rounding turned a narrow polygon between two others inside out, so that the
area it covered is covered by both of its neighbors, that area is removed
from all but the earliest of them. These overlaps are found from edges that
two polygons share in the same direction, which neighbors that tile exactly
never do, and from vertices of one polygon strictly inside another. For Dane County Census blocks at -D8 -d8 -pt -pn, this
reduces the gaps between blocks at z9 and z10 from 55 and 155 pixels to 13
and 23, and the overlaps from 113 and 175 to 56 and 59, and takes about 7%
longer for Natural Earth countries at -z8 -pn.