From 06fdfad89ef04940e3922116f415b361ab1acaf4 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 19 Feb 2020 09:50:19 +0100 Subject: [PATCH] link against place nodes by place type If a boundary relation has no label member preferably link against a place node with the same place type. Also inherit the rank_address from the place node (only has an effect when linking via lable member or place type). --- sql/functions/placex_triggers.sql | 26 +++++++++++++++++++++++--- test/bdd/db/import/linking.feature | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/sql/functions/placex_triggers.sql b/sql/functions/placex_triggers.sql index f301f424..9743eead 100644 --- a/sql/functions/placex_triggers.sql +++ b/sql/functions/placex_triggers.sql @@ -204,9 +204,26 @@ BEGIN END IF; END IF; + -- If extratags has a place tag, look for linked nodes by their place type. + -- Area and node still have to have the same name. + IF bnd.extratags ? 'place' and bnd_name is not null THEN + FOR linked_placex IN + SELECT * FROM placex + WHERE make_standard_name(name->'name') = bnd_name + AND placex.class = 'place' AND placex.type = bnd.extratags->'place' + AND placex.osm_type = 'N' + AND placex.rank_search < 26 -- needed to select the right index + AND _st_covers(bnd.geometry, placex.geometry) + LOOP + --DEBUG: RAISE WARNING 'Found type-matching place node %', linked_placex.osm_id; + RETURN linked_placex; + END LOOP; + END IF; + -- Search for relation members with role admin_center. IF bnd.osm_type = 'R' and bnd_name is not null - and relation_members is not null THEN + and relation_members is not null + THEN FOR rel_member IN SELECT get_rel_node_members(relation_members, ARRAY['admin_center','admin_centre']) as member @@ -231,7 +248,7 @@ BEGIN END IF; -- Name searches can be done for ways as well as relations - IF bnd.osm_type in ('W','R') and bnd_name is not null THEN + IF bnd_name is not null THEN --DEBUG: RAISE WARNING 'Looking for nodes with matching names'; FOR linked_placex IN SELECT placex.* from placex @@ -241,7 +258,7 @@ BEGIN AND placex.rank_search < 26 -- needed to select the right index AND _st_covers(bnd.geometry, placex.geometry) LOOP - --DEBUG: RAISE WARNING 'Found matching place node %', linkedPlacex.osm_id; + --DEBUG: RAISE WARNING 'Found matching place node %', linked_placex.osm_id; RETURN linked_placex; END LOOP; END IF; @@ -824,6 +841,9 @@ BEGIN NEW.centroid := coalesce(location.centroid, ST_Centroid(location.geometry)); + -- Use the address rank of the linked place + NEW.rank_address := location.rank_address; + -- merge in the label name IF NOT location.name IS NULL THEN NEW.name := location.name || NEW.name; diff --git a/test/bdd/db/import/linking.feature b/test/bdd/db/import/linking.feature index c6381792..646f89da 100644 --- a/test/bdd/db/import/linking.feature +++ b/test/bdd/db/import/linking.feature @@ -143,3 +143,33 @@ Feature: Linking of places | object | centroid | name+name | extratags+linked_place | | R13 | 0.006 0.00001 | Garbo | hamlet | + Scenario: Boundaries with place tags are linked against places with same type + Given the places + | osm | class | type | admin | name | extra+place | geometry | + | R13 | boundary | administrative | 5 | Berlin | city |poly-area:0.1 | + And the places + | osm | class | type | name | geometry | + | N2 | place | city | Berlin | 0.006 0.00001 | + When importing + Then placex contains + | object | linked_place_id | + | N2 | R13 | + And placex contains + | object | rank_address | + | R13 | 16 | + + Scenario: Boundaries without place tags only link against same admin level + Given the places + | osm | class | type | admin | name | geometry | + | R13 | boundary | administrative | 5 | Berlin |poly-area:0.1 | + And the places + | osm | class | type | name | geometry | + | N2 | place | city | Berlin | 0.006 0.00001 | + When importing + Then placex contains + | object | linked_place_id | + | N2 | - | + And placex contains + | object | rank_address | + | R13 | 10 | + -- 2.39.5