+ -- 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,
+ CASE WHEN ST_GeometryType(NEW.geometry)
+ IN ('ST_Polygon','ST_MultiPolygon')
+ THEN 'A' ELSE NEW.osm_type END,
+ NEW.class, NEW.type, NEW.admin_level,
+ (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'
+ 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;
+ ELSE
+ NEW.rank_address := parent_address_level + 2;
+ END IF;
+ END IF;
+ ELSE
+ parent_address_level := 3;
+ END IF;
+