From 84d8026a9b6e340b9e7a0816246020c9e997a6aa Mon Sep 17 00:00:00 2001 From: Symmetricity <184246+Symmetricity@users.noreply.github.com> Date: Wed, 13 May 2026 20:29:57 +0200 Subject: [PATCH] Handle open way centroids as lines 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. --- src/osm_lua_processing.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index c395b902..bc5271a4 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -862,14 +862,25 @@ Point OsmLuaProcessing::calculateCentroid(CentroidAlgorithm algorithm) { } return Point(centroid.x()*10000000.0, centroid.y()*10000000.0); } else if (isWay) { - Polygon p; - geom::assign_points(p, linestringCached()); - - if (algorithm == CentroidAlgorithm::Polylabel) { - // CONSIDER: pick precision intelligently - centroid = mapbox::polylabel(p); + if (!isClosed) { + const Linestring &ls = linestringCached(); + if (ls.empty()) + throw geom::centroid_exception(); + if (ls.size()==1) { + centroid = ls.front(); + } else { + geom::centroid(ls, centroid); + } } else { - geom::centroid(p, centroid); + Polygon p; + geom::assign_points(p, linestringCached()); + + if (algorithm == CentroidAlgorithm::Polylabel) { + // CONSIDER: pick precision intelligently + centroid = mapbox::polylabel(p); + } else { + geom::centroid(p, centroid); + } } return Point(centroid.x()*10000000.0, centroid.y()*10000000.0); } else {