Handle open way centroids as lines#890
Conversation
LayerAsCentroid defaults to polylabel, but polylabel operates on polygon geometry. Open ways such as barriers and gates were being assigned into a polygon before calculating their label point, which can produce platform-dependent representative points. Use the cached linestring directly for open ways and keep the existing polygon/polylabel path for closed ways. This keeps area labeling behavior unchanged while making open-way label placement match the geometry type being processed.
|
I also checked the change visually against the OSM source geometry from the same Legend in the screenshots:
For the visual check I used a temporary debug process file with stable POI The largest example is Measured against the source way in the PBF:
Two smaller examples: Overview of the checked examples: |




This PR is AI generated.
Handle open way centroids as lines
LayerAsCentroid()defaults to thepolylabelalgorithm for 2D geometries.That is appropriate for polygonal areas, but open ways are linestrings. The
current code assigns every way into a polygon before calculating the
representative point, so open ways can be passed through polygon/polylabel
logic even though they are not closed areas.
This change keeps the existing polygon path for closed ways, but handles open
ways from the cached linestring directly:
geom::centroid_exceptionClosed ways and relations still use the existing polygon/polylabel behavior.
The stored output is still a point, so this changes how the point is calculated
for open ways without changing output layers, attributes, or geometry storage.
This also avoids a temporary polygon conversion for open ways, but the intent
is correctness rather than a performance optimization.
Reproduce
Generate OpenMapTiles-compatible output for an extract that contains open ways
which are emitted through
LayerAsCentroid(), for example named POI-like wayshandled by
WritePOI()or the catch-allpoi_detailpath inprocess-openmaptiles.lua.Before this change, those open ways are assigned into a polygon and labeled via
polygon logic. That can produce representative points that depend on polygon
handling for invalid/open rings.
After this change, open ways use line geometry for their representative point,
while closed ways continue to use polygon labeling.
In the generated-tile CI investigation, the focused open-way centroid patch
changed only
poigeometry in the local Liechtenstein debug output. Tilecounts, feature counts, attributes, and polygon layers were unchanged in that
run.
Testing
git diff --check origin/master..HEADcmake --build build -j2Related Issues And PRs
I did not find an existing upstream issue or PR that directly reports open ways
being labeled through polygon/polylabel handling.
Related centroid/polylabel context:
polylabelbehavior and precision forLayerAsCentroid()/Centroid().LayerAsCentroid()behavior around Lua interop and relationmembers.