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
+4 -4
View File
@@ -21,7 +21,7 @@
,
{ "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.492188, 39.977120 ], [ -100.019531, 39.977120 ], [ -100.019531, 40.044438 ], [ -99.931641, 40.044438 ], [ -99.755859, 40.044438 ], [ -99.492188, 39.977120 ] ] ] } }
,
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.755859, 40.044438 ], [ -99.492188, 39.977120 ], [ -99.316406, 39.977120 ], [ -99.316406, 39.909736 ], [ -100.019531, 39.909736 ], [ -100.019531, 39.977120 ], [ -99.931641, 40.044438 ], [ -99.755859, 40.044438 ] ] ] } }
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -100.019531, 39.977120 ], [ -99.492188, 39.977120 ], [ -99.316406, 39.977120 ], [ -99.316406, 39.909736 ], [ -100.019531, 39.909736 ], [ -100.019531, 39.977120 ] ] ] } }
] }
] }
,
@@ -49,7 +49,7 @@
,
{ "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.294434, 40.078071 ], [ -99.294434, 40.010787 ], [ -99.492188, 39.977120 ], [ -99.645996, 40.010787 ], [ -99.755859, 39.977120 ], [ -99.821777, 39.993956 ], [ -99.865723, 39.993956 ], [ -99.909668, 40.010787 ], [ -99.931641, 40.010787 ], [ -99.997559, 39.993956 ], [ -99.997559, 40.078071 ], [ -99.294434, 40.078071 ] ] ] } }
,
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.294434, 40.010787 ], [ -99.294434, 39.926588 ], [ -99.997559, 39.926588 ], [ -99.997559, 39.993956 ], [ -99.931641, 40.010787 ], [ -99.909668, 40.010787 ], [ -99.865723, 39.993956 ], [ -99.821777, 39.993956 ], [ -99.645996, 40.010787 ], [ -99.492188, 39.977120 ], [ -99.294434, 40.010787 ] ] ] } }
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.909668, 40.010787 ], [ -99.865723, 39.993956 ], [ -99.821777, 39.993956 ], [ -99.755859, 39.977120 ], [ -99.645996, 40.010787 ], [ -99.492188, 39.977120 ], [ -99.294434, 40.010787 ], [ -99.294434, 39.926588 ], [ -99.997559, 39.926588 ], [ -99.997559, 39.993956 ], [ -99.931641, 40.010787 ], [ -99.909668, 40.010787 ] ] ] } }
] }
] }
,
@@ -95,7 +95,7 @@
,
{ "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.297180, 40.071766 ], [ -99.297180, 40.006580 ], [ -99.319153, 40.017098 ], [ -99.354858, 40.008683 ], [ -99.385071, 40.010787 ], [ -99.420776, 39.993956 ], [ -99.453735, 39.993956 ], [ -99.483948, 39.983434 ], [ -99.519653, 39.993956 ], [ -99.555359, 39.996060 ], [ -99.582825, 40.010787 ], [ -99.618530, 40.008683 ], [ -99.648743, 40.017098 ], [ -99.684448, 40.002372 ], [ -99.717407, 40.000268 ], [ -99.753113, 39.985538 ], [ -99.758606, 39.985538 ], [ -99.783325, 39.989747 ], [ -99.819031, 39.987643 ], [ -99.824524, 39.989747 ], [ -99.846497, 40.002372 ], [ -99.851990, 40.002372 ], [ -99.882202, 40.004476 ], [ -99.917908, 40.017098 ], [ -99.953613, 40.006580 ], [ -99.981079, 40.008683 ], [ -100.000305, 40.000268 ], [ -100.000305, 40.071766 ], [ -99.297180, 40.071766 ] ] ] } }
,
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.912415, 40.017098 ], [ -99.882202, 40.004476 ], [ -99.854736, 40.004476 ], [ -99.851990, 40.002372 ], [ -99.824524, 39.989747 ], [ -99.819031, 39.987643 ], [ -99.813538, 39.985538 ], [ -99.783325, 39.989747 ], [ -99.758606, 39.985538 ], [ -99.753113, 39.985538 ], [ -99.747620, 39.985538 ], [ -99.717407, 40.000268 ], [ -99.684448, 40.002372 ], [ -99.648743, 40.017098 ], [ -99.618530, 40.008683 ], [ -99.582825, 40.010787 ], [ -99.555359, 39.993956 ], [ -99.519653, 39.993956 ], [ -99.483948, 39.983434 ], [ -99.453735, 39.993956 ], [ -99.420776, 39.993956 ], [ -99.385071, 40.010787 ], [ -99.354858, 40.008683 ], [ -99.319153, 40.017098 ], [ -99.297180, 40.006580 ], [ -99.297180, 39.928695 ], [ -100.000305, 39.928695 ], [ -100.000305, 40.000268 ], [ -99.981079, 40.008683 ], [ -99.953613, 40.006580 ], [ -99.923401, 40.017098 ], [ -99.917908, 40.017098 ], [ -99.912415, 40.017098 ] ] ] } }
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.319153, 40.017098 ], [ -99.297180, 40.006580 ], [ -99.297180, 39.928695 ], [ -100.000305, 39.928695 ], [ -100.000305, 40.000268 ], [ -99.981079, 40.008683 ], [ -99.953613, 40.006580 ], [ -99.917908, 40.017098 ], [ -99.882202, 40.004476 ], [ -99.851990, 40.002372 ], [ -99.824524, 39.989747 ], [ -99.819031, 39.987643 ], [ -99.813538, 39.985538 ], [ -99.783325, 39.989747 ], [ -99.758606, 39.985538 ], [ -99.753113, 39.985538 ], [ -99.747620, 39.985538 ], [ -99.717407, 40.000268 ], [ -99.684448, 40.002372 ], [ -99.648743, 40.017098 ], [ -99.618530, 40.008683 ], [ -99.582825, 40.010787 ], [ -99.555359, 39.993956 ], [ -99.519653, 39.993956 ], [ -99.483948, 39.983434 ], [ -99.453735, 39.993956 ], [ -99.420776, 39.993956 ], [ -99.385071, 40.010787 ], [ -99.354858, 40.008683 ], [ -99.319153, 40.017098 ] ] ] } }
] }
] }
,
@@ -111,7 +111,7 @@
,
{ "type": "Feature", "properties": { "name": "A" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.295807, 40.071766 ], [ -99.295807, 40.006580 ], [ -99.308167, 40.012891 ], [ -99.320526, 40.017098 ], [ -99.331512, 40.014994 ], [ -99.354858, 40.008683 ], [ -99.383698, 40.010787 ], [ -99.396057, 40.006580 ], [ -99.419403, 39.993956 ], [ -99.455109, 39.992904 ], [ -99.483948, 39.982382 ], [ -99.496307, 39.984486 ], [ -99.519653, 39.993956 ], [ -99.542999, 39.992904 ], [ -99.553986, 39.995008 ], [ -99.584198, 40.010787 ], [ -99.595184, 40.011839 ], [ -99.618530, 40.008683 ], [ -99.648743, 40.017098 ], [ -99.659729, 40.013943 ], [ -99.683075, 40.002372 ], [ -99.718781, 40.000268 ], [ -99.742126, 39.987643 ], [ -99.744873, 39.986591 ], [ -99.747620, 39.985538 ], [ -99.750366, 39.985538 ], [ -99.753113, 39.984486 ], [ -99.754486, 39.984486 ], [ -99.783325, 39.990799 ], [ -99.806671, 39.986591 ], [ -99.812164, 39.986591 ], [ -99.817657, 39.986591 ], [ -99.820404, 39.987643 ], [ -99.842377, 39.999216 ], [ -99.847870, 40.002372 ], [ -99.849243, 40.002372 ], [ -99.857483, 40.004476 ], [ -99.858856, 40.004476 ], [ -99.882202, 40.004476 ], [ -99.905548, 40.013943 ], [ -99.909668, 40.014994 ], [ -99.912415, 40.016046 ], [ -99.915161, 40.016046 ], [ -99.917908, 40.017098 ], [ -99.919281, 40.017098 ], [ -99.953613, 40.007632 ], [ -99.982452, 40.008683 ], [ -100.000305, 40.000268 ], [ -100.000305, 40.071766 ], [ -99.295807, 40.071766 ] ] ] } }
,
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.923401, 40.017098 ], [ -99.919281, 40.017098 ], [ -99.917908, 40.017098 ], [ -99.915161, 40.016046 ], [ -99.912415, 40.016046 ], [ -99.909668, 40.014994 ], [ -99.905548, 40.013943 ], [ -99.882202, 40.003424 ], [ -99.858856, 40.004476 ], [ -99.857483, 40.004476 ], [ -99.853363, 40.004476 ], [ -99.849243, 40.002372 ], [ -99.847870, 40.002372 ], [ -99.842377, 39.999216 ], [ -99.824524, 39.988695 ], [ -99.820404, 39.987643 ], [ -99.812164, 39.986591 ], [ -99.783325, 39.990799 ], [ -99.759979, 39.984486 ], [ -99.754486, 39.984486 ], [ -99.753113, 39.984486 ], [ -99.750366, 39.985538 ], [ -99.747620, 39.985538 ], [ -99.744873, 39.986591 ], [ -99.742126, 39.987643 ], [ -99.718781, 40.000268 ], [ -99.683075, 40.002372 ], [ -99.659729, 40.013943 ], [ -99.648743, 40.016046 ], [ -99.618530, 40.008683 ], [ -99.595184, 40.011839 ], [ -99.584198, 40.010787 ], [ -99.553986, 39.995008 ], [ -99.542999, 39.992904 ], [ -99.519653, 39.993956 ], [ -99.496307, 39.984486 ], [ -99.483948, 39.982382 ], [ -99.455109, 39.992904 ], [ -99.419403, 39.992904 ], [ -99.396057, 40.006580 ], [ -99.383698, 40.010787 ], [ -99.354858, 40.008683 ], [ -99.331512, 40.014994 ], [ -99.320526, 40.016046 ], [ -99.308167, 40.012891 ], [ -99.295807, 40.005528 ], [ -99.295807, 39.927642 ], [ -100.000305, 39.927642 ], [ -100.000305, 40.000268 ], [ -99.982452, 40.008683 ], [ -99.953613, 40.007632 ], [ -99.923401, 40.017098 ] ] ] } }
{ "type": "Feature", "properties": { "name": "B" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -99.917908, 40.017098 ], [ -99.915161, 40.016046 ], [ -99.912415, 40.016046 ], [ -99.909668, 40.014994 ], [ -99.905548, 40.013943 ], [ -99.882202, 40.003424 ], [ -99.858856, 40.004476 ], [ -99.857483, 40.004476 ], [ -99.849243, 40.002372 ], [ -99.847870, 40.002372 ], [ -99.842377, 39.999216 ], [ -99.824524, 39.988695 ], [ -99.820404, 39.987643 ], [ -99.817657, 39.986591 ], [ -99.812164, 39.986591 ], [ -99.806671, 39.986591 ], [ -99.783325, 39.990799 ], [ -99.759979, 39.984486 ], [ -99.754486, 39.984486 ], [ -99.753113, 39.984486 ], [ -99.750366, 39.985538 ], [ -99.747620, 39.985538 ], [ -99.744873, 39.986591 ], [ -99.742126, 39.987643 ], [ -99.718781, 40.000268 ], [ -99.683075, 40.002372 ], [ -99.659729, 40.013943 ], [ -99.648743, 40.016046 ], [ -99.618530, 40.008683 ], [ -99.595184, 40.011839 ], [ -99.584198, 40.010787 ], [ -99.553986, 39.995008 ], [ -99.542999, 39.992904 ], [ -99.519653, 39.993956 ], [ -99.496307, 39.984486 ], [ -99.483948, 39.982382 ], [ -99.455109, 39.992904 ], [ -99.419403, 39.992904 ], [ -99.396057, 40.006580 ], [ -99.383698, 40.010787 ], [ -99.354858, 40.008683 ], [ -99.331512, 40.014994 ], [ -99.320526, 40.016046 ], [ -99.308167, 40.012891 ], [ -99.295807, 40.005528 ], [ -99.295807, 39.927642 ], [ -100.000305, 39.927642 ], [ -100.000305, 40.000268 ], [ -99.982452, 40.008683 ], [ -99.953613, 40.007632 ], [ -99.919281, 40.017098 ], [ -99.917908, 40.017098 ] ] ] } }
] }
] }
,