- -- Is this object part of a relation?
- FOR relation IN select * from planet_osm_rels where parts @> ARRAY[NEW.osm_id] and members @> ARRAY[lower(NEW.osm_type)||NEW.osm_id]
- LOOP
- -- At the moment we only process one type of relation - associatedStreet
- IF relation.tags @> ARRAY['associatedStreet'] 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 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;
- --DEBUG: RAISE WARNING 'Checked for street relation (%)', NEW.parent_place_id;
-
- -- Note that addr:street links can only be indexed once the street itself is indexed
- IF NEW.parent_place_id IS NULL AND addr_street IS NOT NULL THEN
- address_street_word_ids := get_name_ids(make_standard_name(addr_street));
- IF address_street_word_ids IS NOT NULL THEN
- SELECT place_id from getNearestNamedRoadFeature(NEW.partition, near_centroid, address_street_word_ids) INTO NEW.parent_place_id;
- END IF;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for addr:street (%)', NEW.parent_place_id;
-
- IF NEW.parent_place_id IS NULL AND addr_place IS NOT NULL THEN
- address_street_word_ids := get_name_ids(make_standard_name(addr_place));
- IF address_street_word_ids IS NOT NULL THEN
- SELECT place_id from getNearestNamedPlaceFeature(NEW.partition, near_centroid, address_street_word_ids) INTO NEW.parent_place_id;
- END IF;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for addr:place (%)', NEW.parent_place_id;
-
- -- Is this node part of an interpolation?
- IF NEW.parent_place_id IS NULL AND NEW.osm_type = 'N' THEN
- SELECT q.parent_place_id FROM location_property_osmline q, planet_osm_ways x
- WHERE q.linegeo && NEW.geometry and x.id = q.osm_id and NEW.osm_id = any(x.nodes)
- LIMIT 1 INTO NEW.parent_place_id;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for interpolation (%)', NEW.parent_place_id;
-
- -- Is this node part of a way?
- IF NEW.parent_place_id IS NULL AND NEW.osm_type = 'N' THEN
-
- FOR location IN
- SELECT p.place_id, p.osm_id, p.rank_search, p.address from placex p, planet_osm_ways w
- WHERE p.osm_type = 'W' and p.rank_search >= 26 and p.geometry && NEW.geometry and w.id = p.osm_id and NEW.osm_id = any(w.nodes)
- LOOP
- --DEBUG: RAISE WARNING 'Node is part of way % ', location.osm_id;
-
- -- Way IS a road then we are on it - that must be our road
- IF location.rank_search < 28 THEN
---RAISE WARNING 'node in way that is a street %',location;
- NEW.parent_place_id := location.place_id;
- EXIT;
- END IF;
- --DEBUG: RAISE WARNING 'Checked if way is street (%)', NEW.parent_place_id;
-
- -- If the way mentions a street or place address, try that for parenting.
- IF location.address is not null THEN
- IF location.address ? 'street' THEN
- address_street_word_ids := get_name_ids(make_standard_name(location.address->'street'));
- IF address_street_word_ids IS NOT NULL THEN
- SELECT place_id from getNearestNamedRoadFeature(NEW.partition, near_centroid, address_street_word_ids) INTO NEW.parent_place_id;
- EXIT WHEN NEW.parent_place_id is not NULL;
- END IF;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for addr:street in way (%)', NEW.parent_place_id;
-
- IF location.address ? 'place' THEN
- address_street_word_ids := get_name_ids(make_standard_name(location.address->'place'));
- IF address_street_word_ids IS NOT NULL THEN
- SELECT place_id from getNearestNamedPlaceFeature(NEW.partition, near_centroid, address_street_word_ids) INTO NEW.parent_place_id;
- EXIT WHEN NEW.parent_place_id is not NULL;
- END IF;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for addr:place in way (%)', NEW.parent_place_id;
- END IF;
-
- -- Is the WAY part of a relation
- 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;
- EXIT WHEN NEW.parent_place_id is not null;
- --DEBUG: RAISE WARNING 'Checked for street relation in way (%)', NEW.parent_place_id;
-
- END LOOP;
- END IF;
-
- -- Still nothing, just use the nearest road
- IF NEW.parent_place_id IS NULL THEN
- SELECT place_id FROM getNearestRoadFeature(NEW.partition, near_centroid) INTO NEW.parent_place_id;
- END IF;
- --DEBUG: RAISE WARNING 'Checked for nearest way (%)', NEW.parent_place_id;
-
-
- -- If we didn't find any road fallback to standard method
- IF NEW.parent_place_id IS NOT NULL THEN