]> git.openstreetmap.org Git - nominatim.git/commitdiff
link against place nodes by place type
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 19 Feb 2020 08:50:19 +0000 (09:50 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 28 Feb 2020 14:22:48 +0000 (15:22 +0100)
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
test/bdd/db/import/linking.feature

index f301f4244bf4b1b5a682ea4214f51d3585d048e2..9743eeade7781a9aa312f542bf750452db0bc799 100644 (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;
index c6381792be8a3e7cb5291449ccb364ec6b472467..646f89da179beee066969aab6c4b81c0eaef2fe1 100644 (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 |
+