FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['label']) as member LOOP
FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::char(1)
- and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
+ and osm_id = substring(relMember.member,2,10000)::bigint
+ and class = 'place' order by rank_search desc limit 1 LOOP
-- If we don't already have one use this as the centre point of the geometry
IF NEW.centroid IS NULL THEN
FOR relMember IN select get_osm_rel_members(relation_members,ARRAY['admin_center','admin_centre']) as member LOOP
FOR linkedPlacex IN select * from placex where osm_type = upper(substring(relMember.member,1,1))::char(1)
- and osm_id = substring(relMember.member,2,10000)::bigint order by rank_search desc limit 1 LOOP
+ and osm_id = substring(relMember.member,2,10000)::bigint
+ and class = 'place' order by rank_search desc limit 1 LOOP
-- For an admin centre we also want a name match - still not perfect, for example 'new york, new york'
-- But that can be fixed by explicitly setting the label in the data
NEW.name := hstore('ref', NEW.address->'postcode');
END IF;
+ IF NEW.class in ('boundary')
+ AND ST_GeometryType(NEW.geometry) not in ('ST_Polygon','ST_MultiPolygon') THEN
+ DELETE FROM placex where place_id = existingplacex.place_id;
+ RETURN NULL;
+ END IF;
+
update placex set
name = NEW.name,
address = NEW.address,
update location_property_osmline p set indexed_status = 2 from planet_osm_ways w where p.linegeo && NEW.geometry and p.osm_id = w.id and NEW.osm_id = any(w.nodes);
END IF;
+ -- linked places should get potential new naming and addresses
+ IF existingplacex.linked_place_id is not NULL THEN
+ update placex x set
+ name = p.name,
+ extratags = p.extratags,
+ indexed_status = 2
+ from place p
+ where x.place_id = existingplacex.linked_place_id
+ and x.indexed_status = 0
+ and x.osm_type = p.osm_type
+ and x.osm_id = p.osm_id
+ and x.class = p.class;
+ END IF;
+
END IF;
-- Abort the add (we modified the existing place instead)
IF searchpostcode IS NOT NULL and location.type = 'postcode' THEN
location.isaddress := FALSE;
END IF;
- IF searchpostcode IS NULL and location.isaddress and location.type != 'postcode' and location.postcode IS NOT NULL THEN
+ IF searchpostcode IS NULL and location.isaddress and location.type != 'postcode' and location.postcode IS NOT NULL and location.postcode not similar to '%(,|;)%' THEN
searchpostcode := location.postcode;
END IF;
IF location.rank_address = 4 AND location.isaddress THEN