Find all the overlaps between polygons when removing them

Overlap removal could miss overlapping polygons in three ways:

- An overlap can be bounded entirely by vertices that both polygons share
  (for example, a half-pixel triangle cut off one block's square by another
  block's diagonal), so no vertex is strictly inside the other polygon. But
  the overlap is then bounded by an edge of one polygon that isn't on the
  other's boundary, so the edge's midpoint is strictly inside the other.
  So test the midpoints of edges as well as the vertices, in doubled
  coordinates so the test stays exact.

- A polygon whose edges weren't snapped to the layer's hot pixels (an
  outline replacing a collapsed polygon, or one with spindle strips) can run
  along another polygon's border without having vertices where the other
  does, so neither the shared-edge test nor the vertex and midpoint tests see
  the overlap. So first split each polygon's edges exactly wherever another
  polygon's vertex lies on them, which doesn't change any shape. Polygons
  whose overlaps aren't removed are left as they were.

- Where spindle strips made two polygons' edges cross, the difference has to
  snap the crossing to tile coordinates, which can leave a smaller overlap.
  So repeat overlap removal until nothing changes, at most 4 times.

For Dane County Census blocks at -D8 -d8 -pt -pn, there are now no points
covered by more than one polygon at any zoom level (sampled at four points
per pixel), with -z8 and with -zg up to z12, and 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 02:28:58 +00:00
parent 4d761d4307
commit c7f45ee81d
5 changed files with 167 additions and 15 deletions
+7 -2
View File
@@ -53,10 +53,15 @@
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. The
never do, and from vertices and edge midpoints of one polygon strictly
inside another, after splitting each polygon's edges wherever another
polygon's vertex lies on them. The
overlapping area is removed at a higher resolution than the tile, so that
the polygon isn't snapped to tile coordinates a second time, which could
collapse parts of it that the first snapping had left, and leave holes. For Dane County Census blocks at -D8 -d8 -pt -pn, this
collapse parts of it that the first snapping had left, and leave holes.
Where spindle strips made two polygons' edges cross, removing the overlap
has to snap the crossing to tile coordinates, which can leave a smaller
overlap, so this is repeated until no overlaps are left (at most 4 times). 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.