From 1795e7b74661ab53e7b04d22ccc00520d2cdaf57 Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:00:32 +0100 Subject: [PATCH 01/23] replace `FilterTags()` with `CopyTags()` to avoid mutating `tags` --- app/process/barriers/barriers.lua | 14 +++---- app/process/boundaries/boundaries.lua | 1 - app/process/helper/FilterTags.lua | 21 ---------- app/process/landuse.lua | 13 +++--- app/process/places/places.lua | 16 +++----- app/process/places/places_todoList.lua | 17 +++----- .../poiClassification/poiClassification.lua | 41 ++++++++----------- .../poiClassification_todoList.lua | 23 ++++------- .../roads_bikelanes/maxspeed/Maxspeed.lua | 1 - 9 files changed, 46 insertions(+), 101 deletions(-) delete mode 100644 app/process/helper/FilterTags.lua diff --git a/app/process/barriers/barriers.lua b/app/process/barriers/barriers.lua index b4438912..34e9fc85 100644 --- a/app/process/barriers/barriers.lua +++ b/app/process/barriers/barriers.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("FilterTags") require("Metadata") require("HighwayClasses") @@ -24,7 +23,7 @@ local areaBarriers = osm2pgsql.define_table({ } }) -local allowedTags = Set({ +local tags_cc = { 'tunnel', 'waterway', 'aerodrome', @@ -36,7 +35,7 @@ local allowedTags = Set({ 'area', 'highway', 'bridge', -}) +} local function isAreaBarrier(object) local tags = object.tags @@ -67,9 +66,8 @@ end function osm2pgsql.process_way(object) if object.is_closed then -- process as polygon if isAreaBarrier(object) then - FilterTags(object.tags, allowedTags) areaBarriers:insert({ - tags = object.tags, + tags = CopyTags({}, object.tags, tags_cc), meta = Metadata(object), geom = object:as_multipolygon() }) @@ -89,9 +87,8 @@ function osm2pgsql.process_way(object) end if isBarrier then - FilterTags(object.tags, allowedTags) lineBarriers:insert({ - tags = object.tags, + tags = CopyTags({}, object.tags, tags_cc), meta = Metadata(object), geom = object:as_linestring(), }) @@ -102,9 +99,8 @@ end function osm2pgsql.process_relation(object) if isAreaBarrier(object) then - FilterTags(object.tags, allowedTags) areaBarriers:insert({ - tags = object.tags, + tags = CopyTags({}, object.tags, tags_cc), meta = Metadata(object), geom = object:as_multipolygon() }) diff --git a/app/process/boundaries/boundaries.lua b/app/process/boundaries/boundaries.lua index 4accf76a..b7dfbc76 100644 --- a/app/process/boundaries/boundaries.lua +++ b/app/process/boundaries/boundaries.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("FilterTags") require("Metadata") require("CopyTags") diff --git a/app/process/helper/FilterTags.lua b/app/process/helper/FilterTags.lua deleted file mode 100644 index 8d88a114..00000000 --- a/app/process/helper/FilterTags.lua +++ /dev/null @@ -1,21 +0,0 @@ --- Playground http://tpcg.io/_5LRFVV - --- @desc: Reminder: Mutates input object -function FilterTags(tags, allowedTags) - for key, _ in pairs(tags) do - if not allowedTags[key] then - tags[key] = nil - end - end -end - --- this function is faster iff |tags| > |allowedTags| --- function FilterTags2(tags, allowedTags) --- local tagsFiltered = {} --- for key, _ in pairs(allowedTags) do --- if tags[key] ~= nil then --- tagsFiltered[key] = tags[key] --- end --- end --- return tagsFiltered --- end diff --git a/app/process/landuse.lua b/app/process/landuse.lua index 520880e8..41915bca 100644 --- a/app/process/landuse.lua +++ b/app/process/landuse.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("FilterTags") require("MergeArray") require("Metadata") @@ -48,8 +47,8 @@ end local function processTags(tags) -- For simplicy, we move the amenity values to the landuse key tags.landuse = tags.landuse or tags.amenity - local allowed_tags = Set({ "name", "landuse", "access", "operator" }) - FilterTags(tags, allowed_tags) + local tags_cc = { "name", "landuse", "access", "operator" } + return CopyTags({}, tags, tags_cc) end function osm2pgsql.process_way(object) @@ -57,10 +56,8 @@ function osm2pgsql.process_way(object) return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_polygon() }) @@ -71,10 +68,10 @@ function osm2pgsql.process_relation(object) return end - processTags(object.tags) + table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_multipolygon() }) diff --git a/app/process/places/places.lua b/app/process/places/places.lua index 80cbdbc5..5837c5bf 100644 --- a/app/process/places/places.lua +++ b/app/process/places/places.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("FilterTags") require("MergeArray") require("Metadata") @@ -36,19 +35,17 @@ local function ExitProcessing(object) end local function processTags(tags) - local allowed_tags = Set({ "name", "place", "capital", "website", "wikidata", "wikipedia", "population", + local tags_cc = Set({ "name", "place", "capital", "website", "wikidata", "wikipedia", "population", "population:date", "admin_level" }) - FilterTags(tags, allowed_tags) tags.population = tonumber(tags.population) + return CopyTags({}, tags, tags_cc) end function osm2pgsql.process_node(object) if ExitProcessing(object) then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_point() }) @@ -58,10 +55,8 @@ function osm2pgsql.process_way(object) if ExitProcessing(object) then return end if not object.is_closed then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_polygon():centroid() }) @@ -71,9 +66,8 @@ function osm2pgsql.process_relation(object) if ExitProcessing(object) then return end if not object.tags.type == 'multipolygon' then return end - processTags(object.tags) table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_multipolygon():centroid() }) diff --git a/app/process/places/places_todoList.lua b/app/process/places/places_todoList.lua index 93c8de37..82931242 100644 --- a/app/process/places/places_todoList.lua +++ b/app/process/places/places_todoList.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("FilterTags") require("MergeArray") require("Metadata") @@ -49,19 +48,17 @@ local function ContinueProcess(object) end local function processTags(tags) - local allowed_tags = Set({ "_todos", "name", "place", "capital", "website", "wikidata", "wikipedia", "population", + local tags_cc = Set({ "_todos", "name", "place", "capital", "website", "wikidata", "wikipedia", "population", "population:date", "admin_level" }) - FilterTags(tags, allowed_tags) + return CopyTags({}, tags, tags_cc) -- tags.population = tonumber(tags.population) end function osm2pgsql.process_node(object) if not ContinueProcess(object) then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_point() }) @@ -71,10 +68,8 @@ function osm2pgsql.process_way(object) if not ContinueProcess(object) then return end if not object.is_closed then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_polygon():centroid() }) @@ -84,10 +79,8 @@ function osm2pgsql.process_relation(object) if not ContinueProcess(object) then return end if not object.tags.type == 'multipolygon' then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_multipolygon():centroid() }) diff --git a/app/process/poiClassification/poiClassification.lua b/app/process/poiClassification/poiClassification.lua index 7574f821..9aa8c6b0 100644 --- a/app/process/poiClassification/poiClassification.lua +++ b/app/process/poiClassification/poiClassification.lua @@ -2,10 +2,10 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua;/app/process/poiClassification/?.lua" require("Set") require("ExtractKeys") -require("FilterTags") require("InferAddress") require("MergeArray") require("Metadata") +require("Sanitize") -- Shared: require("ShoppingAllowedListWithCategories") @@ -59,21 +59,22 @@ end local function processTags(tags) -- Set our custom `category` value with one of our 4 values. -- We also introduce `type` as a unified way to speicify the shop-or-amenity type. + local results = InferAddress(tags) if tags.shop then - tags.category = 'Einkauf' - tags.type = "shop-" .. tags.shop + results.category = 'Einkauf' + results.type = "shop-" .. tags.shop end if tags.amenity then - tags.category = ShoppingAllowedListWithCategories[tags.amenity] - tags.type = "amenity-" .. tags.amenity + results.category = ShoppingAllowedListWithCategories[tags.amenity] + results.type = "amenity-" .. tags.amenity end if tags.tourism then - tags.category = ShoppingAllowedListWithCategories[tags.tourism] - tags.type = "tourism-" .. tags.tourism + results.category = ShoppingAllowedListWithCategories[tags.tourism] + results.type = "tourism-" .. tags.tourism end if tags.leisure then - tags.category = ShoppingAllowedListWithCategories[tags.leisure] - tags.type = "leisure-" .. tags.leisure + results.category = ShoppingAllowedListWithCategories[tags.leisure] + results.type = "leisure-" .. tags.leisure end -- This part was previously a separate dataset "education" @@ -85,22 +86,18 @@ local function processTags(tags) "school", "university" }) - if formalEducation[tags.amenity] then - tags.formalEducation = tags.amenity - end + results.formalEducation = Sanitize(tags.amenity, formalEducation) - InferAddress(tags, tags) - local allowed_tags = MergeArray({ "name", "category", "type", "formalEducation" }, AddressKeys) - FilterTags(tags, Set(allowed_tags)) + local tags_cc = { "name" } + CopyTags(results, tags, tags_cc) + return results end function osm2pgsql.process_node(object) if ExitProcessing(object) then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_point() }) @@ -110,10 +107,8 @@ function osm2pgsql.process_way(object) if ExitProcessing(object) then return end if not object.is_closed then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_polygon():centroid() }) @@ -123,10 +118,8 @@ function osm2pgsql.process_relation(object) if ExitProcessing(object) then return end if not object.tags.type == 'multipolygon' then return end - processTags(object.tags) - table:insert({ - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_multipolygon():centroid() }) diff --git a/app/process/poiClassification/poiClassification_todoList.lua b/app/process/poiClassification/poiClassification_todoList.lua index 370f5b9d..f967afbf 100644 --- a/app/process/poiClassification/poiClassification_todoList.lua +++ b/app/process/poiClassification/poiClassification_todoList.lua @@ -2,7 +2,6 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua;/app/process/poiClassification/?.lua" require("Set") require("ExtractKeys") -require("FilterTags") require("InferAddress") require("MergeArray") require("Metadata") @@ -166,26 +165,25 @@ end -- Tag processing extracted to be used inside projcess_* local function processTags(tags) - InferAddress(tags, tags) - local allowed_tags = MergeArray({ "name", "amenity", "tourism" }, AddressKeys) - FilterTags(tags, Set(allowed_tags)) + local results = InferAddress(tags) + local tags_cc = { "name", "amenity", "tourism" } + CopyTags(results, tags, tags_cc) if (tags.amenity) then - tags.taginfo_url = "https://taginfo.openstreetmap.org/tags/amenity=" .. tags.amenity + results.taginfo_url = "https://taginfo.openstreetmap.org/tags/amenity=" .. tags.amenity end if (tags.tourism) then - tags.taginfo_url = "https://taginfo.openstreetmap.org/tags/tourism=" .. tags.tourism + results.taginfo_url = "https://taginfo.openstreetmap.org/tags/tourism=" .. tags.tourism end + return results end function osm2pgsql.process_node(object) if ExitProcessing(object) then return end - processTags(object.tags) - table:insert({ value_to_check = object.tags.amenity or object.tags.shop or object.tags.tourism, - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_point() }) @@ -196,11 +194,9 @@ function osm2pgsql.process_way(object) return end - processTags(object.tags) - table:insert({ value_to_check = object.tags.amenity or object.tags.shop or object.tags.tourism, - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_polygon():centroid() }) @@ -210,10 +206,9 @@ function osm2pgsql.process_relation(object) if ExitProcessing(object) then return end if not object.tags.type == 'multipolygon' then return end - processTags(object.tags) table:insert({ value_to_check = object.tags.amenity or object.tags.shop or object.tags.tourism, - tags = object.tags, + tags = processTags(object.tags), meta = Metadata(object), geom = object:as_multipolygon():centroid() }) diff --git a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua index 847730f8..9007b69a 100644 --- a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua +++ b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua @@ -43,7 +43,6 @@ function Maxspeed(object) CopyTags(maxspeed_data, tags, tags_cc, "osm_") - -- Freshness of data (AFTER `FilterTags`!) -- 700+ https://taginfo.openstreetmap.org/keys/check_date%3Amaxspeed if tags["check_date:maxspeed"] then maxspeed_data.maxspeed_age = AgeInDays(ParseDate(tags["check_date:maxspeed"])) From b35bbb19364f0a3113963acd3a8ac6f94d66551d Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:00:40 +0100 Subject: [PATCH 02/23] add function signatures --- app/process/helper/CopyTags.lua | 6 ++++++ app/process/helper/MergeTable.lua | 5 ++++- app/process/helper/Sanitize.lua | 4 ++++ app/process/shared/InferAddress.lua | 20 +++++++++++--------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/process/helper/CopyTags.lua b/app/process/helper/CopyTags.lua index 152e47c8..e49774a5 100644 --- a/app/process/helper/CopyTags.lua +++ b/app/process/helper/CopyTags.lua @@ -1,3 +1,9 @@ +---@param dst table +---@param src table +---@param tags table +---@param prefix? string +---@return table +-- Copy the given `tags` from table `src` to table `dst` function CopyTags(dst, src, tags, prefix) prefix = prefix or '' for _, val in pairs(tags) do diff --git a/app/process/helper/MergeTable.lua b/app/process/helper/MergeTable.lua index 1395691a..1a3c59d1 100644 --- a/app/process/helper/MergeTable.lua +++ b/app/process/helper/MergeTable.lua @@ -1,4 +1,7 @@ --- Copy all key value pairs from src to dst +---@param dst table +---@param src table +---@return table +-- Copy all key value pairs from `src` to `dst` function MergeTable(dst, src) for k, v in pairs(src) do dst[k] = v diff --git a/app/process/helper/Sanitize.lua b/app/process/helper/Sanitize.lua index 9af0399c..d9b1eed6 100644 --- a/app/process/helper/Sanitize.lua +++ b/app/process/helper/Sanitize.lua @@ -1,3 +1,7 @@ +---@param value any +---@param allowed table +---@param default any +---@return any -- makes sure that `value` is in the set `allowed`. Returns `default` if value is nil function Sanitize(value, allowed, default) if value == nil then diff --git a/app/process/shared/InferAddress.lua b/app/process/shared/InferAddress.lua index 40c7508e..f9429ac4 100644 --- a/app/process/shared/InferAddress.lua +++ b/app/process/shared/InferAddress.lua @@ -3,15 +3,17 @@ -- * @returns -- `dest` if provided with `AddressKeys` added to it. -- Otherwise a new object of format `AddressKeys` is returned. -function InferAddress(tags, dest) - dest = dest or {} +---comment +---@param tags table +---@param dst? table +---@return table +function InferAddress(tags, dst) + dst = dst or {} - dest.addr_street = tags.street or tags["addr:street"] - dest.addr_zip = tags.postcode or tags["addr:postcode"] - dest.addr_city = tags.city or tags["addr:city"] - dest.addr_number = tags.housenumber or tags["addr:housenumber"] + dst.addr_street = tags.street or tags["addr:street"] + dst.addr_zip = tags.postcode or tags["addr:postcode"] + dst.addr_city = tags.city or tags["addr:city"] + dst.addr_number = tags.housenumber or tags["addr:housenumber"] - return dest + return dst end - -AddressKeys = { "addr_street", "addr_zip", "addr_city", "addr_number" } From aa2a5e61098bdee0aa97c0ce6b64d9202e9d2330 Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:12:13 +0100 Subject: [PATCH 03/23] name resulting tag object: `results` --- app/process/bicycleParking/bicycleParking.lua | 20 +++++------ app/process/boundaries/boundaries.lua | 34 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/process/bicycleParking/bicycleParking.lua b/app/process/bicycleParking/bicycleParking.lua index 9e63fc7f..0a990aee 100644 --- a/app/process/bicycleParking/bicycleParking.lua +++ b/app/process/bicycleParking/bicycleParking.lua @@ -53,13 +53,13 @@ end local function processTags(tags) -- this is the list of tags found in the wiki: https://wiki.openstreetmap.org/wiki/Tag:amenity%3Dbicycle_parking -- also https://wiki.openstreetmap.org/wiki/Berlin/Verkehrswende/Fahrradparkpl%C3%A4tze - local processedTags = capacityNormalization(tags) + local results = capacityNormalization(tags) local binary = Set({ "yes", "no" }) - processedTags.access = Sanitize(tags.access, Set({ "yes", "private", "permissive", "customers" })) - processedTags.covered = Sanitize(tags.covered, binary, "implicit_no") - processedTags.fee = Sanitize(tags.fee, binary, "implicit_no") - processedTags.access_cargo_bike = Sanitize(tags.cargo_bike, binary, "implicit_no") - processedTags.bicycle_parking = Sanitize( + results.access = Sanitize(tags.access, Set({ "yes", "private", "permissive", "customers" })) + results.covered = Sanitize(tags.covered, binary, "implicit_no") + results.fee = Sanitize(tags.fee, binary, "implicit_no") + results.access_cargo_bike = Sanitize(tags.cargo_bike, binary, "implicit_no") + results.bicycle_parking = Sanitize( tags.bicycle_parking, Set({ "stands", "wide_stands", "bollard", "wall_loops", "shed", "two-tier", "lockers" }) ) @@ -78,14 +78,14 @@ local function processTags(tags) "mapillary", "description", } - CopyTags(processedTags, tags, allowed_tags) - CopyTags(processedTags, tags, tags_cc, "osm_") + CopyTags(results, tags, allowed_tags) + CopyTags(results, tags, tags_cc, "osm_") local checkDateTag = "check_date" if tags[checkDateTag] then - processedTags.age = AgeInDays(ParseDate(tags[checkDateTag])) + results.age = AgeInDays(ParseDate(tags[checkDateTag])) end - return processedTags + return results end function osm2pgsql.process_node(object) diff --git a/app/process/boundaries/boundaries.lua b/app/process/boundaries/boundaries.lua index b7dfbc76..dc328037 100644 --- a/app/process/boundaries/boundaries.lua +++ b/app/process/boundaries/boundaries.lua @@ -40,30 +40,30 @@ function osm2pgsql.process_relation(object) return end - local results_tags = {} - results_tags.admin_level = tonumber(tags.admin_level) - results_tags.population = tonumber(tags.population) + local results = {} + results.admin_level = tonumber(tags.admin_level) + results.population = tonumber(tags.population) -- Categories: - if (results_tags.admin_level == 8) then - results_tags.category_municipality = "Gemeinde" + if (results.admin_level == 8) then + results.category_municipality = "Gemeinde" end - if (results_tags.admin_level == 6) then - results_tags.category_district = "Landkreis" + if (results.admin_level == 6) then + results.category_district = "Landkreis" if (tags.place == "city" or tags["name:prefix"] == "Kreisfreie Stadt") then - results_tags.category_municipality = "Kreisfreie Stadt" - results_tags.category_district = "Kreisfreie Stadt" + results.category_municipality = "Kreisfreie Stadt" + results.category_district = "Kreisfreie Stadt" end end - if (results_tags.admin_level == 4 and tags.place == "city") then - results_tags.category_municipality = "Stadtstaat" - results_tags.category_district = "Stadtstaat" + if (results.admin_level == 4 and tags.place == "city") then + results.category_municipality = "Stadtstaat" + results.category_district = "Stadtstaat" end -- these tags are copied (Eigennamen) local allowed_tags = { "name", "name:prefix" } - CopyTags(results_tags, tags, allowed_tags) + CopyTags(results, tags, allowed_tags) -- these tags are copied and prefixed with `osm_` local tags_cc = { "de:regionalschluessel", "population:date", "wikidata", "wikipedia" } - CopyTags(results_tags, tags, tags_cc, "osm_") + CopyTags(results, tags, tags_cc, "osm_") -- Make sure we only include boundaries with a geometry -- https://osm2pgsql.org/doc/manual.html#processing-callbacks @@ -71,12 +71,12 @@ function osm2pgsql.process_relation(object) if object:as_multipolygon():is_null() then return end table:insert({ - tags = results_tags, + tags = results, meta = Metadata(object), geom = object:as_multipolygon() }) labelTable:insert({ - tags = results_tags, + tags = results, meta = Metadata(object), geom = object:as_multipolygon():centroid() }) @@ -84,7 +84,7 @@ function osm2pgsql.process_relation(object) local admin_levels = Set({ "4", "6", "7", "8" }) if admin_levels[tags.admin_level] then statsTable:insert({ - tags = results_tags, + tags = results, meta = Metadata(object), geom = object:as_multipolygon() }) From b527c1370f9c484b56632c64a8d93d003eab1e13 Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:12:30 +0100 Subject: [PATCH 04/23] add comment --- app/process/places/places.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/app/process/places/places.lua b/app/process/places/places.lua index 5837c5bf..68263d98 100644 --- a/app/process/places/places.lua +++ b/app/process/places/places.lua @@ -37,6 +37,7 @@ end local function processTags(tags) local tags_cc = Set({ "name", "place", "capital", "website", "wikidata", "wikipedia", "population", "population:date", "admin_level" }) + -- TODO: I don't think that we need the line bellow, osm2pgsql should convert this automatically tags.population = tonumber(tags.population) return CopyTags({}, tags, tags_cc) end From 60b2feed6272852385f1d233a1d5ff0b2647ff4e Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:22:42 +0100 Subject: [PATCH 05/23] evitate mutation of `tags` --- app/process/trafficSigns/trafficSigns.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/process/trafficSigns/trafficSigns.lua b/app/process/trafficSigns/trafficSigns.lua index d32ea39b..8060fbb3 100644 --- a/app/process/trafficSigns/trafficSigns.lua +++ b/app/process/trafficSigns/trafficSigns.lua @@ -45,13 +45,13 @@ local function splitDirections(tags) local directedTag = "traffic_sing:" .. direction local both = "traffic_sing:both" if tags[directedTag] or tags[both] then - traffic_signs[direction] = { ["traffic_sign"] = tags[directedTag] or tags[both], ["offset"] = offset, direction=tags.direction } + traffic_signs[direction] = { ["traffic_sign"] = tags[directedTag] or tags[both], ["offset"] = offset } elseif tags.direction == direction or tags.direction=="both" then traffic_signs[direction] = { ["traffic_sign"] = tags.traffic_sign, ["offset"] = offset } end end if traffic_signs.forward == nil and traffic_signs.backward == nil then - traffic_signs.forward = { ["traffic_sign"] = tags.traffic_sign, ["offset"] = 0, direction=tags.direction } + traffic_signs.forward = { ["traffic_sign"] = tags.traffic_sign, ["offset"] = 0 } end return { traffic_signs.forward, traffic_signs.backward } end @@ -99,25 +99,24 @@ function osm2pgsql.process_node(object) if ExitProcessing(object) then return end tags.direction = tags.direction or tags['traffic_sign:direction'] -- the tag `traffic_sign:direction` depicts the same as `direction` (give the original precedence) + local direction local direction_source = nil if tags.direction ~= nil then -- orinetation is given in degree - local direction = tonumber(tags.direction) + direction = tonumber(tags.direction) direction_source = 'tag_degrees' if direction == nil then -- orientation is given by a cardinal direction e.g. NW direction = cardinalDirection2Degree(tags.direction) direction_source = 'tag_cardinal' end - if direction ~= nil then -- one of the previous cases worked and we have a direction in degrees - tags.direction = direction - else -- we don't have a direction in degrees and now try to orient the traffic sign by the way it is part of + if direction == nil then -- we don't have a direction in degrees and now try to orient the traffic sign by the way it is part of to_orient[object.id] = true end end for _, traffic_sign in pairs(splitDirections(tags)) do -- here we possibly duplicate a node due to the possibility of two traffic signs per node + traffic_sign.direction = tonumber(direction) traffic_sign.direction_source = direction_source - traffic_sign.direction = tonumber(traffic_sign.direction) for k,v in pairs(tags) do traffic_sign['osm_' .. k] = v end table:insert({ tags = traffic_sign, From 2487023db32aa35c5806c9350034c81cb2515a3e Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 12 Feb 2024 13:30:59 +0100 Subject: [PATCH 06/23] remove outdated helper --- app/process/helper/MergeArray.lua | 9 --------- app/process/helper/PrintTable.lua | 16 ---------------- app/process/landuse.lua | 1 - app/process/places/places.lua | 1 - app/process/places/places_todoList.lua | 1 - .../poiClassification/poiClassification.lua | 1 - .../poiClassification_todoList.lua | 1 - app/process/publicTransport.lua | 1 - .../ConvertCyclewayOppositeSchema.test.lua | 7 ------- 9 files changed, 38 deletions(-) delete mode 100644 app/process/helper/MergeArray.lua delete mode 100644 app/process/helper/PrintTable.lua diff --git a/app/process/helper/MergeArray.lua b/app/process/helper/MergeArray.lua deleted file mode 100644 index 0e8820cd..00000000 --- a/app/process/helper/MergeArray.lua +++ /dev/null @@ -1,9 +0,0 @@ --- Demo http://tpcg.io/_HFSD73 --- Source https://stackoverflow.com/a/65600458/729221 - --- * @desc `MergeArray({ 'array1' }, { 'array2' })` --- * @returns `{ 'array1', 'array2' }` -function MergeArray(array1, array2) - for _, v in pairs(array2) do table.insert(array1, v) end - return array1 -end diff --git a/app/process/helper/PrintTable.lua b/app/process/helper/PrintTable.lua deleted file mode 100644 index ae6fe837..00000000 --- a/app/process/helper/PrintTable.lua +++ /dev/null @@ -1,16 +0,0 @@ -function PrintTable(table) - PrintTableWithHeadline(table, "(no headline)") -end - -function PrintTableWithHeadline(table, headline) - print("-- PrintTable -- " .. headline .. " --") - - if not table then - print('table is nil') - return - end - - for k, v in pairs(table) do - print(k .. ": " .. tostring(v)) - end -end diff --git a/app/process/landuse.lua b/app/process/landuse.lua index 41915bca..940520ab 100644 --- a/app/process/landuse.lua +++ b/app/process/landuse.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("MergeArray") require("Metadata") local table = osm2pgsql.define_table({ diff --git a/app/process/places/places.lua b/app/process/places/places.lua index 68263d98..f622bfed 100644 --- a/app/process/places/places.lua +++ b/app/process/places/places.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("MergeArray") require("Metadata") local table = osm2pgsql.define_table({ diff --git a/app/process/places/places_todoList.lua b/app/process/places/places_todoList.lua index 82931242..ff1d7588 100644 --- a/app/process/places/places_todoList.lua +++ b/app/process/places/places_todoList.lua @@ -1,6 +1,5 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") -require("MergeArray") require("Metadata") diff --git a/app/process/poiClassification/poiClassification.lua b/app/process/poiClassification/poiClassification.lua index 9aa8c6b0..e96ade82 100644 --- a/app/process/poiClassification/poiClassification.lua +++ b/app/process/poiClassification/poiClassification.lua @@ -3,7 +3,6 @@ package.path = package.path .. require("Set") require("ExtractKeys") require("InferAddress") -require("MergeArray") require("Metadata") require("Sanitize") diff --git a/app/process/poiClassification/poiClassification_todoList.lua b/app/process/poiClassification/poiClassification_todoList.lua index f967afbf..3c566be1 100644 --- a/app/process/poiClassification/poiClassification_todoList.lua +++ b/app/process/poiClassification/poiClassification_todoList.lua @@ -3,7 +3,6 @@ package.path = package.path .. require("Set") require("ExtractKeys") require("InferAddress") -require("MergeArray") require("Metadata") require("ShoppingAllowedListWithCategories") diff --git a/app/process/publicTransport.lua b/app/process/publicTransport.lua index 5f10872c..51a1376c 100644 --- a/app/process/publicTransport.lua +++ b/app/process/publicTransport.lua @@ -1,7 +1,6 @@ package.path = package.path .. ";/app/process/helper/?.lua;/app/process/shared/?.lua" require("Set") require("CopyTags") -require("MergeArray") require("Metadata") local table = osm2pgsql.define_table({ diff --git a/app/process/shared/__test__/ConvertCyclewayOppositeSchema.test.lua b/app/process/shared/__test__/ConvertCyclewayOppositeSchema.test.lua index 94477ad7..eaee0285 100644 --- a/app/process/shared/__test__/ConvertCyclewayOppositeSchema.test.lua +++ b/app/process/shared/__test__/ConvertCyclewayOppositeSchema.test.lua @@ -2,7 +2,6 @@ package.path = package.path .. ";./app/process/helper/?.lua;./app/process/shared require("CompareTables") require("ConvertCyclewayOppositeSchema") require("osm2pgsql") -require("PrintTable") require("DeepCopy") print('=== Test ConvertCyclewayOppositeSchema: do nothing ===') @@ -15,9 +14,7 @@ print('=== Test ConvertCyclewayOppositeSchema: handle opposite ===') local originalTags = { ["cycleway"] = "opposite",["oneway"] = "yes" } local tags = DeepCopy(originalTags) local expectedResult = { ["cycleway"] = "no",["oneway:bicycle"] = "no",["oneway"] = "yes" } --- PrintTableWithHeadline(tags, 'original tags') ConvertCyclewayOppositeSchema(tags) --- PrintTableWithHeadline(tags, 'modified tags') assert(CompareTables(tags, expectedResult)) print('=== Test ConvertCyclewayOppositeSchema: handle opposite_lane ===') @@ -29,9 +26,7 @@ local expectedResult = { ["oneway:bicycle"] = "no", ["oneway"] = "yes", } --- PrintTableWithHeadline(tags, 'original tags') ConvertCyclewayOppositeSchema(tags) --- PrintTableWithHeadline(tags, 'modified tags') assert(CompareTables(tags, expectedResult)) print('=== Test ConvertCyclewayOppositeSchema: handle opposite_track ===') @@ -43,7 +38,5 @@ local expectedResult = { ["oneway:bicycle"] = "no", ["oneway"] = "yes", } --- PrintTableWithHeadline(tags, 'original tags') ConvertCyclewayOppositeSchema(tags) --- PrintTableWithHeadline(tags, 'modified tags') assert(CompareTables(tags, expectedResult)) From 0ddf39178ff137527ecc60a0fbbbd36e404f5203 Mon Sep 17 00:00:00 2001 From: rush42 Date: Tue, 13 Feb 2024 16:33:57 +0100 Subject: [PATCH 07/23] `Sanatize()` make `default` parameter optional --- app/process/helper/Sanitize.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/process/helper/Sanitize.lua b/app/process/helper/Sanitize.lua index d9b1eed6..756ba66c 100644 --- a/app/process/helper/Sanitize.lua +++ b/app/process/helper/Sanitize.lua @@ -1,6 +1,6 @@ ---@param value any ---@param allowed table ----@param default any +---@param default? any ---@return any -- makes sure that `value` is in the set `allowed`. Returns `default` if value is nil function Sanitize(value, allowed, default) From 56c146c20e68bac1e914c266c8397867fd6aa8d3 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 17 Feb 2024 20:29:40 +0100 Subject: [PATCH 08/23] Bikelanes: Add alternative tagging `path=sidewalk` --- app/process/roads_bikelanes/bikelanes/categories.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/process/roads_bikelanes/bikelanes/categories.lua b/app/process/roads_bikelanes/bikelanes/categories.lua index cb27fc93..e54c6cbb 100644 --- a/app/process/roads_bikelanes/bikelanes/categories.lua +++ b/app/process/roads_bikelanes/bikelanes/categories.lua @@ -90,7 +90,7 @@ local function footAndCyclewaySharedCases(tags) local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:240") if taggedWithAccessTagging or taggedWithTrafficsign then -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. - if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" or tags.path == "sidewalk" then return "footAndCyclewayShared_adjoining" end -- Eg https://www.openstreetmap.org/way/440072364 highway=service @@ -110,7 +110,7 @@ local function footAndCyclewaySegregatedCases(tags) local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:241") if taggedWithAccessTagging or taggedWithTrafficsign then -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. - if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" or tags.path == "sidewalk" then return "footAndCyclewaySegregated_adjoining" end if tags.is_sidepath == "no" then @@ -132,7 +132,7 @@ local function footwayBicycleYesCases(tags) if tags.highway == "footway" or tags.highway == "path" then if tags.bicycle == "yes" or IsTermInString("1022-10", tags.traffic_sign) then -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. - if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" or tags.path == "sidewalk" then return "footwayBicycleYes_adjoining" end -- https://www.openstreetmap.org/way/946438663 From 5d0564d6f72f756ad1d0c04bb963a08619f68578 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:47:32 +0100 Subject: [PATCH 09/23] Revert "TEMP: disable processing" This reverts commit f039b2a94e19222cc107f88e0caedd24047550bd. --- app/run.sh | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/app/run.sh b/app/run.sh index 078829b5..476bbe21 100755 --- a/app/run.sh +++ b/app/run.sh @@ -26,33 +26,33 @@ alert() { curl -X POST $url -d "payload=$payload" --silent --output "/dev/null" } -# if ! ./run-1-download.sh; then -# alert '*ERROR*: #run-1-download exited with non-zero status code' -# fi - -# if ! ./run-2-filter.sh; then -# alert '*ERROR*: #run-2-filter exited with non-zero status code' -# fi - -# if ! ./run-3-migration.sh; then -# alert '*ERROR*: #run-3-migration exited with non-zero status code' -# fi - -# process_start_time=$(date +%s) -# if ! ./run-4-process.sh; then -# alert '*ERROR*: #run-4-process exited with non-zero status code' -# fi -# process_end_time=$(date +%s) -# export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh - -# if ! ./run-5-postprocess.sh; then -# alert '*ERROR*: #run-5-postprocess exited with non-zero status code' -# fi - -# if ! ./run-6-analysis.sh; then -# alert '*ERROR*: #run-6-analysis exited with non-zero status code' -# fi - -# if ! ./run-7-metadata.sh; then -# alert '*ERROR*: #run-7-metadata exited with non-zero status code' -# fi +if ! ./run-1-download.sh; then + alert '*ERROR*: #run-1-download exited with non-zero status code' +fi + +if ! ./run-2-filter.sh; then + alert '*ERROR*: #run-2-filter exited with non-zero status code' +fi + +if ! ./run-3-migration.sh; then + alert '*ERROR*: #run-3-migration exited with non-zero status code' +fi + +process_start_time=$(date +%s) +if ! ./run-4-process.sh; then + alert '*ERROR*: #run-4-process exited with non-zero status code' +fi +process_end_time=$(date +%s) +export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh + +if ! ./run-5-postprocess.sh; then + alert '*ERROR*: #run-5-postprocess exited with non-zero status code' +fi + +if ! ./run-6-analysis.sh; then + alert '*ERROR*: #run-6-analysis exited with non-zero status code' +fi + +if ! ./run-7-metadata.sh; then + alert '*ERROR*: #run-7-metadata exited with non-zero status code' +fi From 04f1b64ec7471e05b68ea01e43d3c94d29774be3 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 05:45:40 +0100 Subject: [PATCH 10/23] Move `is_sidepath:of:name` fallback to the right place --- app/process/roads_bikelanes/lit/Lit.lua | 4 ---- app/process/roads_bikelanes/roads_bikelanes.lua | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/process/roads_bikelanes/lit/Lit.lua b/app/process/roads_bikelanes/lit/Lit.lua index dc9e3af1..083091db 100644 --- a/app/process/roads_bikelanes/lit/Lit.lua +++ b/app/process/roads_bikelanes/lit/Lit.lua @@ -38,10 +38,6 @@ function Lit(object) end end - -- Normalize name info for sidepath' - -- TODO: Extact into helper - tags.name = tags.name or tags['is_sidepath:of:name'] - -- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Alit if tags["check_date:lit"] then lit_data.lit_age= AgeInDays(ParseDate(tags["check_date:lit"])) diff --git a/app/process/roads_bikelanes/roads_bikelanes.lua b/app/process/roads_bikelanes/roads_bikelanes.lua index 658ce564..08a0b163 100644 --- a/app/process/roads_bikelanes/roads_bikelanes.lua +++ b/app/process/roads_bikelanes/roads_bikelanes.lua @@ -84,7 +84,7 @@ function osm2pgsql.process_way(object) -- ====== (C) Compute results and insert ====== local results = { - name = tags.name or tags.ref + name = tags.name or tags.ref or tags['is_sidepath:of:name'] } MergeTable(results, RoadClassification(object)) From b50675f6b7d47f5ccc0732d8a9b0d6445456c294 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:26:46 +0100 Subject: [PATCH 11/23] Streamline `tags_copied`, `tags_prefixed` All files in roads_bikelanes now have two array at the top of the file. This gives clarity on which files add tags to the results and which don't. It makes it easier to compare the files and spot bugs. --- .../roads_bikelanes/bikelanes/Bikelanes.lua | 15 ++++------ app/process/roads_bikelanes/lit/Lit.lua | 5 ++++ .../roads_bikelanes/maxspeed/Maxspeed.lua | 18 +++++------ .../roadClassification/RoadClassification.lua | 30 +++++++++---------- .../surfaceQuality/SurfaceQuality.lua | 7 +++-- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua index f7cd44ab..c228fecb 100644 --- a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua +++ b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua @@ -13,13 +13,12 @@ require("DeriveSurface") require("DeriveSmoothness") require("BikelanesTodos") - --- these tags are copied (Eigennamen) -local allowed_tags = { +local tags_copied = { "name", + "mapillary", + "description", } --- these tags are copied and prefixed with `osm_` -local tags_cc = { +local tags_prefixed = { 'surface:colour', 'traffic_sign', 'traffic_sign:forward', @@ -30,8 +29,6 @@ local tags_cc = { 'traffic_mode', 'traffic_mode:left', 'traffic_mode:right', - "mapillary", - "description", } function Bikelanes(object) @@ -90,8 +87,8 @@ function Bikelanes(object) MergeTable(results, DeriveSmoothness(cycleway)) MergeTable(results, DeriveSurface(cycleway)) - CopyTags(results, tags, allowed_tags) - CopyTags(results, tags, tags_cc, 'osm_') + CopyTags(results, tags, tags_copied) + CopyTags(results, tags, tags_prefixed, 'osm_') -- cycleway._todos = ToMarkdownList(BikelanesTodos(cycleway)) bikelanes[i] = results diff --git a/app/process/roads_bikelanes/lit/Lit.lua b/app/process/roads_bikelanes/lit/Lit.lua index 083091db..1d0bfd1d 100644 --- a/app/process/roads_bikelanes/lit/Lit.lua +++ b/app/process/roads_bikelanes/lit/Lit.lua @@ -21,6 +21,8 @@ require("Set") -- We need to improve this, to copy the ways for sidewalks and cycleways that are not yet mapped separately. And apply the data on those ways as well. -- Could we do this, by adding a _processing_instructions="move left". -- We add those ways twice to the data … and post-process the in SQL? +local tags_copied = {} +local tags_prefixed = {} function Lit(object) local tags = object.tags @@ -43,5 +45,8 @@ function Lit(object) lit_data.lit_age= AgeInDays(ParseDate(tags["check_date:lit"])) end + CopyTags(lit_data, tags, tags_copied) + CopyTags(lit_data, tags, tags_prefixed, "osm_") + return lit_data end diff --git a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua index 847730f8..bdbc2c3b 100644 --- a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua +++ b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua @@ -7,6 +7,13 @@ require("MaxspeedFromZone") require("CopyTags") require("Set") +local tags_copied = {} +local tags_prefixed = { + "maxspeed:backward", + "maxspeed:forward", + "maxspeed:conditional", +} + function Maxspeed(object) local tags = object.tags @@ -34,21 +41,14 @@ function Maxspeed(object) end end - -- all tags that are shown on the application - local tags_cc = { - "maxspeed:backward", - "maxspeed:forward", - "maxspeed:conditional", - } - - CopyTags(maxspeed_data, tags, tags_cc, "osm_") - -- Freshness of data (AFTER `FilterTags`!) -- 700+ https://taginfo.openstreetmap.org/keys/check_date%3Amaxspeed if tags["check_date:maxspeed"] then maxspeed_data.maxspeed_age = AgeInDays(ParseDate(tags["check_date:maxspeed"])) end + CopyTags(maxspeed_data, tags, tags_copied) + CopyTags(maxspeed_data, tags, tags_prefixed, "osm_") maxspeed_data.maxspeed = maxspeed maxspeed_data.maxspeed_source = source maxspeed_data.maxspeed_confidence = confidence diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index b6440464..b034a711 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -3,13 +3,21 @@ require("Set") require("CopyTags") require("Sanitize") -function RoadClassification(object) - -- Values that we would allow, but skip here: - -- "construction", "planned", "proposed", "platform" (Haltestellen), - -- "rest_area" (https://wiki.openstreetmap.org/wiki/DE:Tag:highway=rest%20area) +local tags_copied = { + "mapillary", + "description", +} +local tags_prefixed = { + 'traffic_sign', + 'traffic_sign:forward', + 'traffic_sign:backward', + "mapillary", + "description", +} - local roadClassification = {} +function RoadClassification(object) local tags = object.tags + local roadClassification = {} -- https://wiki.openstreetmap.org/wiki/DE:Key:highway -- We use the OSM highway value as category, but have a few special cases below. @@ -83,16 +91,8 @@ function RoadClassification(object) roadClassification['road_oneway:bicycle'] = tags['oneway:bicycle'] end - -- these tags are copied and prefixed with `osm_` - -- we need to sanatize them at some point - local tags_cc = { - 'traffic_sign', - 'traffic_sign:forward', - 'traffic_sign:backward', - "mapillary", - "description", - } - CopyTags(roadClassification, tags, tags_cc, "osm_") + CopyTags(roadClassification, tags, tags_copied) + CopyTags(roadClassification, tags, tags_prefixed, "osm_") roadClassification.width = ParseLength(tags.width) roadClassification.oneway = Sanitize(tags.oneway, Set({ "yes", "no" })) diff --git a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua index 166d74b9..b73f96cf 100644 --- a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua +++ b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua @@ -7,9 +7,10 @@ require("DeriveSmoothness") require("Set") require("CopyTags") -function SurfaceQuality(object) - -- Same as roadClassification, except for `HighwayClasses` +local tags_copied = {} +local tags_prefixed = {} +function SurfaceQuality(object) local tags = object.tags local surface_data = {} @@ -27,6 +28,8 @@ function SurfaceQuality(object) surface_data.smoothness_age = AgeInDays(ParseDate(tags["check_date:smoothness"])) end + CopyTags(surface_data, tags, tags_copied) + CopyTags(surface_data, tags, tags_prefixed, "osm_") return surface_data end From 04c4124804aac51769a36fb7df26f95951755a6e Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:27:34 +0100 Subject: [PATCH 12/23] Bikelanes: Move copy name one level up to make it the same as roads --- app/process/roads_bikelanes/bikelanes/Bikelanes.lua | 1 - app/process/roads_bikelanes/roads_bikelanes.lua | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua index c228fecb..c84d26d7 100644 --- a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua +++ b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua @@ -14,7 +14,6 @@ require("DeriveSmoothness") require("BikelanesTodos") local tags_copied = { - "name", "mapillary", "description", } diff --git a/app/process/roads_bikelanes/roads_bikelanes.lua b/app/process/roads_bikelanes/roads_bikelanes.lua index 08a0b163..49ba6249 100644 --- a/app/process/roads_bikelanes/roads_bikelanes.lua +++ b/app/process/roads_bikelanes/roads_bikelanes.lua @@ -94,6 +94,7 @@ function osm2pgsql.process_way(object) local cycleways = Bikelanes(object) for _, cycleway in pairs(cycleways) do if cycleway._infrastructureExists then + cycleway.name = results.name cycleway.road = results.road bikelanesTable:insert({ tags = cycleway, From d33f17b3f2a066078db4f427b5a2fefa1e9ccd0f Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:29:08 +0100 Subject: [PATCH 13/23] Cleanup old comments, improve docs, improve formatting --- .../roads_bikelanes/bikelanes/Bikelanes.lua | 6 ++- .../roads_bikelanes/bikelanes/categories.lua | 8 +++- app/process/roads_bikelanes/lit/Lit.lua | 25 +----------- app/process/roads_bikelanes/lit/README.md | 27 +------------ .../roads_bikelanes/maxspeed/Maxspeed.lua | 18 ++++----- .../roadClassification/RoadClassification.lua | 3 +- .../roads_bikelanes/roads_bikelanes.lua | 2 +- .../surfaceQuality/SurfaceQuality.lua | 2 - .../roads_bikelanes/surfaceQuality/TODO.lua | 40 ------------------- 9 files changed, 24 insertions(+), 107 deletions(-) delete mode 100644 app/process/roads_bikelanes/surfaceQuality/TODO.lua diff --git a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua index c84d26d7..571216a6 100644 --- a/app/process/roads_bikelanes/bikelanes/Bikelanes.lua +++ b/app/process/roads_bikelanes/bikelanes/Bikelanes.lua @@ -59,7 +59,11 @@ function Bikelanes(object) else local category = CategorizeBikelane(cycleway) if category ~= nil then - local results = { _infrastructureExists = true, category = category, offset = sign * RoadWidth(tags) / 2 } + local results = { + _infrastructureExists = true, + category = category, + offset = sign * RoadWidth(tags) / 2, -- TODO: Should be `_offset` + } -- Our atlas-app inspector should be explicit about tagging that OSM considers default/implicit if cycleway.oneway == nil then diff --git a/app/process/roads_bikelanes/bikelanes/categories.lua b/app/process/roads_bikelanes/bikelanes/categories.lua index e54c6cbb..c5639dbd 100644 --- a/app/process/roads_bikelanes/bikelanes/categories.lua +++ b/app/process/roads_bikelanes/bikelanes/categories.lua @@ -286,8 +286,12 @@ end -- Categories for objects where no infrastructure is available but the data is considered complete function CategorizeOnlyPresent(tags) - local dataCategories = { dataNo, isSeparate, implicitOneWay } - return defineCategory(tags, dataCategories) + local categories = { + dataNo, + isSeparate, + implicitOneWay, + } + return defineCategory(tags, categories) end function CategorizeBikelane(tags) diff --git a/app/process/roads_bikelanes/lit/Lit.lua b/app/process/roads_bikelanes/lit/Lit.lua index 1d0bfd1d..646f3972 100644 --- a/app/process/roads_bikelanes/lit/Lit.lua +++ b/app/process/roads_bikelanes/lit/Lit.lua @@ -3,34 +3,13 @@ require("CopyTags") require("TimeUtils") require("Set") --- Notes --- ===== --- Which highways do we look at? --- We should include sidewalks. --- But ideally, we would exclude ways that are not network-relevant like cemetary footways - --- We ignore street lamps: --- https://wiki.openstreetmap.org/wiki/Tag:highway%3Dstreet_lamp is not relevant for this data set - --- About nodes and relations: --- process_node: We only look at highways --- process_relation: We might need to add relations later; but for now ways should be enought - --- TODO: Process sidewalk:*, cycleway:* data othe centerline --- Right now, we only look at the primary data. --- We need to improve this, to copy the ways for sidewalks and cycleways that are not yet mapped separately. And apply the data on those ways as well. --- Could we do this, by adding a _processing_instructions="move left". --- We add those ways twice to the data … and post-process the in SQL? local tags_copied = {} local tags_prefixed = {} function Lit(object) local tags = object.tags - local lit_data = {} - -- https://wiki.openstreetmap.org/wiki/Key:lit - -- Categorize the data in three groups: "lit", "unlit", "special" if tags.lit ~= nil then if (tags.lit == "yes" or tags.lit == "no") then @@ -40,9 +19,9 @@ function Lit(object) end end - -- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Alit + -- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Alit, https://overpass-turbo.eu/s/1lZW if tags["check_date:lit"] then - lit_data.lit_age= AgeInDays(ParseDate(tags["check_date:lit"])) + lit_data.lit_age = AgeInDays(ParseDate(tags["check_date:lit"])) end CopyTags(lit_data, tags, tags_copied) diff --git a/app/process/roads_bikelanes/lit/README.md b/app/process/roads_bikelanes/lit/README.md index fdc4766d..8d64a0af 100644 --- a/app/process/roads_bikelanes/lit/README.md +++ b/app/process/roads_bikelanes/lit/README.md @@ -3,33 +3,8 @@ **OSM:** - Docs: https://wiki.openstreetmap.org/wiki/Key:lit - Note: the QA tools on https://wiki.openstreetmap.org/wiki/DE:Key:lit do not work for our use case or not at all. + Note: The QA tools on https://wiki.openstreetmap.org/wiki/DE:Key:lit do not work for our use case or not at all. ## Main values - `category` (string) – `list`, `unlit`, `special` -- `lit` (string) – Raw osm values - -## Style helper tags - -- `verified` (string) – The state of verification -- `is_present` (boolean) – Is the main data (lit) present? "Any lit values" is `true`, "no lit value" is `false`. -- `fresh` (string | "not present") – Was the main data (lit) checked at least 2 years ago? (based on `check_date:lit` or the object's timestamp) the string is of the form `<"fresh" | "outdated">_<"updated_at" | "check_date">` where the `"check_date"` indicates a higher confidence; -- `fresh_age_days` (number) – Age of data as number of days based on `check_date:lit` - -## Raw OSM tags - -(!) We might change those tags at any time. - -- `access` -- `check_date:lit` – Testing https://overpass-turbo.eu/s/1lZW -- `footway` -- `highway` -- `is_sidepath` -- `name` -- `service` - -## Processing helper - -- `_exclude` -- `_excludeNotes` diff --git a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua index bdbc2c3b..94023e52 100644 --- a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua +++ b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua @@ -14,16 +14,15 @@ local tags_prefixed = { "maxspeed:conditional", } +-- Try to find maxspeed information in the following order: +-- 1. `maxspeed` tag (also looking at `maxspeed:forward` and `maxspeed:backward`) +-- 2. maxspeed zones tags +-- 3. highway type +-- 4. TODO: intersecting landuse via SQL, see https://github.com/FixMyBerlin/atlas-geo/pull/28 function Maxspeed(object) local tags = object.tags - local maxspeed_data = {} - -- Try to find maxspeed information in the following order: - -- 1. `maxspeed` tag - -- 2. maxspeed zones tags - -- 3. highway type - -- 4. SQL: intersecting landuse local maxspeed, source, confidence = MaxspeedDirect(tags) if maxspeed == nil then @@ -41,7 +40,7 @@ function Maxspeed(object) end end - -- Freshness of data (AFTER `FilterTags`!) + -- Freshness of data -- 700+ https://taginfo.openstreetmap.org/keys/check_date%3Amaxspeed if tags["check_date:maxspeed"] then maxspeed_data.maxspeed_age = AgeInDays(ParseDate(tags["check_date:maxspeed"])) @@ -53,8 +52,5 @@ function Maxspeed(object) maxspeed_data.maxspeed_source = source maxspeed_data.maxspeed_confidence = confidence - if maxspeed ~= nil then - return maxspeed_data - end - return {} + return maxspeed_data end diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index b034a711..7c547b01 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -20,7 +20,7 @@ function RoadClassification(object) local roadClassification = {} -- https://wiki.openstreetmap.org/wiki/DE:Key:highway - -- We use the OSM highway value as category, but have a few special cases below. + -- In general, we use the OSM highway value as category, but have a few special cases below. local highway_mapping = { road = "unspecified_road", steps = "footway_steps", @@ -82,6 +82,7 @@ function RoadClassification(object) if tags.oneway == 'yes' then -- Note: We do not pass 'oneway=no' to the 'road_oneway' key + -- because it is the default which we do not want to show in the UI. roadClassification.road_oneway = tags.oneway if tags.dual_carriageway == "yes" then roadClassification.road_oneway = tags.oneway .. '_dual_carriageway' diff --git a/app/process/roads_bikelanes/roads_bikelanes.lua b/app/process/roads_bikelanes/roads_bikelanes.lua index 49ba6249..4b9a81e1 100644 --- a/app/process/roads_bikelanes/roads_bikelanes.lua +++ b/app/process/roads_bikelanes/roads_bikelanes.lua @@ -109,7 +109,7 @@ function osm2pgsql.process_way(object) MergeTable(results, BikelanesPresence(object, cycleways)) end - -- We need sidewalk for Biklanes() + -- We need sidewalk for Biklanes(), but not for `roads` local isSidewalk = tags.footway == 'sidewalk' or tags.steps == 'sidewalk' if not isSidewalk then roadsTable:insert({ diff --git a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua index b73f96cf..77209693 100644 --- a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua +++ b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua @@ -12,13 +12,11 @@ local tags_prefixed = {} function SurfaceQuality(object) local tags = object.tags - local surface_data = {} MergeTable(surface_data, DeriveSurface(tags)) MergeTable(surface_data, DeriveSmoothness(tags)) - -- 77,000+ https://taginfo.openstreetmap.org/keys/check_date%3Asurface if tags["check_date:surface"] then surface_data.surface_age = AgeInDays(ParseDate(tags["check_date:surface"])) diff --git a/app/process/roads_bikelanes/surfaceQuality/TODO.lua b/app/process/roads_bikelanes/surfaceQuality/TODO.lua deleted file mode 100644 index 326a93b3..00000000 --- a/app/process/roads_bikelanes/surfaceQuality/TODO.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Goal: --- ====== --- Data set about "Oberflächenqualität" which we consider a combination of `surface` and `smoothness` data. - --- Visualization --- ===== --- 1. Map of smoothness data --- 2. Map of surface data - --- Hidden complexity --- ===== --- There is a hidden complexity in this task having to do with "cycleway:*" and "sidewalk:*" tagging. --- (AKA bike and pedestiran infrastructure that is mapped on the "centerline".) --- In my proof of concept, I tried to handle this with complex hierachical keys. --- However, with the power of PostgreSQL, a better approach is likely to first split the data and then process it. --- A "centerline" with "sidewalk=both" (or "sidewalk:both=yes") would become 3 lines, with the two sidewalk lines being moved to the left/right of the centerline. Same for "cycleway*". Possible keys like "cycleway:left:surface=*" need to be moved as well. --- Its recommended to first pre-process the data in LUA to normalize the tagging of "sidewalk=both" and "sidewalk:both=yes" to a "sidewalk:left+sidewalk:right" patter, so in SQL we only need to deal with explicit left/right. --- UPDATE 2022-09-21: See "bikelanes.lua" for my latest idea how to setup a process for this. --- UPDATE 2022-11-24: We are working on a solution in biklanesNew.lua. Once this is finished, we can rework this file to follow the new conventions established there. Until then, lets only look at the simple tags surface+smoothness on the centerline (tags for the "car road"). - --- Processing --- ==== --- We interpolate surface and smoothness data in order to show a complete map. --- We also show a confidence and confidence-description for those fields. --- --- 1. If smoothness present, normalize the data. --- This will reduce the values to a list that we support. --- See https://github.com/FixMyBerlin/osm-scripts/blob/main/utils/Highways-SurfaceData/utils/normalizedSmoothness.ts --- confidence: high --- conficence-description: explicit tagging OR explicit tagging, normalized --- I use a different approach in the script above, which documents the tag modification in "before => after" pattern, which is probably the better idea. --- See https://github.com/FixMyBerlin/osm-scripts/blob/main/utils/Highways-SurfaceData/utils/addCustomSmoothnessProps.ts#L78 --- Note, that the normalization (and other transponation) can have two list: One main list and one to be used to add "_todos" in a separate data layer. --- --- 2. If no smoothness is given, use surface to extrapolate a smoothness value --- See https://github.com/FixMyBerlin/osm-scripts/blob/main/utils/Highways-SurfaceData/utils/extrapolatedSmoothnessBasedOnSurface.ts --- Again, the second list might be re-used for a "todoList". --- --- 3. If no surface is given, use the highway (type) to exptrapolate a surface/smoothness value. --- See https://github.com/FixMyBerlin/osm-scripts/blob/main/utils/Highways-SurfaceData/utils/extrapolatedSmoothnessBasedOnHighway.ts From a5341db7134689615d9ea54385cce6a28ac4093f Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:29:14 +0100 Subject: [PATCH 14/23] Improve type comments --- app/process/shared/ExcludeHighways.lua | 6 +++--- app/process/shared/ToMarkdownList.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/process/shared/ExcludeHighways.lua b/app/process/shared/ExcludeHighways.lua index 4d4cfac8..e660b9ca 100644 --- a/app/process/shared/ExcludeHighways.lua +++ b/app/process/shared/ExcludeHighways.lua @@ -1,7 +1,8 @@ require("Set") --- * @desc If and why a highway object should be excluded based on its tags. --- * @returns { boolean (shouldFilter), string (reason) } +---@return boolean, string +-- If and why a highway object should be excluded based on its tags. +-- @return true/false, reason function ExcludeHighways(tags) -- Skip all non standard access values local forbidden_accesses = Set({ "private", "no", "destination", "delivery", "permit" }) @@ -29,7 +30,6 @@ function ExcludeHighways(tags) return true, "Excluded by `informal=yes`" end - -- Skip all unwanted `highway=service + service=` values -- The key can have random values, we mainly want to skip -- - "driveway" which we consider implicitly private diff --git a/app/process/shared/ToMarkdownList.lua b/app/process/shared/ToMarkdownList.lua index c58d456e..66c01ae2 100644 --- a/app/process/shared/ToMarkdownList.lua +++ b/app/process/shared/ToMarkdownList.lua @@ -1,6 +1,6 @@ --- @desc Transform a list of string into a Markdown list --- @param array string[] --- @return string|nil +---@param array string[] +---@return string|nil +-- Transform a list of string into a Markdown list function ToMarkdownList(array) if not array or #array == 0 then return nil From 9426fd5b368fb80055e1a9943ac1cb93cec51fb1 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:31:49 +0100 Subject: [PATCH 15/23] RaodClassification: Simplify conditions Which makes it easier to read --- .../roads_bikelanes/roadClassification/RoadClassification.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index 7c547b01..5cd3a4af 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -45,8 +45,8 @@ function RoadClassification(object) -- Vorfahrtsstraße, Zubringerstraße -- https://wiki.openstreetmap.org/wiki/DE:Key:priority_road - if (tags.highway == 'residential' and tags.priority_road == 'designated') - or (tags.highway == 'residential' and tags.priority_road == 'yes_unposted') then + if tags.highway == 'residential' and + (tags.priority_road == 'designated' or tags.priority_road == 'yes_unposted') then roadClassification.road = "residential_priority_road" end From e32db04a6b21c821e674196ec8d99e890da9a461 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:32:22 +0100 Subject: [PATCH 16/23] RoadClassification: Add another crossing case for `path` --- app/process/roads_bikelanes/roadClassification/README.md | 6 ++++++ .../roadClassification/RoadClassification.lua | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/app/process/roads_bikelanes/roadClassification/README.md b/app/process/roads_bikelanes/roadClassification/README.md index 5a2ea8e2..da7a9590 100644 --- a/app/process/roads_bikelanes/roadClassification/README.md +++ b/app/process/roads_bikelanes/roadClassification/README.md @@ -11,3 +11,9 @@ - `highway=service + service=parking_aisle` becomes `category=service_parking_aisle` - `highway=* + bicycle_road=yes` becomes `category=bicycle_road` - `highway=steps` becomes `category=footway` + +## Notes / TODOs + +- We could improve the `*crossing` categories +- We could add special tags for streets only for bus, tax, etc. + (we would probably have to look at the `*lanes` schema for that) diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index 5cd3a4af..313999fc 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -43,6 +43,13 @@ function RoadClassification(object) roadClassification.road = "cycleway_crossing" end + -- Foot- and Bicycle Crossing + -- This is a strong simplification because we do not look at the access tags here. + -- However, that should bring us pretty close without the added complexity. + if tags.highway == 'path' and tags.path == 'crossing' then + roadClassification.road = "footway_cycleway_crossing" + end + -- Vorfahrtsstraße, Zubringerstraße -- https://wiki.openstreetmap.org/wiki/DE:Key:priority_road if tags.highway == 'residential' and From 18c0da48ddbb23fe7e87f00ce72c655e950df88e Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:33:38 +0100 Subject: [PATCH 17/23] RoadClassification: Improve sidewalk case Same as for the Categories file in 56c146c --- .../roads_bikelanes/roadClassification/RoadClassification.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index 313999fc..65055c9e 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -29,7 +29,7 @@ function RoadClassification(object) -- Sidewalks if (tags.highway == 'footway' and tags.footway == 'sidewalk') - or (tags.highway == 'path' and tags.is_sidepath == 'yes') then + or (tags.highway == 'path' and (tags.is_sidepath == 'yes' or tags.path == 'sidewalk')) then roadClassification.road = "footway_sidewalk" end From e25a4601e8698654897a5ff06a21c4b2e70cb40c Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 06:33:58 +0100 Subject: [PATCH 18/23] Streamline `result_tags` as name to be returned --- .../bikelanes/BikelanesPresence.lua | 5 ++- app/process/roads_bikelanes/lit/Lit.lua | 14 ++++---- .../roads_bikelanes/maxspeed/Maxspeed.lua | 16 ++++----- .../roadClassification/RoadClassification.lua | 36 +++++++++---------- .../surfaceQuality/SurfaceQuality.lua | 16 ++++----- 5 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/process/roads_bikelanes/bikelanes/BikelanesPresence.lua b/app/process/roads_bikelanes/bikelanes/BikelanesPresence.lua index 852ebf16..fbce6eb7 100644 --- a/app/process/roads_bikelanes/bikelanes/BikelanesPresence.lua +++ b/app/process/roads_bikelanes/bikelanes/BikelanesPresence.lua @@ -30,12 +30,11 @@ function BikelanesPresence(object, cycleways) -- replace all nil values with 'missing' for _, side in pairs(sides) do presence[side] = presence[side] or "missing" end - - local presence_data = { + local result_tags = { bikelane_left = presence[LEFT_SIGN], bikelane_self = presence[CENTER_SIGN], bikelane_right = presence[RIGHT_SIGN] } - return presence_data + return result_tags end diff --git a/app/process/roads_bikelanes/lit/Lit.lua b/app/process/roads_bikelanes/lit/Lit.lua index 646f3972..ffb8874f 100644 --- a/app/process/roads_bikelanes/lit/Lit.lua +++ b/app/process/roads_bikelanes/lit/Lit.lua @@ -8,24 +8,24 @@ local tags_prefixed = {} function Lit(object) local tags = object.tags - local lit_data = {} + local result_tags = {} -- Categorize the data in three groups: "lit", "unlit", "special" if tags.lit ~= nil then if (tags.lit == "yes" or tags.lit == "no") then - lit_data.lit = tags.lit + result_tags.lit = tags.lit else - lit_data.lit = "special" + result_tags.lit = "special" end end -- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Alit, https://overpass-turbo.eu/s/1lZW if tags["check_date:lit"] then - lit_data.lit_age = AgeInDays(ParseDate(tags["check_date:lit"])) + result_tags.lit_age = AgeInDays(ParseDate(tags["check_date:lit"])) end - CopyTags(lit_data, tags, tags_copied) - CopyTags(lit_data, tags, tags_prefixed, "osm_") + CopyTags(result_tags, tags, tags_copied) + CopyTags(result_tags, tags, tags_prefixed, "osm_") - return lit_data + return result_tags end diff --git a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua index 94023e52..d7f3650e 100644 --- a/app/process/roads_bikelanes/maxspeed/Maxspeed.lua +++ b/app/process/roads_bikelanes/maxspeed/Maxspeed.lua @@ -21,7 +21,7 @@ local tags_prefixed = { -- 4. TODO: intersecting landuse via SQL, see https://github.com/FixMyBerlin/atlas-geo/pull/28 function Maxspeed(object) local tags = object.tags - local maxspeed_data = {} + local result_tags = {} local maxspeed, source, confidence = MaxspeedDirect(tags) @@ -43,14 +43,14 @@ function Maxspeed(object) -- Freshness of data -- 700+ https://taginfo.openstreetmap.org/keys/check_date%3Amaxspeed if tags["check_date:maxspeed"] then - maxspeed_data.maxspeed_age = AgeInDays(ParseDate(tags["check_date:maxspeed"])) + result_tags.maxspeed_age = AgeInDays(ParseDate(tags["check_date:maxspeed"])) end - CopyTags(maxspeed_data, tags, tags_copied) - CopyTags(maxspeed_data, tags, tags_prefixed, "osm_") - maxspeed_data.maxspeed = maxspeed - maxspeed_data.maxspeed_source = source - maxspeed_data.maxspeed_confidence = confidence + CopyTags(result_tags, tags, tags_copied) + CopyTags(result_tags, tags, tags_prefixed, "osm_") + result_tags.maxspeed = maxspeed + result_tags.maxspeed_source = source + result_tags.maxspeed_confidence = confidence - return maxspeed_data + return result_tags end diff --git a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua index 65055c9e..e8a62e29 100644 --- a/app/process/roads_bikelanes/roadClassification/RoadClassification.lua +++ b/app/process/roads_bikelanes/roadClassification/RoadClassification.lua @@ -17,7 +17,7 @@ local tags_prefixed = { function RoadClassification(object) local tags = object.tags - local roadClassification = {} + local result_tags = {} -- https://wiki.openstreetmap.org/wiki/DE:Key:highway -- In general, we use the OSM highway value as category, but have a few special cases below. @@ -25,36 +25,36 @@ function RoadClassification(object) road = "unspecified_road", steps = "footway_steps", } - roadClassification.road = highway_mapping[tags.highway] or tags.highway + result_tags.road = highway_mapping[tags.highway] or tags.highway -- Sidewalks if (tags.highway == 'footway' and tags.footway == 'sidewalk') or (tags.highway == 'path' and (tags.is_sidepath == 'yes' or tags.path == 'sidewalk')) then - roadClassification.road = "footway_sidewalk" + result_tags.road = "footway_sidewalk" end -- Sidewalks Crossing if tags.highway == 'footway' and tags.footway == 'crossing' then - roadClassification.road = "footway_crossing" + result_tags.road = "footway_crossing" end -- Bikelane Crossing if tags.highway == 'cycleway' and tags.cycleway == 'crossing' then - roadClassification.road = "cycleway_crossing" + result_tags.road = "cycleway_crossing" end -- Foot- and Bicycle Crossing -- This is a strong simplification because we do not look at the access tags here. -- However, that should bring us pretty close without the added complexity. if tags.highway == 'path' and tags.path == 'crossing' then - roadClassification.road = "footway_cycleway_crossing" + result_tags.road = "footway_cycleway_crossing" end -- Vorfahrtsstraße, Zubringerstraße -- https://wiki.openstreetmap.org/wiki/DE:Key:priority_road if tags.highway == 'residential' and (tags.priority_road == 'designated' or tags.priority_road == 'yes_unposted') then - roadClassification.road = "residential_priority_road" + result_tags.road = "residential_priority_road" end -- Service @@ -66,17 +66,17 @@ function RoadClassification(object) parking_isle = 'service_parking_aisle' } -- Fallbacks: - roadClassification.road = service_mapping[tags.service] or 'service_uncategorized' + result_tags.road = service_mapping[tags.service] or 'service_uncategorized' -- https://taginfo.openstreetmap.org/keys/service#values if tags.service == nil then - roadClassification.road = "service_road" + result_tags.road = "service_road" end end -- Fahrradstraßen if tags.bicycle_road == 'yes' then -- traffic_sign=DE:244.1 - roadClassification.road = "bicycle_road" + result_tags.road = "bicycle_road" end -- Mischverkehr @@ -90,19 +90,19 @@ function RoadClassification(object) if tags.oneway == 'yes' then -- Note: We do not pass 'oneway=no' to the 'road_oneway' key -- because it is the default which we do not want to show in the UI. - roadClassification.road_oneway = tags.oneway + result_tags.road_oneway = tags.oneway if tags.dual_carriageway == "yes" then - roadClassification.road_oneway = tags.oneway .. '_dual_carriageway' + result_tags.road_oneway = tags.oneway .. '_dual_carriageway' end end if tags['oneway:bicycle'] == 'no' or tags['oneway:bicycle'] then - roadClassification['road_oneway:bicycle'] = tags['oneway:bicycle'] + result_tags['road_oneway:bicycle'] = tags['oneway:bicycle'] end - CopyTags(roadClassification, tags, tags_copied) - CopyTags(roadClassification, tags, tags_prefixed, "osm_") - roadClassification.width = ParseLength(tags.width) - roadClassification.oneway = Sanitize(tags.oneway, Set({ "yes", "no" })) + CopyTags(result_tags, tags, tags_copied) + CopyTags(result_tags, tags, tags_prefixed, "osm_") + result_tags.width = ParseLength(tags.width) + result_tags.oneway = Sanitize(tags.oneway, Set({ "yes", "no" })) - return roadClassification + return result_tags end diff --git a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua index 77209693..f7a5c464 100644 --- a/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua +++ b/app/process/roads_bikelanes/surfaceQuality/SurfaceQuality.lua @@ -12,22 +12,22 @@ local tags_prefixed = {} function SurfaceQuality(object) local tags = object.tags - local surface_data = {} + local result_tags = {} - MergeTable(surface_data, DeriveSurface(tags)) - MergeTable(surface_data, DeriveSmoothness(tags)) + MergeTable(result_tags, DeriveSurface(tags)) + MergeTable(result_tags, DeriveSmoothness(tags)) -- 77,000+ https://taginfo.openstreetmap.org/keys/check_date%3Asurface if tags["check_date:surface"] then - surface_data.surface_age = AgeInDays(ParseDate(tags["check_date:surface"])) + result_tags.surface_age = AgeInDays(ParseDate(tags["check_date:surface"])) end -- 4,000+ https://taginfo.openstreetmap.org/keys/check_date%3Asmoothness if tags["check_date:smoothness"] then - surface_data.smoothness_age = AgeInDays(ParseDate(tags["check_date:smoothness"])) + result_tags.smoothness_age = AgeInDays(ParseDate(tags["check_date:smoothness"])) end - CopyTags(surface_data, tags, tags_copied) - CopyTags(surface_data, tags, tags_prefixed, "osm_") + CopyTags(result_tags, tags, tags_copied) + CopyTags(result_tags, tags, tags_prefixed, "osm_") - return surface_data + return result_tags end From 0c72723c13cd2b60e0b9e3fee6b1de9481f5960d Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 10:17:14 +0100 Subject: [PATCH 19/23] Revert "Bikelanes: Add alternative tagging `path=sidewalk`" This reverts commit 8d457f9ef75cd8f00cf2bc1e901003b738e1a619. --- app/process/roads_bikelanes/bikelanes/categories.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/process/roads_bikelanes/bikelanes/categories.lua b/app/process/roads_bikelanes/bikelanes/categories.lua index 1ed2f2cf..5f108b9e 100644 --- a/app/process/roads_bikelanes/bikelanes/categories.lua +++ b/app/process/roads_bikelanes/bikelanes/categories.lua @@ -89,7 +89,7 @@ local function footAndCyclewaySharedCases(tags) local taggedWithAccessTagging = tags.bicycle == "designated" and tags.foot == "designated" and tags.segregated == "no" local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:240") if taggedWithAccessTagging or taggedWithTrafficsign then - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" or tags.path == "sidewalk" then + if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then return "footAndCyclewayShared_adjoining" end -- Eg https://www.openstreetmap.org/way/440072364 highway=service @@ -108,7 +108,7 @@ local function footAndCyclewaySegregatedCases(tags) local taggedWithAccessTagging = tags.bicycle == "designated" and tags.foot == "designated" and tags.segregated == "yes" local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:241") if taggedWithAccessTagging or taggedWithTrafficsign then - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" or tags.path == "sidewalk" then + if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then return "footAndCyclewaySegregated_adjoining" end if tags.is_sidepath == "no" then @@ -130,9 +130,7 @@ local function footwayBicycleYesCases(tags) if tags.highway == "footway" or tags.highway == "path" then if tags.bicycle == "yes" or IsTermInString("1022-10", tags.traffic_sign) then -- https://www.openstreetmap.org/way/946438663 - -- path=sidewalk is an uncommon alternative to is_sidepath=yes or footway=sidewalk - -- see https://taginfo.geofabrik.de/europe:germany/tags/path=sidewalk#overview - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" or tags.path == "sidewalk" then + if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then return "footwayBicycleYes_isolated" end if tags.is_sidepath == "no" then From c18f05176c20fb9c16ccbd41fd9ab612a44a82f9 Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 10:17:17 +0100 Subject: [PATCH 20/23] Revert "TEMP: disable processing" This reverts commit 59e62953c55049003bda6246480befe7c96a926a. --- app/run.sh | 60 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/app/run.sh b/app/run.sh index 078829b5..476bbe21 100755 --- a/app/run.sh +++ b/app/run.sh @@ -26,33 +26,33 @@ alert() { curl -X POST $url -d "payload=$payload" --silent --output "/dev/null" } -# if ! ./run-1-download.sh; then -# alert '*ERROR*: #run-1-download exited with non-zero status code' -# fi - -# if ! ./run-2-filter.sh; then -# alert '*ERROR*: #run-2-filter exited with non-zero status code' -# fi - -# if ! ./run-3-migration.sh; then -# alert '*ERROR*: #run-3-migration exited with non-zero status code' -# fi - -# process_start_time=$(date +%s) -# if ! ./run-4-process.sh; then -# alert '*ERROR*: #run-4-process exited with non-zero status code' -# fi -# process_end_time=$(date +%s) -# export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh - -# if ! ./run-5-postprocess.sh; then -# alert '*ERROR*: #run-5-postprocess exited with non-zero status code' -# fi - -# if ! ./run-6-analysis.sh; then -# alert '*ERROR*: #run-6-analysis exited with non-zero status code' -# fi - -# if ! ./run-7-metadata.sh; then -# alert '*ERROR*: #run-7-metadata exited with non-zero status code' -# fi +if ! ./run-1-download.sh; then + alert '*ERROR*: #run-1-download exited with non-zero status code' +fi + +if ! ./run-2-filter.sh; then + alert '*ERROR*: #run-2-filter exited with non-zero status code' +fi + +if ! ./run-3-migration.sh; then + alert '*ERROR*: #run-3-migration exited with non-zero status code' +fi + +process_start_time=$(date +%s) +if ! ./run-4-process.sh; then + alert '*ERROR*: #run-4-process exited with non-zero status code' +fi +process_end_time=$(date +%s) +export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh + +if ! ./run-5-postprocess.sh; then + alert '*ERROR*: #run-5-postprocess exited with non-zero status code' +fi + +if ! ./run-6-analysis.sh; then + alert '*ERROR*: #run-6-analysis exited with non-zero status code' +fi + +if ! ./run-7-metadata.sh; then + alert '*ERROR*: #run-7-metadata exited with non-zero status code' +fi From 3d808513e2bc1cc5adce821ba1047b111d9807ce Mon Sep 17 00:00:00 2001 From: Tobias Date: Mon, 19 Feb 2024 10:17:19 +0100 Subject: [PATCH 21/23] Revert "Revert "Release 2024-02-15 (#91)"" This reverts commit 2015c6ba88a089a46300dc9ade124e9b6d1ffd7c. --- .github/workflows/deployment.production.yml | 4 +- .github/workflows/deployment.staging.yml | 2 +- .github/workflows/deployment.yml | 74 +++++++++++++++---- app/process/barriers/barriers.lua | 57 +++----------- .../roads_bikelanes/bikelanes/categories.lua | 15 ++-- app/run.sh | 60 +++++++-------- configs/nginx.conf | 4 +- docker-compose.traefik.yml | 31 -------- docker-compose.yml | 56 +++++++++++++- 9 files changed, 164 insertions(+), 139 deletions(-) delete mode 100644 docker-compose.traefik.yml diff --git a/.github/workflows/deployment.production.yml b/.github/workflows/deployment.production.yml index d4fc00d4..cb777e32 100644 --- a/.github/workflows/deployment.production.yml +++ b/.github/workflows/deployment.production.yml @@ -10,7 +10,7 @@ jobs: uses: ./.github/workflows/deployment.yml with: ENVIRONMENT: production - URL: tiles.radverkehrsatlas.de + TILES_URL: tiles.radverkehrsatlas.de secrets: SERVICE_NAME: ${{ secrets.SERVICE_NAME }} DATABASE_NAME: ${{ secrets.DATABASE_NAME }} @@ -24,4 +24,4 @@ jobs: SSH_USERNAME: ${{ secrets.SSH_USERNAME }} SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} SYNOLOGY_LOG_TOKEN: ${{ secrets.SYNOLOGY_LOG_TOKEN }} - SYNOLOGY_ERROR_LOG_TOKEN: ${{ secrets.SYNOLOGY_ERROR_LOG_TOKEN }} \ No newline at end of file + SYNOLOGY_ERROR_LOG_TOKEN: ${{ secrets.SYNOLOGY_ERROR_LOG_TOKEN }} diff --git a/.github/workflows/deployment.staging.yml b/.github/workflows/deployment.staging.yml index 17dffafa..2c579bed 100644 --- a/.github/workflows/deployment.staging.yml +++ b/.github/workflows/deployment.staging.yml @@ -10,7 +10,7 @@ jobs: uses: ./.github/workflows/deployment.yml with: ENVIRONMENT: staging - URL: staging-tiles.radverkehrsatlas.de + TILES_URL: staging-tiles.radverkehrsatlas.de secrets: SERVICE_NAME: ${{ secrets.SERVICE_NAME }} DATABASE_NAME: ${{ secrets.DATABASE_NAME }} diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index bef2fca0..ed76ce20 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -33,7 +33,7 @@ on: ENVIRONMENT: type: string required: true - URL: + TILES_URL: type: string required: true @@ -42,11 +42,40 @@ jobs: runs-on: ubuntu-latest environment: name: ${{ inputs.ENVIRONMENT }} - url: https://${{ inputs.URL }} + url: https://${{ inputs.TILES_URL }} steps: - uses: actions/checkout@v4 + with: + fetch-depth: 6 + + - name: Get last run commit SHA + id: last_run + run: | + LAST_RUN_SHA=$(curl --request GET \ + --url https://api.github.com/repos/${{ github.repository }}/actions/runs \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + | jq -r '.workflow_runs[1].head_sha') + echo "::set-output name=sha::$LAST_RUN_SHA" + shell: bash + + - name: Check if LAST_RUN_SHA is one of the last 6 commits and check changes + id: git_changes + run: | + LAST_6_COMMITS=$(git log -n 6 --pretty=format:"%H") + if echo "$LAST_6_COMMITS" | grep -q "${{ steps.last_run.outputs.sha }}"; then + if git diff --quiet ${{ steps.last_run.outputs.sha }} HEAD -- app/ helpers/ app.Dockerfile docker-compose.yml; then + echo "::set-output name=changes::false" + else + echo "::set-output name=changes::true" + fi + else + echo "::set-output name=changes::true" + fi + shell: bash + - name: Upgrade AWS CLI version and setup lightsailctl + if: steps.git_changes.outputs.changes == 'true' run: | aws --version curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" @@ -58,6 +87,7 @@ jobs: sudo chmod +x /usr/local/bin/lightsailctl - name: Configure AWS credentials + if: steps.git_changes.outputs.changes == 'true' uses: aws-actions/configure-aws-credentials@v2 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -65,9 +95,11 @@ jobs: aws-region: ${{ secrets.AWS_REGION }} - name: Setup buildx + if: steps.git_changes.outputs.changes == 'true' uses: docker/setup-buildx-action@v3 - name: Build app image + if: steps.git_changes.outputs.changes == 'true' uses: docker/build-push-action@v5 with: context: . @@ -79,6 +111,7 @@ jobs: tags: public.ecr.aws/n0p8j4k5/atlas/app:${{ github.sha }} - name: Push the app image + if: steps.git_changes.outputs.changes == 'true' run: | aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/n0p8j4k5/ docker push public.ecr.aws/n0p8j4k5/atlas/app:${{ github.sha }} @@ -93,6 +126,17 @@ jobs: target: "/srv/processing/" overwrite: true + - name: Update GITHUB_SHA + if: steps.git_changes.outputs.changes == 'true' + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + script: | + cd /srv/processing/ + sed -i "s|^GITHUB_SHA=.*$|GITHUB_SHA='${{ github.sha }}'|" .env + - name: Stop & Start containers on VPS uses: appleboy/ssh-action@master with: @@ -101,20 +145,18 @@ jobs: password: ${{ secrets.SSH_PASSWORD }} script: | cd /srv/processing/ - echo "Updating '.env'" - rm .env - touch .env - echo PGHOST='${{ vars.DATABASE_HOST }}' >> .env - echo ENVIRONMENT='${{ inputs.ENVIRONMENT }}' >> .env - echo SYNOLOGY_LOG_TOKEN='${{ secrets.SYNOLOGY_LOG_TOKEN }}' >> .env - echo SYNOLOGY_ERROR_LOG_TOKEN='${{ secrets.SYNOLOGY_ERROR_LOG_TOKEN }}' >> .env - echo PGUSER='${{ secrets.DATABASE_USER }}' >> .env - echo PGPASSWORD='${{ secrets.DATABASE_PASSWORD }}' >> .env - echo PGDATABASE='${{ secrets.DATABASE_NAME }}' >> .env - echo OSM_DOWNLOAD_URL='${{ vars.OSM_DOWNLOAD_URL }}' >> .env - echo URL='${{ inputs.URL }}' >> .env - echo GITHUB_SHA='${{ github.sha }}' >> .env + sed -i \ + -e "s|^PGHOST=.*$|PGHOST='${{ vars.DATABASE_HOST }}'|" \ + -e "s|^ENVIRONMENT=.*$|ENVIRONMENT='${{ inputs.ENVIRONMENT }}'|" \ + -e "s|^SYNOLOGY_LOG_TOKEN=.*$|SYNOLOGY_LOG_TOKEN='${{ secrets.SYNOLOGY_LOG_TOKEN }}'|" \ + -e "s|^SYNOLOGY_ERROR_LOG_TOKEN=.*$|SYNOLOGY_ERROR_LOG_TOKEN='${{ secrets.SYNOLOGY_ERROR_LOG_TOKEN }}'|" \ + -e "s|^PGUSER=.*$|PGUSER='${{ secrets.DATABASE_USER }}'|" \ + -e "s|^PGPASSWORD=.*$|PGPASSWORD='${{ secrets.DATABASE_PASSWORD }}'|" \ + -e "s|^PGDATABASE=.*$|PGDATABASE='${{ secrets.DATABASE_NAME }}'|" \ + -e "s|^OSM_DOWNLOAD_URL=.*$|OSM_DOWNLOAD_URL='${{ vars.OSM_DOWNLOAD_URL }}'|" \ + -e "s|^TILES_URL=.*$|TILES_URL='${{ inputs.TILES_URL }}'|" \ + .env echo "Reload containers" - docker compose -f docker-compose.traefik.yml up -d + docker compose pull docker compose up -d docker image prune -fa diff --git a/app/process/barriers/barriers.lua b/app/process/barriers/barriers.lua index 8d429952..b4438912 100644 --- a/app/process/barriers/barriers.lua +++ b/app/process/barriers/barriers.lua @@ -14,16 +14,6 @@ local lineBarriers = osm2pgsql.define_table({ } }) --- local excludedLineBarriers = osm2pgsql.define_table({ --- name = 'barrierLines_excluded', --- ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, --- columns = { --- { column = 'tags', type = 'jsonb' }, --- { column = 'meta', type = 'jsonb' }, --- { column = 'geom', type = 'linestring' }, --- } --- }) - local areaBarriers = osm2pgsql.define_table({ name = 'barrierAreas', ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, @@ -34,17 +24,6 @@ local areaBarriers = osm2pgsql.define_table({ } }) --- local excludedAreaBarriers = osm2pgsql.define_table({ --- name = 'barrierAreas_excluded', --- ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' }, --- columns = { --- { column = 'tags', type = 'jsonb' }, --- { column = 'meta', type = 'jsonb' }, --- { column = 'geom', type = 'multipolygon' }, --- } --- }) - - local allowedTags = Set({ 'tunnel', 'waterway', @@ -91,44 +70,33 @@ function osm2pgsql.process_way(object) FilterTags(object.tags, allowedTags) areaBarriers:insert({ tags = object.tags, - meta=Metadata(object), - geom=object:as_multipolygon() + meta = Metadata(object), + geom = object:as_multipolygon() }) return end - -- excludedAreaBarriers:insert({ - -- tags=object.tags, - -- meta=Metadata(object), - -- geom=object:as_multipolygon() - -- }) else --process as linestring local tags = object.tags - -- if tags.tunnel =='yes' then return end -- we don't consider tunnels as barriers - local isBarrier = HighwayClasses[tags.highway] - -- only need for low zoom levels - local waterBarriers = Set({"river", "canal"}) + -- waterways as lines are used for low zoom levels + local waterBarriers = Set({ "river", "canal" }) isBarrier = isBarrier or waterBarriers[tags.waterway] - local trainBarriers = Set({"main", "branch"}) + local trainBarriers = Set({ "main", "branch" }) if (tags.railway == 'rail' or tags.railway == 'light_rail') then isBarrier = isBarrier or trainBarriers[tags.usage] end + if isBarrier then FilterTags(object.tags, allowedTags) lineBarriers:insert({ tags = object.tags, - meta=Metadata(object), - geom=object:as_linestring(), + meta = Metadata(object), + geom = object:as_linestring(), }) return end - -- excludedLineBarriers:insert({ - -- tags=object.tags, - -- meta=Metadata(object), - -- geom=object:as_linestring() - -- }) end end @@ -137,14 +105,9 @@ function osm2pgsql.process_relation(object) FilterTags(object.tags, allowedTags) areaBarriers:insert({ tags = object.tags, - meta=Metadata(object), - geom=object:as_multipolygon() + meta = Metadata(object), + geom = object:as_multipolygon() }) return end - -- excludedAreaBarriers:insert({ - -- tags=object.tags, - -- meta=Metadata(object), - -- geom=object:as_multipolygon() - -- }) end diff --git a/app/process/roads_bikelanes/bikelanes/categories.lua b/app/process/roads_bikelanes/bikelanes/categories.lua index 5f108b9e..cb27fc93 100644 --- a/app/process/roads_bikelanes/bikelanes/categories.lua +++ b/app/process/roads_bikelanes/bikelanes/categories.lua @@ -89,7 +89,8 @@ local function footAndCyclewaySharedCases(tags) local taggedWithAccessTagging = tags.bicycle == "designated" and tags.foot == "designated" and tags.segregated == "no" local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:240") if taggedWithAccessTagging or taggedWithTrafficsign then - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then + -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then return "footAndCyclewayShared_adjoining" end -- Eg https://www.openstreetmap.org/way/440072364 highway=service @@ -108,7 +109,8 @@ local function footAndCyclewaySegregatedCases(tags) local taggedWithAccessTagging = tags.bicycle == "designated" and tags.foot == "designated" and tags.segregated == "yes" local taggedWithTrafficsign = osm2pgsql.has_prefix(tags.traffic_sign, "DE:241") if taggedWithAccessTagging or taggedWithTrafficsign then - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then + -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then return "footAndCyclewaySegregated_adjoining" end if tags.is_sidepath == "no" then @@ -129,12 +131,13 @@ local function footwayBicycleYesCases(tags) if tags.highway == "footway" or tags.highway == "path" then if tags.bicycle == "yes" or IsTermInString("1022-10", tags.traffic_sign) then - -- https://www.openstreetmap.org/way/946438663 - if tags.is_sidepath == "yes" or tags.footway == "sidewalk" then - return "footwayBicycleYes_isolated" + -- `_parent_highway` indicates that this way was split of the centerline; in this case, we consider it a sidepath. + if tags.is_sidepath == "yes" or tags._parent_highway or tags.footway == "sidewalk" then + return "footwayBicycleYes_adjoining" end + -- https://www.openstreetmap.org/way/946438663 if tags.is_sidepath == "no" then - return "footwayBicycleYes_adjoining" + return "footwayBicycleYes_isolated" end return "footwayBicycleYes_adjoiningOrIsolated" end diff --git a/app/run.sh b/app/run.sh index 476bbe21..078829b5 100755 --- a/app/run.sh +++ b/app/run.sh @@ -26,33 +26,33 @@ alert() { curl -X POST $url -d "payload=$payload" --silent --output "/dev/null" } -if ! ./run-1-download.sh; then - alert '*ERROR*: #run-1-download exited with non-zero status code' -fi - -if ! ./run-2-filter.sh; then - alert '*ERROR*: #run-2-filter exited with non-zero status code' -fi - -if ! ./run-3-migration.sh; then - alert '*ERROR*: #run-3-migration exited with non-zero status code' -fi - -process_start_time=$(date +%s) -if ! ./run-4-process.sh; then - alert '*ERROR*: #run-4-process exited with non-zero status code' -fi -process_end_time=$(date +%s) -export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh - -if ! ./run-5-postprocess.sh; then - alert '*ERROR*: #run-5-postprocess exited with non-zero status code' -fi - -if ! ./run-6-analysis.sh; then - alert '*ERROR*: #run-6-analysis exited with non-zero status code' -fi - -if ! ./run-7-metadata.sh; then - alert '*ERROR*: #run-7-metadata exited with non-zero status code' -fi +# if ! ./run-1-download.sh; then +# alert '*ERROR*: #run-1-download exited with non-zero status code' +# fi + +# if ! ./run-2-filter.sh; then +# alert '*ERROR*: #run-2-filter exited with non-zero status code' +# fi + +# if ! ./run-3-migration.sh; then +# alert '*ERROR*: #run-3-migration exited with non-zero status code' +# fi + +# process_start_time=$(date +%s) +# if ! ./run-4-process.sh; then +# alert '*ERROR*: #run-4-process exited with non-zero status code' +# fi +# process_end_time=$(date +%s) +# export PROCESS_RUN_TIME_DIFF=$((process_end_time - process_start_time)) # used by metadata.sh + +# if ! ./run-5-postprocess.sh; then +# alert '*ERROR*: #run-5-postprocess exited with non-zero status code' +# fi + +# if ! ./run-6-analysis.sh; then +# alert '*ERROR*: #run-6-analysis exited with non-zero status code' +# fi + +# if ! ./run-7-metadata.sh; then +# alert '*ERROR*: #run-7-metadata exited with non-zero status code' +# fi diff --git a/configs/nginx.conf b/configs/nginx.conf index 76af1598..084fa879 100644 --- a/configs/nginx.conf +++ b/configs/nginx.conf @@ -35,7 +35,7 @@ http { proxy_cache_path /var/cache/nginx/ levels=1:2 - max_size=15g + max_size=50g inactive=60m use_temp_path=off keys_zone=backend_cache:240m; @@ -61,7 +61,7 @@ http { proxy_cache backend_cache; proxy_cache_lock on; proxy_cache_revalidate on; - proxy_cache_valid 200 204 302 1d; + proxy_cache_valid 200 204 302 12h; proxy_cache_valid 404 1m; proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; add_header X-Cache-Status $upstream_cache_status; diff --git a/docker-compose.traefik.yml b/docker-compose.traefik.yml deleted file mode 100644 index e47bc227..00000000 --- a/docker-compose.traefik.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: "3" -services: - traefik: - image: traefik:v2.10 - container_name: traefik - # See https://techoverflow.net/2021/06/11/how-to-fix-traefik-gateway-timeout-for-docker-services/ for network_mode - network_mode: host - restart: always - command: - - "--log.level=WARN" - - "--api.insecure=false" - - "--api.dashboard=false" - - "--providers.docker=true" - # Do not expose containers unless explicitly told so - - "--providers.docker.exposedbydefault=false" - - "--entrypoints.web.address=:80" - - "--entrypoints.websecure.address=:443" - - "--entrypoints.web.http.redirections.entryPoint.to=websecure" - - "--entrypoints.web.http.redirections.entryPoint.scheme=https" - - "--certificatesresolvers.letsencrypt.acme.httpchallenge=true" - - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web" - - "--certificatesresolvers.letsencrypt.acme.email=dev-team@fixmycity.de" - - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json" - - "--serversTransport.forwardingTimeouts.dialTimeout=100s" - ports: - - "80:80" - - "443:443" - - "8080:8080" - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - "./letsencrypt:/letsencrypt" diff --git a/docker-compose.yml b/docker-compose.yml index ad1dfd34..dad72754 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,35 @@ version: "3" services: + traefik: + image: traefik:v2.10 + container_name: traefik + # Networking: See https://techoverflow.net/2021/06/11/how-to-fix-traefik-gateway-timeout-for-docker-services/ for network_mode + restart: unless-stopped + command: + - "--log.level=WARN" + - "--api.insecure=false" + - "--api.dashboard=false" + - "--providers.docker=true" + # Do not expose containers unless explicitly told so + - "--providers.docker.exposedbydefault=false" + - "--entrypoints.web.address=:80" + - "--entrypoints.websecure.address=:443" + - "--entrypoints.web.http.redirections.entryPoint.to=websecure" + - "--entrypoints.web.http.redirections.entryPoint.scheme=https" + - "--certificatesresolvers.letsencrypt.acme.httpchallenge=true" + - "--certificatesresolvers.letsencrypt.acme.httpchallenge.entrypoint=web" + - "--certificatesresolvers.letsencrypt.acme.email=dev-team@fixmycity.de" + - "--certificatesresolvers.letsencrypt.acme.storage=/letsencrypt/acme.json" + - "--serversTransport.forwardingTimeouts.dialTimeout=100s" + ports: + - "80:80" + - "443:443" + - "8080:8080" + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - "./letsencrypt:/letsencrypt" + networks: + - app_bridge app: image: public.ecr.aws/n0p8j4k5/atlas/app:${GITHUB_SHA} entrypoint: /app/run.sh @@ -35,17 +65,35 @@ services: command: ["--auto-bounds=calc"] ports: - 3333:3000 + labels: + - "traefik.enable=false" + networks: + - app_bridge + depends_on: + db: + condition: service_healthy + proxy: + image: nginx:alpine + restart: unless-stopped + container_name: tiles_proxy labels: - "traefik.enable=true" - - "traefik.http.routers.tiles.rule=Host(`${URL}`)" + - "traefik.http.routers.tiles.rule=Host(`${TILES_URL}`)" - "traefik.http.routers.tiles.entrypoints=websecure" - "traefik.http.routers.tiles.tls.certresolver=letsencrypt" - "traefik.http.routers.tiles.tls=true" networks: - app_bridge - depends_on: - db: - condition: service_healthy + ports: + - "4444:80" + volumes: + - ./cache:/var/cache/nginx + - ./logs:/var/log/nginx + - ./configs/nginx.conf:/etc/nginx/nginx.conf:ro + # Needs healty check for tiles server + # depends_on: + # tiles: + # condition: service_healthy db: image: postgis/postgis:14-3.3-alpine container_name: db From d2c2209167f67821afdb827f922271bd4051018a Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 19 Feb 2024 10:53:13 +0100 Subject: [PATCH 22/23] remove comment --- app/process/places/places.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/app/process/places/places.lua b/app/process/places/places.lua index f622bfed..922164fb 100644 --- a/app/process/places/places.lua +++ b/app/process/places/places.lua @@ -36,7 +36,6 @@ end local function processTags(tags) local tags_cc = Set({ "name", "place", "capital", "website", "wikidata", "wikipedia", "population", "population:date", "admin_level" }) - -- TODO: I don't think that we need the line bellow, osm2pgsql should convert this automatically tags.population = tonumber(tags.population) return CopyTags({}, tags, tags_cc) end From ef83a4b7763c7e49b0fc963d2cf92e835f08b63e Mon Sep 17 00:00:00 2001 From: rush42 Date: Mon, 19 Feb 2024 11:34:13 +0100 Subject: [PATCH 23/23] rename parameter: `default` -> `fallback` --- app/process/helper/Sanitize.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/process/helper/Sanitize.lua b/app/process/helper/Sanitize.lua index 756ba66c..044418ac 100644 --- a/app/process/helper/Sanitize.lua +++ b/app/process/helper/Sanitize.lua @@ -1,11 +1,11 @@ ---@param value any ---@param allowed table ----@param default? any +---@param fallback? any ---@return any -- makes sure that `value` is in the set `allowed`. Returns `default` if value is nil -function Sanitize(value, allowed, default) +function Sanitize(value, allowed, fallback) if value == nil then - return default + return fallback end if allowed[value] then return value