Repository navigation
Conversation
PostGIS ST_ClipByBox2D can produce MultiPolygons where interior rings (holes) are stored as separate single-ring polygons instead of being associated with their parent exterior ring. The MVT encoder flattens all rings and the MVT decoder re-groups them via winding order, which accidentally fixes the structure. The MLT encoder preserved the broken PostGIS structure as-is, causing maplibre to render holes as filled polygons and produce triangular artifacts at specific zoom levels. Fix: before encoding a MultiPolygon, detect whether any single-ring polygon has a clockwise (interior) ring — a sign that holes were separated from their parent. If so, re-group all rings using the same winding-order heuristic as the MVT decoder (classifyRings): non-CW rings start a new polygon, CW rings become holes of the current polygon. Correctly structured MultiPolygons are left untouched. Verified on tile 7/65/47: landuse_a went from 2 to 26 MultiPolygons with holes, matching the PBF output exactly.
Contributor
Author
|
Closing: the winding-order "regrouping" heuristic in this PR is actively harmful. It merges legitimate MultiPolygons that contain several separate same-winding components (e.g. 28 disjoint forest patches) into a single polygon with bogus holes, producing the very triangular artifacts it aimed to fix. The correct hole/interior-ring association is guaranteed by the data source (PostGIS ST_MakeValid(method=structure)); the MLT encoder simply passes the structure through unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MLT tiles showed triangular artifacts in maplibre-gl-js when rendering fill polygons at specific zoom levels (e.g. z7). The PBF (MVT) version of the same tile rendered correctly.
Root cause
PostGIS
ST_ClipByBox2Dcan produce MultiPolygons where interior rings (holes) are stored as separate single-ring polygons instead of being associated with their parent exterior ring.classifyRings), which accidentally fixes the broken PostGIS structure.Fix
In
MLTEncoder.encode, before encoding a MultiPolygon:Verification
7/65/47landuse_alayer: went from 2 → 26 MultiPolygons with holes, matching the PBF output exactly.Files changed
Sources/MVTTools/Coders/MLT/MLTEncoder.swift— the fixTests/MVTToolsTests/MLT/MLTRoundtripGeometryTests.swift— regression tests