]> git.openstreetmap.org Git - nominatim.git/blobdiff - sql/functions/placex_triggers.sql
Merge pull request #1960 from lonvia/fix-postcodes-duplicated-by-normalization
[nominatim.git] / sql / functions / placex_triggers.sql
index ccee3c826b40cf9e2813bce758d07e9e8387bdd3..3ddb97c04240225d87345360bbddf7e3ddbd52d7 100644 (file)
@@ -92,7 +92,7 @@ BEGIN
     END IF;
 
     IF fallback THEN
-      IF ST_Area(bbox) < 0.01 THEN
+      IF ST_Area(bbox) < 0.005 THEN
         -- for smaller features get the nearest road
         SELECT getNearestRoadPlaceId(poi_partition, bbox) INTO parent_place_id;
         --DEBUG: RAISE WARNING 'Checked for nearest way (%)', parent_place_id;
@@ -581,6 +581,11 @@ BEGIN
     RETURN NEW;
   END IF;
 
+  -- Speed up searches - just use the centroid of the feature
+  -- cheaper but less acurate
+  NEW.centroid := ST_PointOnSurface(NEW.geometry);
+  --DEBUG: RAISE WARNING 'Computing preliminary centroid at %',ST_AsText(NEW.centroid);
+
   -- recompute the ranks, they might change when linking changes
   SELECT * INTO NEW.rank_search, NEW.rank_address
     FROM compute_place_rank(NEW.country_code,
@@ -591,8 +596,10 @@ BEGIN
                             (NEW.extratags->'capital') = 'yes',
                             NEW.address->'postcode');
   -- We must always increase the address level relative to the admin boundary.
-  IF NEW.class = 'boundary' and NEW.type = 'administrative' THEN
-    parent_address_level := get_parent_address_level(NEW.geometry, NEW.admin_level);
+  IF NEW.class = 'boundary' and NEW.type = 'administrative'
+     and NEW.osm_type = 'R' and NEW.rank_address > 0
+  THEN
+    parent_address_level := get_parent_address_level(NEW.centroid, NEW.admin_level);
     IF parent_address_level >= NEW.rank_address THEN
       IF parent_address_level >= 24 THEN
         NEW.rank_address := 25;
@@ -632,11 +639,6 @@ BEGIN
       END IF;
   END IF;
 
-  -- Speed up searches - just use the centroid of the feature
-  -- cheaper but less acurate
-  NEW.centroid := ST_PointOnSurface(NEW.geometry);
-  --DEBUG: RAISE WARNING 'Computing preliminary centroid at %',ST_AsText(NEW.centroid);
-
   NEW.postcode := null;
 
   -- recalculate country and partition