From 99a56c00bd438d8de0912b02d602c5178de54406 Mon Sep 17 00:00:00 2001 From: Michael Reichert Date: Fri, 22 Sep 2023 16:28:44 +0200 Subject: [PATCH 1/3] Add missing attributes to transportation layer This adds following attributes according to the documentation: surface, mtb_scale, expressway, access, bicycle, foot, horse, toll, layer --- resources/config-openmaptiles.json | 6 ++- resources/process-openmaptiles.lua | 78 +++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/resources/config-openmaptiles.json b/resources/config-openmaptiles.json index 3cb1a3be..33114096 100644 --- a/resources/config-openmaptiles.json +++ b/resources/config-openmaptiles.json @@ -11,7 +11,11 @@ "waterway": { "minzoom": 8, "maxzoom": 14, "simplify_below": 12, "simplify_level": 0.0003, "simplify_ratio": 2 }, "waterway_detail": { "minzoom": 12, "maxzoom": 14, "write_to": "waterway" }, - "transportation": { "minzoom": 4, "maxzoom": 14, "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation": { "minzoom": 12, "maxzoom": 14, "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation_4": { "minzoom": 4, "maxzoom": 8, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation_7": { "minzoom": 7, "maxzoom": 8, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation_9": { "minzoom": 9, "maxzoom": 9, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation_10": { "minzoom": 10, "maxzoom": 10, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, "transportation_name": { "minzoom": 8, "maxzoom": 14 }, "transportation_name_mid": { "minzoom": 12, "maxzoom": 14, "write_to": "transportation_name" }, "transportation_name_detail": { "minzoom": 14, "maxzoom": 14, "write_to": "transportation_name" }, diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index c121eb52..960db249 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -45,6 +45,8 @@ BUILDING_FLOOR_HEIGHT = 3.66 -- 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" } -- Process node tags @@ -212,6 +214,53 @@ function relation_scan_function(relation) end end +function write_to_transportation_layer(way, minzoom, zoom, highway_class) + if minzoom > zoom then + return + end + local layer = "transportation_" .. tostring(zoom) + if zoom == 14 then + layer = "transportation" + end + way:Layer(layer, false) + way:MinZoom(minzoom) + SetZOrder(way) + way:Attribute("class", highway_class) + SetBrunnelAttributes(way) + if ramp then way:AttributeNumeric("ramp",1) end + + -- Service + if highway == "service" and service ~="" then way:Attribute("service", service) end + + local oneway = way:Find("oneway") + if oneway == "yes" or oneway == "1" then + way:AttributeNumeric("oneway",1) + end + if oneway == "-1" then + -- **** TODO + end + local surface = way:Find("surface") + if zoom >= 12 and pavedValues[surface] then + way:Attribute("surface", "paved") + elseif zoom >= 12 and unpavedValues[surface] then + way:Attribute("surface", "unpaved") + end + if zoom >= 9 then + if way:Holds("access") then way:Attribute("access", way:Find("access")) end + if way:Holds("bicycle") then way:Attribute("bicycle", way:Find("bicycle")) end + if way:Holds("foot") then way:Attribute("foot", way:Find("foot")) end + if way:Holds("horse") then way:Attribute("horse", way:Find("horse")) end + way:AttributeBoolean("toll", way:Find("toll") == "yes") + way:AttributeNumeric("layer", tonumber(way:Find("layer")) or 0) + end + if zoom >= 7 then + way:AttributeBoolean("expressway", way:Find("expressway")) + end + if zoom >= 10 and way:Holds("mtb:scale") then + way:Attribute("mtb_scale", way:Find("mtb:scale")) + end +end + -- Process way tags function way_function(way) @@ -331,30 +380,11 @@ function way_function(way) -- Write to layer if minzoom <= 14 then - way:Layer(layer, false) - way:MinZoom(minzoom) - SetZOrder(way) - way:Attribute("class", h) - SetBrunnelAttributes(way) - if ramp then way:AttributeNumeric("ramp",1) end - if access=="private" or access=="no" then way:Attribute("access", "no") end - if pavedValues[surface] then way:Attribute("surface", "paved") end - if unpavedValues[surface] then way:Attribute("surface", "unpaved") end - if way:Holds("bicycle") then way:Attribute("bicycle", way:Find("bicycle")) end - if way:Holds("foot") then way:Attribute("foot", way:Find("foot")) end - if way:Holds("horse") then way:Attribute("horse", way:Find("horse")) end - if way:Holds("mtb:scale") then way:Attribute("mtb_scale", way:Find("mtb:scale")) end - - -- Service - if highway == "service" and service ~="" then way:Attribute("service", service) end - - local oneway = way:Find("oneway") - if oneway == "yes" or oneway == "1" then - way:AttributeNumeric("oneway",1) - end - if oneway == "-1" then - -- **** TODO - end + write_to_transportation_layer(way, minzoom, 4, h) + write_to_transportation_layer(way, minzoom, 7, h) + write_to_transportation_layer(way, minzoom, 9, h) + write_to_transportation_layer(way, minzoom, 10, h) + write_to_transportation_layer(way, minzoom, 14, h) -- Write names if minzoom < 8 then From c528f94bf246744ec51c9bba4fb70e438de33e4b Mon Sep 17 00:00:00 2001 From: Michael Reichert Date: Tue, 26 Sep 2023 13:20:02 +0200 Subject: [PATCH 2/3] Add rank and capital attribute to places layer Original OpenMapTiles joins ne_10m_populated_places and OSM places by their Wikidata ID (and names as fallback). We do not use NaturalEarth, therefore we rely on population and capital only to calculate the rank. --- resources/process-openmaptiles.lua | 71 +++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index 960db249..2fd18712 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -51,6 +51,73 @@ unpavedValues = Set { "unpaved", "compacted", "dirt", "earth", "fine_gravel", "g -- Process node tags node_keys = { "addr:housenumber","aerialway","aeroway","amenity","barrier","highway","historic","leisure","natural","office","place","railway","shop","sport","tourism","waterway" } + +-- Get admin level which the place node is capital of. +-- Returns nil in case of invalid capital and for places which are not capitals. +function capitalLevel(capital) + local capital_al = tonumber(capital) or 0 + if capital == "yes" then + capital_al = 2 + end + if capital_al == 0 then + return nil + end + return capital_al +end + +-- Calculate rank for place nodes +-- place: value of place=* +-- popuplation: population as number +-- capital_al: result of capitalLevel() +function calcRank(place, population, capital_al) + local rank = 0 + if capital_al and capital_al >= 2 and capital_al <= 4 then + rank = capital_al + if population > 3 * 10^6 then + rank = rank - 2 + elseif population > 1 * 10^6 then + rank = rank - 1 + elseif population < 100000 then + rank = rank + 2 + elseif population < 50000 then + rank = rank + 3 + end + -- Safety measure to avoid place=village/farm/... appear early (as important capital) because a mapper added capital=yes/2/3/4 + if place ~= "city" then + rank = rank + 3 + -- Decrease rank further if it is not even a town. + if place ~= "town" then + rank = rank + 2 + end + end + return rank + end + if place ~= "city" and place ~= "town" then + return nil + end + if population > 3 * 10^6 then + return 1 + elseif population > 1 * 10^6 then + return 2 + elseif population > 500000 then + return 3 + elseif population > 200000 then + return 4 + elseif population > 100000 then + return 5 + elseif population > 75000 then + return 6 + elseif population > 50000 then + return 7 + elseif population > 25000 then + return 8 + elseif population > 10000 then + return 9 + end + return 10 +end + + function node_function(node) -- Write 'aerodrome_label' local aeroway = node:Find("aeroway") @@ -78,9 +145,10 @@ function node_function(node) -- we could potentially approximate it for cities based on the population tag local place = node:Find("place") if place ~= "" then - local rank = nil local mz = 13 local pop = tonumber(node:Find("population")) or 0 + local capital = capitalLevel(node:Find("capital")) + local rank = calcRank(place, pop, capital) if place == "continent" then mz=0 elseif place == "country" then @@ -103,6 +171,7 @@ function node_function(node) node:Attribute("class", place) node:MinZoom(mz) if rank then node:AttributeNumeric("rank", rank) end + if capital then node:AttributeNumeric("capital", capital) end if place=="country" then node:Attribute("iso_a2", node:Find("ISO3166-1:alpha2")) end SetNameAttributes(node) return From bc318b400a0dbe4f445f11b0d89482794b177f18 Mon Sep 17 00:00:00 2001 From: Michael Reichert Date: Fri, 17 Nov 2023 13:09:24 +0100 Subject: [PATCH 3/3] Simplify code Make use of the new way:Attribute(name, value, minzoom) function. --- resources/config-openmaptiles.json | 6 +--- resources/process-openmaptiles.lua | 51 +++++++++++------------------- 2 files changed, 19 insertions(+), 38 deletions(-) diff --git a/resources/config-openmaptiles.json b/resources/config-openmaptiles.json index 33114096..3cb1a3be 100644 --- a/resources/config-openmaptiles.json +++ b/resources/config-openmaptiles.json @@ -11,11 +11,7 @@ "waterway": { "minzoom": 8, "maxzoom": 14, "simplify_below": 12, "simplify_level": 0.0003, "simplify_ratio": 2 }, "waterway_detail": { "minzoom": 12, "maxzoom": 14, "write_to": "waterway" }, - "transportation": { "minzoom": 12, "maxzoom": 14, "simplify_below": 13, "simplify_level": 0.0003 }, - "transportation_4": { "minzoom": 4, "maxzoom": 8, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, - "transportation_7": { "minzoom": 7, "maxzoom": 8, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, - "transportation_9": { "minzoom": 9, "maxzoom": 9, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, - "transportation_10": { "minzoom": 10, "maxzoom": 10, "write_to": "transportation", "simplify_below": 13, "simplify_level": 0.0003 }, + "transportation": { "minzoom": 4, "maxzoom": 14, "simplify_below": 13, "simplify_level": 0.0003 }, "transportation_name": { "minzoom": 8, "maxzoom": 14 }, "transportation_name_mid": { "minzoom": 12, "maxzoom": 14, "write_to": "transportation_name" }, "transportation_name_detail": { "minzoom": 14, "maxzoom": 14, "write_to": "transportation_name" }, diff --git a/resources/process-openmaptiles.lua b/resources/process-openmaptiles.lua index 2fd18712..9a386a0b 100644 --- a/resources/process-openmaptiles.lua +++ b/resources/process-openmaptiles.lua @@ -283,15 +283,8 @@ function relation_scan_function(relation) end end -function write_to_transportation_layer(way, minzoom, zoom, highway_class) - if minzoom > zoom then - return - end - local layer = "transportation_" .. tostring(zoom) - if zoom == 14 then - layer = "transportation" - end - way:Layer(layer, false) +function write_to_transportation_layer(way, minzoom, highway_class) + way:Layer("transportation", false) way:MinZoom(minzoom) SetZOrder(way) way:Attribute("class", highway_class) @@ -309,25 +302,21 @@ function write_to_transportation_layer(way, minzoom, zoom, highway_class) -- **** TODO end local surface = way:Find("surface") - if zoom >= 12 and pavedValues[surface] then - way:Attribute("surface", "paved") - elseif zoom >= 12 and unpavedValues[surface] then - way:Attribute("surface", "unpaved") - end - if zoom >= 9 then - if way:Holds("access") then way:Attribute("access", way:Find("access")) end - if way:Holds("bicycle") then way:Attribute("bicycle", way:Find("bicycle")) end - if way:Holds("foot") then way:Attribute("foot", way:Find("foot")) end - if way:Holds("horse") then way:Attribute("horse", way:Find("horse")) end - way:AttributeBoolean("toll", way:Find("toll") == "yes") - way:AttributeNumeric("layer", tonumber(way:Find("layer")) or 0) - end - if zoom >= 7 then - way:AttributeBoolean("expressway", way:Find("expressway")) - end - if zoom >= 10 and way:Holds("mtb:scale") then - way:Attribute("mtb_scale", way:Find("mtb:scale")) - end + local surfaceMinzoom = 12 + if pavedValues[surface] then + way:Attribute("surface", "paved", surfaceMinzoom) + elseif unpavedValues[surface] then + way:Attribute("surface", "unpaved", surfaceMinzoom) + end + local accessMinzoom = 9 + if way:Holds("access") then way:Attribute("access", way:Find("access"), accessMinzoom) end + if way:Holds("bicycle") then way:Attribute("bicycle", way:Find("bicycle"), accessMinzoom) end + if way:Holds("foot") then way:Attribute("foot", way:Find("foot"), accessMinzoom) end + if way:Holds("horse") then way:Attribute("horse", way:Find("horse"), accessMinzoom) end + way:AttributeBoolean("toll", way:Find("toll") == "yes", accessMinzoom) + way:AttributeNumeric("layer", tonumber(way:Find("layer")) or 0, accessMinzoom) + way:AttributeBoolean("expressway", way:Find("expressway"), 7) + way:Attribute("mtb_scale", way:Find("mtb:scale"), 10) end -- Process way tags @@ -449,11 +438,7 @@ function way_function(way) -- Write to layer if minzoom <= 14 then - write_to_transportation_layer(way, minzoom, 4, h) - write_to_transportation_layer(way, minzoom, 7, h) - write_to_transportation_layer(way, minzoom, 9, h) - write_to_transportation_layer(way, minzoom, 10, h) - write_to_transportation_layer(way, minzoom, 14, h) + write_to_transportation_layer(way, minzoom, h) -- Write names if minzoom < 8 then