simplify getNearestRoadFeature function

The function only ever returns one result of which only the
place_id is used. So simplify it to return a single place_id
only (or NULL if none is found). Rename funciton to avoid
conflicts when updating an existing database.
This commit is contained in:
Sarah Hoffmann
2020-02-26 10:04:17 +01:00
parent c1ef56c870
commit 84ea0753d8
4 changed files with 16 additions and 19 deletions

View File

@@ -28,8 +28,8 @@ BEGIN
END IF; END IF;
IF out_parent_place_id IS NULL THEN IF out_parent_place_id IS NULL THEN
FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP SELECT getNearestRoadPlaceId(out_partition, place_centroid)
out_parent_place_id := location.place_id; INTO out_parent_place_id;
END LOOP; END LOOP;
END IF; END IF;

View File

@@ -135,8 +135,7 @@ BEGIN
IF fallback THEN IF fallback THEN
IF ST_Area(bbox) < 0.01 THEN IF ST_Area(bbox) < 0.01 THEN
-- for smaller features get the nearest road -- for smaller features get the nearest road
SELECT place_id FROM getNearestRoadFeature(poi_partition, bbox) SELECT getNearestRoadPlaceId(poi_partition, bbox) INTO parent_place_id;
INTO parent_place_id;
--DEBUG: RAISE WARNING 'Checked for nearest way (%)', parent_place_id; --DEBUG: RAISE WARNING 'Checked for nearest way (%)', parent_place_id;
ELSE ELSE
-- for larger features simply find the area with the largest rank that -- for larger features simply find the area with the largest rank that

View File

@@ -214,29 +214,28 @@ END
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql;
create or replace function getNearestRoadFeature(in_partition INTEGER, point GEOMETRY) RETURNS setof nearfeature AS $$ CREATE OR REPLACE FUNCTION getNearestRoadPlaceId(in_partition INTEGER, point GEOMETRY)
RETURNS BIGINT
AS $$
DECLARE DECLARE
r nearfeature%rowtype; r RECORD;
search_diameter FLOAT; search_diameter FLOAT;
BEGIN BEGIN
-- start -- start
IF in_partition = -partition- THEN IF in_partition = -partition- THEN
search_diameter := 0.00005; search_diameter := 0.00005;
WHILE search_diameter < 0.1 LOOP WHILE search_diameter < 0.1 LOOP
FOR r IN FOR r IN
SELECT place_id, null, null, null, SELECT place_id FROM location_road_-partition-
ST_Distance(geometry, point) as distance, null as isguess WHERE ST_DWithin(geometry, point, search_diameter)
FROM location_road_-partition- ORDER BY ST_Distance(geometry, point) ASC limit 1
WHERE ST_DWithin(geometry, point, search_diameter)
ORDER BY distance ASC limit 1
LOOP LOOP
RETURN NEXT r; RETURN r.place_id;
RETURN;
END LOOP; END LOOP;
search_diameter := search_diameter * 2; search_diameter := search_diameter * 2;
END LOOP; END LOOP;
RETURN; RETURN NULL;
END IF; END IF;
-- end -- end

View File

@@ -69,9 +69,8 @@ BEGIN
END IF; END IF;
IF out_parent_place_id IS NULL THEN IF out_parent_place_id IS NULL THEN
FOR location IN SELECT place_id FROM getNearestRoadFeature(out_partition, place_centroid) LOOP SELECT getNearestRoadPlaceId(out_partition, place_centroid)
out_parent_place_id := location.place_id; INTO out_parent_place_id;
END LOOP;
END IF; END IF;
--insert street(line) into import table --insert street(line) into import table