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).
This commit is contained in:
Sarah Hoffmann
2020-02-19 09:50:19 +01:00
parent 00ca493f33
commit 06fdfad89e
2 changed files with 53 additions and 3 deletions

View File

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

View File

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