From 353bf897ace0610242b6f465cee2314ba8fe88a1 Mon Sep 17 00:00:00 2001 From: adrian Date: Sun, 22 Jun 2025 20:28:09 -0400 Subject: [PATCH 1/5] fix a number of bugs and differences from openmaptiles vector tile schema 1. zoom 4, 5, and 7 road values were incorrectly being used. 2. openmaptiles shows admin 3 boundaries much higher. 3. unpaved and paved values are parsed from surface list 4. remove duplicate variable definitions. 5. SetMinZoomByAreaWithLimit allows up to minzoom 4 6. fix whitespace and a few variable issues. --- resources/process-openmaptiles.lua | 74 +++++++++++++++++------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index 3158bfba..15a0755b 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -30,6 +30,8 @@ function Set(list) end -- Meters per pixel if tile is 256x256 +ZRES3 = 19567.88 +ZRES4 = 9783.94 ZRES5 = 4891.97 ZRES6 = 2445.98 ZRES7 = 1222.99 @@ -47,8 +49,8 @@ INVALID_ZOOM = 99 -- Process node/way tags aerodromeValues = Set { "international", "public", "regional", "military", "private" } -pavedValues = Set { "paved", "asphalt", "cobblestone", "concrete", "concrete:lanes", "concrete:plates", "metal", "paving_stones", "sett", "unhewn_cobblestone", "wood" } -unpavedValues = Set { "unpaved", "compacted", "dirt", "earth", "fine_gravel", "grass", "grass_paver", "gravel", "gravel_turf", "ground", "ice", "mud", "pebblestone", "salt", "sand", "snow", "woodchips" } +unpavedValues = Set { "unpaved", "artificial_turf", "clay", "compacted", "crushed_limestone", "dirt", "dirt/sand", "earth", "fine_gravel", "grass", "grass_paver", "gravel", "gravel_turf", "ground", "ice", "mud", "pebblestone", "rock", "rocky", "rocks", "salt", "sand", "shells", "snow", "soil", "stepping_stones", "stone", "woodchips" } +pavedValues = Set { "paved", "acrylic", "asphalt", "brick", "bricks", "cement", "chipseal", "cobblestone", "concrete", "concrete:lanes", "concrete:plates", "granite", "interlock", "metal", "metal_grid", "paving_stones", "plastic", "rubber", "sett", "tartan", "unhewn_cobblestone", "wood", "grade1" } -- Process node tags @@ -64,7 +66,7 @@ function capitalLevel(capital) if capital_al == 0 then return nil end - return capital_al + return capital_al end -- Calculate rank for place nodes @@ -96,7 +98,7 @@ function calcRank(place, population, capital_al) end if place ~= "city" and place ~= "town" then return nil - end + end if population > 3 * 10^6 then return 1 elseif population > 1 * 10^6 then @@ -217,7 +219,9 @@ end -- Process way tags -majorRoadValues = Set { "motorway", "trunk", "primary" } +z4RoadValues = Set { "motorway" } +z5RoadValues = Set { "trunk" } +z7RoadValues = Set { "primary" } z9RoadValues = Set { "secondary", "motorway_link", "trunk_link" } z10RoadValues = Set { "primary_link", "secondary_link" } z11RoadValues = Set { "tertiary", "tertiary_link", "busway", "bus_guideway" } @@ -228,8 +232,6 @@ z13RoadValues = Set { "track", "service" } manMadeRoadValues = Set { "pier", "bridge" } pathValues = Set { "footway", "cycleway", "bridleway", "path", "steps", "pedestrian", "platform" } linkValues = Set { "motorway_link", "trunk_link", "primary_link", "secondary_link", "tertiary_link" } -pavedValues = Set { "paved", "asphalt", "cobblestone", "concrete", "concrete:lanes", "concrete:plates", "metal", "paving_stones", "sett", "unhewn_cobblestone", "wood" } -unpavedValues = Set { "unpaved", "compacted", "dirt", "earth", "fine_gravel", "grass", "grass_paver", "gravel", "gravel_turf", "ground", "ice", "mud", "pebblestone", "salt", "sand", "snow", "woodchips" } railwayClasses = { rail="rail", narrow_gauge="rail", preserved="rail", funicular="rail", subway="transit", light_rail="transit", monorail="transit", tram="transit" } aerowayBuildings= Set { "terminal", "gate", "tower" } @@ -314,6 +316,7 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s if subclass and subclass ~= "" then Attribute("subclass", subclass) end + local accessMinzoom = 9 AttributeInteger("layer", tonumber(Find("layer")) or 0, accessMinzoom) SetBrunnelAttributes() -- We do not write any other attributes for areas. @@ -327,7 +330,6 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s -- Service if (is_rail or highway_class == "service") and (service and service ~="") then Attribute("service", service) end - local accessMinzoom = 9 if is_road then local oneway = Find("oneway") if oneway == "yes" or oneway == "1" then @@ -336,13 +338,9 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s if oneway == "-1" then -- **** TODO end - local surface = Find("surface") local surfaceMinzoom = 12 - if pavedValues[surface] then - Attribute("surface", "paved", surfaceMinzoom) - elseif unpavedValues[surface] then - Attribute("surface", "unpaved", surfaceMinzoom) - end + local surface = GetSurface() + if surface ~= "" then Attribute("surface", surface, surfaceMinzoom) end if Holds("access") then Attribute("access", Find("access"), accessMinzoom) end if Holds("bicycle") then Attribute("bicycle", Find("bicycle"), accessMinzoom) end if Holds("foot") then Attribute("foot", Find("foot"), accessMinzoom) end @@ -353,6 +351,18 @@ function write_to_transportation_layer(minzoom, highway_class, subclass, ramp, s end end +function GetSurface() + local surface = split(Find("surface"), ";") + -- prioritize unpaved + for _, surfaceEntry in ipairs(surface) do + if unpavedValues[surfaceEntry] then return "unpaved" end + end + for _, surfaceEntry in ipairs(surface) do + if pavedValues[surfaceEntry] then return "paved" end + end + return "" +end + -- Process way tags function way_function() @@ -424,7 +434,7 @@ function way_function() -- https://openmaptiles.org/schema/#boundary if isBoundary and not (Find("maritime")=="yes") then local mz = 0 - if admin_level>=3 and admin_level<5 then mz=4 + if admin_level>=3 and admin_level<5 then mz=3 elseif admin_level>=5 and admin_level<7 then mz=8 elseif admin_level==7 then mz=10 elseif admin_level>=8 then mz=12 @@ -472,9 +482,9 @@ function way_function() under_construction = true end local minzoom = INVALID_ZOOM - if majorRoadValues[h] then minzoom = 4 - elseif h == "trunk" then minzoom = 5 - elseif highway == "primary" then minzoom = 7 + if z4RoadValues[h] then minzoom = 4 + elseif z5RoadValues[h] then minzoom = 5 + elseif z7RoadValues[h] then minzoom = 7 elseif z9RoadValues[h] then minzoom = 9 elseif z10RoadValues[h] then minzoom = 10 elseif z11RoadValues[h] then minzoom = 11 @@ -604,16 +614,16 @@ function way_function() -- 'aerodrome_label' if aeroway=="aerodrome" then - LayerAsCentroid("aerodrome_label") - SetNameAttributes() - Attribute("iata", Find("iata")) - SetEleAttributes() - Attribute("icao", Find("icao")) + LayerAsCentroid("aerodrome_label") + SetNameAttributes() + Attribute("iata", Find("iata")) + SetEleAttributes() + Attribute("icao", Find("icao")) - local aerodrome = Find(aeroway) - local class - if aerodromeValues[aerodrome] then class = aerodrome else class = "other" end - Attribute("class", class) + local aerodrome = Find(aeroway) + local class + if aerodromeValues[aerodrome] then class = aerodrome else class = "other" end + Attribute("class", class) end -- Set 'waterway' and associated @@ -662,7 +672,7 @@ function way_function() local class="lake"; if waterway~="" then class="river" end if class=="lake" and Find("wikidata")=="Q192770" then return end Layer("water",true) - SetMinZoomByArea(way) + SetMinZoomByArea() Attribute("class",class) if Find("intermittent")=="yes" then Attribute("intermittent",1) end @@ -802,13 +812,13 @@ end -- Set ele and ele_ft on any object function SetEleAttributes() - local ele = Find("ele") + local ele = Find("ele") if ele ~= "" then local meter = math.floor(tonumber(ele) or 0) local feet = math.floor(meter * 3.2808399) AttributeNumeric("ele", meter) AttributeNumeric("ele_ft", feet) - end + end end function SetBrunnelAttributes() @@ -826,7 +836,9 @@ end -- Set minimum zoom level by area but not below given minzoom function SetMinZoomByAreaWithLimit(minzoom) local area=Area() - if minzoom <= 6 and area>ZRES5^2 then MinZoom(6) + if minzoom <= 4 and area>ZRES3^2 then MinZoom(4) + elseif minzoom <= 5 and area>ZRES4^2 then MinZoom(5) + elseif minzoom <= 6 and area>ZRES5^2 then MinZoom(6) elseif minzoom <= 7 and area>ZRES6^2 then MinZoom(7) elseif minzoom <= 8 and area>ZRES7^2 then MinZoom(8) elseif minzoom <= 9 and area>ZRES8^2 then MinZoom(9) From bcd32ec4e714b7dc9c55f0478f8f5bbf7f07f3f1 Mon Sep 17 00:00:00 2001 From: adrian Date: Wed, 25 Jun 2025 09:04:41 -0400 Subject: [PATCH 2/5] SetMinZoomByAreaWithLimit allow zoom level 3, fix some whitespace. --- resources/process-openmaptiles.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index 15a0755b..d5f21a2b 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -30,6 +30,7 @@ function Set(list) end -- Meters per pixel if tile is 256x256 +ZRES2 = 39135.68 ZRES3 = 19567.88 ZRES4 = 9783.94 ZRES5 = 4891.97 @@ -222,9 +223,9 @@ end z4RoadValues = Set { "motorway" } z5RoadValues = Set { "trunk" } z7RoadValues = Set { "primary" } -z9RoadValues = Set { "secondary", "motorway_link", "trunk_link" } -z10RoadValues = Set { "primary_link", "secondary_link" } -z11RoadValues = Set { "tertiary", "tertiary_link", "busway", "bus_guideway" } +z9RoadValues = Set { "secondary", "motorway_link", "trunk_link" } +z10RoadValues = Set { "primary_link", "secondary_link" } +z11RoadValues = Set { "tertiary", "tertiary_link", "busway", "bus_guideway" } -- On zoom 12, various road classes are merged into "minor" z12MinorRoadValues = Set { "unclassified", "residential", "road", "living_street" } z12OtherRoadValues = Set { "raceway" } @@ -836,7 +837,8 @@ end -- Set minimum zoom level by area but not below given minzoom function SetMinZoomByAreaWithLimit(minzoom) local area=Area() - if minzoom <= 4 and area>ZRES3^2 then MinZoom(4) + if minzoom <= 3 and area>ZRES2^2 then MinZoom(3) + elseif minzoom <= 4 and area>ZRES3^2 then MinZoom(4) elseif minzoom <= 5 and area>ZRES4^2 then MinZoom(5) elseif minzoom <= 6 and area>ZRES5^2 then MinZoom(6) elseif minzoom <= 7 and area>ZRES6^2 then MinZoom(7) From 2dc44b1188432010dafae6c1e274979257fa41e0 Mon Sep 17 00:00:00 2001 From: adrian Date: Wed, 25 Jun 2025 09:14:18 -0400 Subject: [PATCH 3/5] recalculate constants: using 40.075e6 --- resources/process-openmaptiles.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index d5f21a2b..3564db11 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -30,8 +30,10 @@ function Set(list) end -- Meters per pixel if tile is 256x256 -ZRES2 = 39135.68 -ZRES3 = 19567.88 +ZRES0 = 156542.97 +ZRES1 = 78271.48 +ZRES2 = 39135.74 +ZRES3 = 19567.87 ZRES4 = 9783.94 ZRES5 = 4891.97 ZRES6 = 2445.98 From 3468535cea492f41f95a6c221a950c184bdf97df Mon Sep 17 00:00:00 2001 From: adrian Date: Wed, 25 Jun 2025 09:17:48 -0400 Subject: [PATCH 4/5] SetMinZoomByAreaWithLimit allow zoom level 1. --- resources/process-openmaptiles.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index 3564db11..d9b397e5 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -839,7 +839,9 @@ end -- Set minimum zoom level by area but not below given minzoom function SetMinZoomByAreaWithLimit(minzoom) local area=Area() - if minzoom <= 3 and area>ZRES2^2 then MinZoom(3) + if minzoom <= 1 and area>ZRES0^2 then MinZoom(1) + elseif minzoom <= 2 and area>ZRES1^2 then MinZoom(2) + elseif minzoom <= 3 and area>ZRES2^2 then MinZoom(3) elseif minzoom <= 4 and area>ZRES3^2 then MinZoom(4) elseif minzoom <= 5 and area>ZRES4^2 then MinZoom(5) elseif minzoom <= 6 and area>ZRES5^2 then MinZoom(6) From 04088fd42e468b0c0b7ddf3e6834a2f0486403d7 Mon Sep 17 00:00:00 2001 From: adrian Date: Fri, 8 Aug 2025 08:38:05 -0400 Subject: [PATCH 5/5] fix bug with name: do not set an unset name. --- resources/process-openmaptiles.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index d9b397e5..9909a240 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -802,14 +802,14 @@ function SetNameAttributes() if iname~=name and default_language_attribute then Attribute(default_language_attribute, name) else main_written = iname end - else + elseif name ~= "" then Attribute(preferred_language_attribute, name) end -- then set any additional languages for i,lang in ipairs(additional_languages) do iname = Find("name:"..lang) if iname=="" then iname=name end - if iname~=main_written then Attribute("name:"..lang, iname) end + if iname~=main_written and iname ~= "" then Attribute("name:"..lang, iname) end end end