Replace polygons that collapse entirely with their outlines, not rectangles

When a polygon collapsed away to nothing during cleaning, revive_polygon()
replaced it with a rectangle with the polygon's area, centered on the
average of its vertices. That looked bad for two reasons. Most polygons that
collapse are much smaller than a pixel, and the rectangle is at least a
pixel, so it was usually far too big: for Dane County Census blocks at
-D8 -d8 -pt -pn, 88% of the 27,206 revived polygons had less than half a
pixel of area, and the median rectangle had 11 times the area of the polygon
it replaced. And the larger polygons that collapse are almost all long and
narrow, like blocks between roads, so a square at their midpoint looked
nothing like them.

Now a polygon that collapses entirely is first replaced by the union of
one-pixel strips along every edge of its simplified outline, which traces
its shape in the right place. Only if that is empty too, because the whole
polygon is within a pixel or so, is it replaced by the rectangle, which is
then a single pixel. This is part of spindle preservation, so with
--no-spindle-preservation the rectangle is still used.

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-11-30 22:41:12 +00:00
parent 5b35e5dacf
commit 34e1f56bdd
10 changed files with 106 additions and 9 deletions
+1 -1
View File
@@ -513,7 +513,7 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
* `-pt` or `--no-tiny-polygon-reduction`: Don't combine the area of very small polygons into small squares that represent their combined area.
* `-pT` or `--no-tiny-polygon-reduction-at-maximum-zoom`: Combine the area of very small polygons into small squares that represent their combined area only at zoom levels below the maximum.
* `--tiny-polygon-size=`_size_: Use the specified _size_ for tiny polygons instead of the default 2. Anything above 6 or so will lead to visible artifacts with the default tile detail.
* `--no-spindle-preservation`: Don't preserve the narrow parts of polygons. Normally, parts of polygons that are too narrow to survive being rounded to tile coordinates (like a buffer of a few meters around a long road or river) are kept as continuous lines of polygon one pixel wide, and long, narrow polygons are kept as polygons rather than being combined into tiny-polygon squares. With this option, they are allowed to collapse away, which leaves them as scattered fragments wherever the rounding happens to keep their two sides apart. With `--no-simplification-of-shared-nodes`, narrow parts are not preserved where that would make them overlap a neighboring feature that shares a border with them, like a panhandle between two other political units, so that features that tile exactly continue to do so.
* `--no-spindle-preservation`: Don't preserve the narrow parts of polygons. Normally, parts of polygons that are too narrow to survive being rounded to tile coordinates (like a buffer of a few meters around a long road or river) are kept as continuous lines of polygon one pixel wide, and long, narrow polygons are kept as polygons rather than being combined into tiny-polygon squares. A polygon that still collapses away entirely is replaced by a line one pixel wide along its outline, rather than by a rectangle with its area. With this option, they are allowed to collapse away, which leaves them as scattered fragments wherever the rounding happens to keep their two sides apart. With `--no-simplification-of-shared-nodes`, narrow parts are not preserved where that would make them overlap a neighboring feature that shares a border with them, like a panhandle between two other political units, so that features that tile exactly continue to do so.
* `-av` or `--visvalingam`: Use Visvalingam's simplification algorithm rather than Douglas-Peucker's.
### Attempts to improve shared polygon boundaries