From a049569020744324bd8c4538770ed4464727efb0 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 11 Sep 2025 10:01:24 +0200 Subject: [PATCH 1/3] downgrade Japanese boundaries one level Definition is shifted by one compared to other countries, see https://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative --- settings/address-levels.json | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/settings/address-levels.json b/settings/address-levels.json index 1b1ef7e7..93ceef3b 100644 --- a/settings/address-levels.json +++ b/settings/address-levels.json @@ -21,8 +21,8 @@ "croft" : 20, "subdivision" : 22, "allotments" : 22, - "neighbourhood" : [20, 22], - "quarter" : [20, 22], + "neighbourhood" : 22, + "quarter" : 22, "isolated_dwelling" : [22, 25], "farm" : [22, 25], "city_block" : 25, @@ -236,6 +236,20 @@ "administrative11" : 20 } } +}, +{ "countries" : ["jp"], + "tags" : { + "boundary" : { + "administrative7" : 16, + "administrative8" : 18, + "administrative9" : 20, + "administrative10" : 22, + "administrative11" : 24 + }, + "place" : { + "neighbourhood" : 24 + } + } } ] From 433c40cd68d4847335710ab4f057e747c39955a5 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 11 Sep 2025 10:20:33 +0200 Subject: [PATCH 2/3] downgrade neighbourhoods and landuses Neighbourhoods shoud be below a quarter hierarchically speaking, so downgrade them a bit. Consider named landuses the area form of a meighbourhood and put it at the same level. --- settings/address-levels.json | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/settings/address-levels.json b/settings/address-levels.json index 93ceef3b..eb3f2acd 100644 --- a/settings/address-levels.json +++ b/settings/address-levels.json @@ -21,8 +21,8 @@ "croft" : 20, "subdivision" : 22, "allotments" : 22, - "neighbourhood" : 22, - "quarter" : 22, + "neighbourhood" : 24, + "quarter" : [20, 22], "isolated_dwelling" : [22, 25], "farm" : [22, 25], "city_block" : 25, @@ -48,14 +48,14 @@ "" : [25, 0] }, "landuse" : { - "residential" : 22, - "farm" : 22, - "farmyard" : 22, - "industrial" : 22, - "commercial" : 22, - "allotments" : 22, - "retail" : 22, - "" : [22, 0] + "residential" : 24, + "farm" : 24, + "farmyard" : 24, + "industrial" : 24, + "commercial" : 24, + "allotments" : 24, + "retail" : 24, + "" : [24, 0] }, "leisure" : { "park" : [24, 0] @@ -245,9 +245,6 @@ "administrative9" : 20, "administrative10" : 22, "administrative11" : 24 - }, - "place" : { - "neighbourhood" : 24 } } } From 1d1d80e1e3f08b3729032b0d5fb84e0c9b168d14 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 11 Sep 2025 11:56:39 +0200 Subject: [PATCH 3/3] adapt BDD tests for new address ranks --- lib-sql/functions/placex_triggers.sql | 16 ++++++++++++++++ test/bdd/features/db/import/placex.feature | 6 +++--- .../features/db/import/rank_computation.feature | 8 ++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib-sql/functions/placex_triggers.sql b/lib-sql/functions/placex_triggers.sql index d5aafa3f..600ba401 100644 --- a/lib-sql/functions/placex_triggers.sql +++ b/lib-sql/functions/placex_triggers.sql @@ -530,6 +530,7 @@ CREATE OR REPLACE FUNCTION insert_addresslines(obj_place_id BIGINT, AS $$ DECLARE address_havelevel BOOLEAN[]; + place_min_distance FLOAT[]; location_isaddress BOOLEAN; current_boundary GEOMETRY := NULL; @@ -545,6 +546,7 @@ BEGIN nameaddress_vector := '{}'::int[]; address_havelevel := array_fill(false, ARRAY[maxrank]); + place_min_distance := array_fill(1.0, ARRAY[maxrank]); FOR location IN SELECT apl.*, key @@ -575,6 +577,10 @@ BEGIN END IF; END IF; + IF location.isguess and location.distance < place_min_distance[location.rank_address] THEN + place_min_distance[location.rank_address] := location.distance; + END IF; + INSERT INTO place_addressline (place_id, address_place_id, fromarea, isaddress, distance, cached_rank_address) VALUES (obj_place_id, location.place_id, not location.isguess, @@ -602,6 +608,16 @@ BEGIN -- If this is the first item in the rank, then assume it is the address. location_isaddress := not address_havelevel[location.rank_address]; + -- Ignore guessed places when they are too far away compared to similar closer ones. + IF location.isguess THEN + CONTINUE WHEN not location_isaddress + AND location.distance > 2 * place_min_distance[location.rank_address]; + + IF location.distance < place_min_distance[location.rank_address] THEN + place_min_distance[location.rank_address] := location.distance; + END IF; + END IF; + -- Further sanity checks to ensure that the address forms a sane hierarchy. IF location_isaddress THEN IF location.isguess and current_node_area is not NULL THEN diff --git a/test/bdd/features/db/import/placex.feature b/test/bdd/features/db/import/placex.feature index 8c1e4a8a..8b4a07db 100644 --- a/test/bdd/features/db/import/placex.feature +++ b/test/bdd/features/db/import/placex.feature @@ -135,9 +135,9 @@ Feature: Import into placex | object | rank_search | rank_address | | N2 | 30 | 30 | | W2 | 30 | 30 | - | W4 | 22 | 22 | - | R2 | 22 | 22 | - | R3 | 22 | 0 | + | W4 | 24 | 24 | + | R2 | 24 | 24 | + | R3 | 24 | 0 | Scenario: rank and inclusion of naturals Given the 0.4 grid diff --git a/test/bdd/features/db/import/rank_computation.feature b/test/bdd/features/db/import/rank_computation.feature index de123a56..5be941b2 100644 --- a/test/bdd/features/db/import/rank_computation.feature +++ b/test/bdd/features/db/import/rank_computation.feature @@ -114,10 +114,10 @@ Feature: Rank assignment Scenario: Admin levels must not be larger than 25 Given the named places - | osm | class | type | admin | extra+place | geometry | - | R20 | boundary | administrative | 6 | neighbourhood | (0 0, 0 2, 2 2, 2 0, 0 0) | - | R21 | boundary | administrative | 7 | | (0 0, 0 1, 1 1, 1 0, 0 0) | - | R22 | boundary | administrative | 8 | | (0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0) | + | osm | class | type | admin | extra+place | geometry | + | R20 | boundary | administrative | 6 | quarter | (0 0, 0 2, 2 2, 2 0, 0 0) | + | R21 | boundary | administrative | 7 | | (0 0, 0 1, 1 1, 1 0, 0 0) | + | R22 | boundary | administrative | 8 | | (0 0, 0 0.5, 0.5 0.5, 0.5 0, 0 0) | When importing Then placex contains | object | rank_search | rank_address |