- IF fallback THEN
- IF addr_street is null and addr_place is not null THEN
- -- The address is attached to a place we don't know.
- -- Instead simply use the containing area with the largest rank.
- FOR location IN
- SELECT place_id FROM placex
- WHERE bbox && geometry AND _ST_Covers(geometry, ST_Centroid(bbox))
- AND rank_address between 5 and 25
- ORDER BY rank_address desc
- LOOP
- RETURN location.place_id;
- END LOOP;
- ELSEIF ST_Area(bbox) < 0.005 THEN
- -- for smaller features get the nearest road
- SELECT getNearestRoadPlaceId(poi_partition, bbox) INTO parent_place_id;
- {% if debug %}RAISE WARNING 'Checked for nearest way (%)', parent_place_id;{% endif %}
- ELSE
- -- for larger features simply find the area with the largest rank that
- -- contains the bbox, only use addressable features
- FOR location IN
- SELECT place_id FROM placex
- WHERE bbox && geometry AND _ST_Covers(geometry, ST_Centroid(bbox))
- AND rank_address between 5 and 25
- ORDER BY rank_address desc
- LOOP
- RETURN location.place_id;
- END LOOP;
- END IF;
- END IF;
-
- RETURN parent_place_id;