]> git.openstreetmap.org Git - nominatim.git/commitdiff
demote place nodes in admin areas
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 7 Oct 2020 15:33:52 +0000 (17:33 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 11 Oct 2020 10:04:53 +0000 (12:04 +0200)
If a place node of city rank and above finds itself in an
administrative boundary of the same address rank, then
increase the address rank by 2. This catches the rather
frequent case where city suburbs are tagged for historical
reasons as towns or villages.

sql/functions/placex_triggers.sql

index 9ef83b82d3ed9b9db332796a43dcab09c9186917..8c9cfae120bf9666e7e35c1b964f78efb0fc6704 100644 (file)
@@ -624,6 +624,21 @@ BEGIN
         NEW.rank_address := parent_address_level + 2;
       END IF;
     END IF;
+  -- If a place node is contained in a admin boundary with the same address level
+  -- and has not been linked, then make the node a subpart by increasing the
+  -- address rank (city level and above).
+  ELSEIF NEW.class = 'place' and NEW.osm_type = 'N'
+     and NEW.rank_address between 16 and 23
+  THEN
+    FOR location IN
+        SELECT rank_address FROM placex
+        WHERE osm_type = 'R' and class = 'boundary' and type = 'administrative'
+              and rank_address = NEW.rank_address
+              and geometry && NEW.centroid and _ST_Covers(geometry, NEW.centroid)
+        LIMIT 1
+    LOOP
+      NEW.rank_address = NEW.rank_address + 2;
+    END LOOP;
   ELSE
     parent_address_level := 3;
   END IF;