- SELECT place_id from placex where osm_type='W' and osm_id = substring(relation.members[i],2,200)::bigint
- and rank_search = 26 and name is not null INTO NEW.parent_place_id;
- END IF;
- END LOOP;
- END IF;
- END LOOP;
-
---RAISE WARNING 'x1';
- -- Is this node part of a way?
- FOR way IN select id from planet_osm_ways where nodes @> ARRAY[NEW.osm_id] LOOP
---RAISE WARNING '%', way;
- FOR location IN select * from placex where osm_type = 'W' and osm_id = way.id
- LOOP
---RAISE WARNING '%', location;
- -- Way IS a road then we are on it - that must be our road
- IF location.rank_search = 26 AND NEW.parent_place_id IS NULL THEN
---RAISE WARNING 'node in way that is a street %',location;
- NEW.parent_place_id := location.place_id;
- END IF;
-
- -- Is the WAY part of a relation
- IF NEW.parent_place_id IS NULL THEN
- FOR relation IN select * from planet_osm_rels where parts @> ARRAY[location.osm_id] and members @> ARRAY['w'||location.osm_id]
- LOOP
- -- At the moment we only process one type of relation - associatedStreet
- IF relation.tags @> ARRAY['associatedStreet'] AND array_upper(relation.members, 1) IS NOT NULL THEN
- FOR i IN 1..array_upper(relation.members, 1) BY 2 LOOP
- IF NEW.parent_place_id IS NULL AND relation.members[i+1] = 'street' THEN
- --RAISE WARNING 'node in way that is in a relation %',relation;
- SELECT place_id from placex where osm_type='W' and osm_id = substring(relation.members[i],2,200)::bigint
- and rank_search = 26 and name is not null INTO NEW.parent_place_id;
- END IF;
- END LOOP;
- END IF;
- END LOOP;
- END IF;
-
- -- If the way contains an explicit name of a street copy it
- -- Slightly less strict then above because data is copied from any object.
- IF NEW.street IS NULL AND NEW.addr_place IS NULL THEN
---RAISE WARNING 'node in way that has a streetname %',location;
- NEW.street := location.street;
- NEW.addr_place := location.addr_place;
- END IF;
-
- -- If this way is a street interpolation line then it is probably as good as we are going to get
- IF NEW.parent_place_id IS NULL AND NEW.street IS NULL AND NEW.addr_place IS NULL AND location.class = 'place' and location.type='houses' THEN
- -- Try and find a way that is close roughly parellel to this line
- FOR relation IN SELECT place_id FROM placex
- WHERE ST_DWithin(location.geometry, placex.geometry, 0.001) and placex.rank_search = 26
- and st_geometrytype(location.geometry) in ('ST_LineString')
- ORDER BY (ST_distance(placex.geometry, ST_LineInterpolatePoint(location.geometry,0))+
- ST_distance(placex.geometry, ST_LineInterpolatePoint(location.geometry,0.5))+
- ST_distance(placex.geometry, ST_LineInterpolatePoint(location.geometry,1))) ASC limit 1
- LOOP
---RAISE WARNING 'using nearest street to address interpolation line,0.001 %',relation;
- NEW.parent_place_id := relation.place_id;
- END LOOP;
- END IF;
-
- END LOOP;
- END LOOP;
-
- END IF;
-
---RAISE WARNING 'x2';
-
- IF NEW.parent_place_id IS NULL AND NEW.osm_type = 'W' THEN
- -- Is this way part of a relation?
- FOR relation IN select * from planet_osm_rels where parts @> ARRAY[NEW.osm_id] and members @> ARRAY['w'||NEW.osm_id]
- LOOP
- -- At the moment we only process one type of relation - associatedStreet
- IF relation.tags @> ARRAY['associatedStreet'] AND array_upper(relation.members, 1) IS NOT NULL THEN
- FOR i IN 1..array_upper(relation.members, 1) BY 2 LOOP
- IF NEW.parent_place_id IS NULL AND relation.members[i+1] = 'street' THEN
---RAISE WARNING 'way that is in a relation %',relation;
- SELECT place_id from placex where osm_type='W' and osm_id = substring(relation.members[i],2,200)::bigint
- and rank_search = 26 and name is not null INTO NEW.parent_place_id;
- END IF;
- END LOOP;