Make POI tag ranking deterministic and rank-aware#889
Conversation
GetPOIRank returned the first matching POI tag group, but it iterated poiTags with pairs(). Lua does not specify table traversal order, so objects matching multiple POI groups could receive different class and rank values across runs or platforms. Iterate an explicit POI key list with ipairs() so the profile priority order is stable, and keep the subclass temporary local to the ranking function.
|
I added visual checks for the determinism issue. For this comparison I generated two local upstream outputs from the same binary, I also generated the PR output twice for the same objects; the selected POI tags The screenshots use a local Sportsplatz RheinwieseSource tags include
Schwimmbad MühleholzSource tags include
Tennishalle SchaanSource tags include
|
|
I think this one will be the most controversial. The issue at play that this PR fixes is that currently POI tagging isn't deterministic - on one run it will be right, on others wrong. What this fixes is that it will be consistent - either wrong all the time, or right all the time. |
OpenMapTiles ranks POI classes by ascending class priority, but the profile previously stopped at the first matching POI key. Even after making that iteration deterministic, multi-tag POIs could consistently select a lower-priority class. Evaluate all explicit POI tag matches and keep the lowest numeric rank, using the explicit key list only as the deterministic equal-rank tie-break. This keeps the profile stable while matching the OpenMapTiles priority model more closely. Co-authored-by: Codex <noreply@openai.com>
|
Okay, I've fixed my own concern here now. This will now make it deterministic & rank aware, so it will always return the highest ranked (most important) tag. |



This PR is AI generated.
Make POI tag ranking deterministic and rank-aware
GetPOIRank()returns the first matching POI tag group. It currently iteratespoiTagswithpairs(), but Lua does not specify table traversal order fornon-array tables. That means an object with more than one matching POI tag can
receive different
class,subclass, and rank values depending on Lua tableiteration order.
OpenMapTiles ranks POIs by class priority in ascending order:
layers/poi/class.sqldefinespoi_class_rank(class)layers/poi/poi.sqlorders POIs withpoi_class_rank(...) ASCTilemaker's OpenMapTiles profile mirrors that priority with
poiClassRanks.Use an explicit
poiTagKeysarray and iterate it withipairs(), but do notstop at the first matching key. Instead, evaluate all explicit matching POI tag
groups and return the candidate with the lowest numeric
poiClassRanksvalue.The explicit key order remains the deterministic tie-break for equal ranks.
OpenMapTiles does not define a secondary equal-rank ordering in
layer_poi(),so this tie-break is tilemaker's deterministic profile order rather than a
claim about SQL result order.
Apply the same change to both OpenMapTiles profiles,
process-openmaptiles.luaandprocess-debug.lua.Examples
An object with both of these tags has two valid POI matches:
Before this change, whichever key
pairs(poiTags)returned first determinedthe output. The object could be classified from either matching tag group.
After this change, both candidates are evaluated and the OpenMapTiles-style
rank priority is used:
That matches the profile rank table because
attractionhas a higher prioritythan
school.For the sports pitch case from the visual evidence:
The previous deterministic-only version consistently selected the first
profile key:
This version selects the better-ranked class:
For equal ranks, the explicit key order is still used as the tie-break. For
example:
returns the first equal-rank candidate in
process-openmaptiles.lua:Reproduce
Load the OpenMapTiles process file and evaluate POIs that have multiple
matching tag groups:
Expected output:
The same ranking issue and fix apply to
resources/process-debug.lua.Testing
git diff --check origin/master..HEADluac -p resources/process-openmaptiles.lua resources/process-debug.luaGetPOIRank()in both process files:amenity=school+tourism=attractionleisure=pitch+sport=soccerleisure=sports_centre+sport=tennisRelated Issues And PRs
I did not find an existing upstream issue, PR, or discussion that directly
reports this
pairs(poiTags)ordering issue.Related POI context:
process-openmaptiles.luato match newerOpenMapTiles POI schema coverage. This PR does not change the schema mapping;
it only makes the current mapping deterministic and rank-aware.