]> git.openstreetmap.org Git - nominatim.git/commitdiff
minor fixes for geometry compuation during boundary ranking
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 23 Oct 2020 08:43:57 +0000 (10:43 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Wed, 28 Oct 2020 09:49:26 +0000 (10:49 +0100)
Go back to using centroid when determining if one admin level
is within another. There are cases where boundaries are slightly
misaligned due to mapping errors (not using the same ways in the
relations).

Only declare boundaries the same when they have the same wikidata
tag _and_ have exactly the same geometry. This works around tagging
errors with the wikidata tag, which happen because of automated
edits to the wikidata tag.

sql/functions/placex_triggers.sql
test/bdd/db/import/rank_computation.feature

index 837f8fd369f1a722c1159149553f2ce2f982d080..1e2aac4c96fcc88a6e188eacf43a0888135458e6 100644 (file)
@@ -585,16 +585,19 @@ BEGIN
     -- First, check that admin boundaries do not overtake each other rank-wise.
     parent_address_level := 3;
     FOR location IN
-      SELECT rank_address, extratags FROM placex
+      SELECT rank_address,
+             (CASE WHEN extratags ? 'wikidata' and NEW.extratags ? 'wikidata'
+                        and extratags->'wikidata' = NEW.extratags->'wikidata'
+                   THEN ST_Equals(geometry, NEW.geometry)
+                   ELSE false END) as is_same
+      FROM placex
       WHERE osm_type = 'R' and class = 'boundary' and type = 'administrative'
             and admin_level < NEW.admin_level and admin_level > 3
             and rank_address > 0
-            and ST_Covers(geometry, NEW.geometry)
+            and geometry && NEW.centroid and _ST_Covers(geometry, NEW.centroid)
       ORDER BY admin_level desc LIMIT 1
     LOOP
-      IF location.extratags ? 'wikidata' and NEW.extratags ? 'wikidata'
-         and location.extratags->'wikidata' = NEW.extratags->'wikidata'
-      THEN
+      IF location.is_same THEN
         -- Looks like the same boundary is replicated on multiple admin_levels.
         -- Usual tagging in Poland. Remove our boundary from addresses.
         NEW.rank_address := 0;
index beecb36658536324c786912d292082cdd68f6101..0fe440ce835210144b9046afd7c7e641f8f70e9b 100644 (file)
@@ -101,6 +101,20 @@ Feature: Rank assignment
             | R21    | R20     | 16                  |
             | R22    | R20     | 16                  |
 
+    Scenario: Admin levels cannot overtake each other due to place address ranks even when slightly misaligned
+        Given the named places
+          | osm | class    | type           | admin | extra+place  | geometry |
+          | R20 | boundary | administrative | 6     | town         | (0 0, 0 2, 2 2, 2 0, 0 0) |
+          | R21 | boundary | administrative | 8     |              | (0 0, -0.0001 1, 1 1, 1 0, 0 0) |
+        When importing
+        Then placex contains
+          | object | rank_search | rank_address |
+          | R20    | 12          | 16 |
+          | R21    | 16          | 18 |
+        Then place_addressline contains
+            | object | address | cached_rank_address |
+            | R21    | R20     | 16                  |
+
     Scenario: Admin levels must not be larger than 25
         Given the named places
           | osm | class    | type           | admin | extra+place   | geometry |