felt / tippecanoe

Build vector tilesets from large collections of GeoJSON features.
BSD 2-Clause "Simplified" License
875 stars 76 forks source link

Improve the appearance of coalesce-densest-as-needed tiles #247

Closed e-n-f closed 2 weeks ago

e-n-f commented 3 weeks ago

This PR improves the appearance of the coalesced-as-needed tiles that are generated when the full feature data for a tile exceeds the tile size limit.

The representative point for spatial indexing of polygon features is now the center of mass instead of an arbitrary vertex, reducing the risk that two consecutive features will be given the same index, causing the second to be considered infinitely high-density even if it is quite large. (This change only applies if the --drop-densest-as-needed or --coalesce-densest-as-needed flag is set, to avoid changing the sequence of all of the polygons in all of the test fixtures again.)

Rather than calculating the density of features during tiling, by comparing the feature's index to the previous feature's index, each feature now has a gap field, containing the square of the physical (mercator) distance from the previous feature's representative point to the most distant vertex of this feature. This prevents features from being considered more densely packed than they actually are, and discourages coalescing of large features onto small ones. Each feature's gap is now also constant across zooms rather than sometimes varying because of differences in which features survived clipping to the tile bounds.

In addition, coalesced features often looked stairstepped because --no-simplification-of-shared-nodes prevented simplification of vertices that had been corners of the original features. Collinear vertices are now simplified away before scaling down to tile resolution, eliminating the stairstepping.