Merge pull request #3834 from lonvia/neighbourhoods

Improve handling of neighbourhoods in addresses
This commit is contained in:
Sarah Hoffmann
2025-09-11 15:25:01 +02:00
committed by GitHub
4 changed files with 43 additions and 16 deletions

View File

@@ -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

View File

@@ -21,7 +21,7 @@
"croft" : 20,
"subdivision" : 22,
"allotments" : 22,
"neighbourhood" : [20, 22],
"neighbourhood" : 24,
"quarter" : [20, 22],
"isolated_dwelling" : [22, 25],
"farm" : [22, 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]
@@ -236,6 +236,17 @@
"administrative11" : 20
}
}
},
{ "countries" : ["jp"],
"tags" : {
"boundary" : {
"administrative7" : 16,
"administrative8" : 18,
"administrative9" : 20,
"administrative10" : 22,
"administrative11" : 24
}
}
}
]

View File

@@ -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

View File

@@ -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 |