From b04463bb2d522d37de3ac4e56f2553144ff83604 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 7 Oct 2020 17:33:52 +0200 Subject: [PATCH] demote place nodes in admin areas 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 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sql/functions/placex_triggers.sql b/sql/functions/placex_triggers.sql index 9ef83b82..8c9cfae1 100644 --- a/sql/functions/placex_triggers.sql +++ b/sql/functions/placex_triggers.sql @@ -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; -- 2.39.5