mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
simplify getNearestParallelRoadFeature 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). Also fix typo in function name.
This commit is contained in:
@@ -242,19 +242,22 @@ BEGIN
|
|||||||
RAISE EXCEPTION 'Unknown partition %', in_partition;
|
RAISE EXCEPTION 'Unknown partition %', in_partition;
|
||||||
END
|
END
|
||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql IMMUTABLE;
|
||||||
|
|
||||||
create or replace function getNearestParellelRoadFeature(in_partition INTEGER, line GEOMETRY) RETURNS setof nearfeature AS $$
|
CREATE OR REPLACE FUNCTION getNearestParallelRoadFeature(in_partition INTEGER,
|
||||||
|
line GEOMETRY)
|
||||||
|
RETURNS BIGINT
|
||||||
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
r nearfeature%rowtype;
|
r RECORD;
|
||||||
search_diameter FLOAT;
|
search_diameter FLOAT;
|
||||||
p1 GEOMETRY;
|
p1 GEOMETRY;
|
||||||
p2 GEOMETRY;
|
p2 GEOMETRY;
|
||||||
p3 GEOMETRY;
|
p3 GEOMETRY;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
IF st_geometrytype(line) not in ('ST_LineString') THEN
|
IF ST_GeometryType(line) not in ('ST_LineString') THEN
|
||||||
RETURN;
|
RETURN NULL;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
p1 := ST_LineInterpolatePoint(line,0);
|
p1 := ST_LineInterpolatePoint(line,0);
|
||||||
@@ -266,24 +269,21 @@ BEGIN
|
|||||||
search_diameter := 0.0005;
|
search_diameter := 0.0005;
|
||||||
WHILE search_diameter < 0.01 LOOP
|
WHILE search_diameter < 0.01 LOOP
|
||||||
FOR r IN
|
FOR r IN
|
||||||
SELECT place_id, null, null, null,
|
SELECT place_id FROM location_road_-partition-
|
||||||
ST_Distance(geometry, line) as distance, null as isguess
|
WHERE ST_DWithin(line, geometry, search_diameter)
|
||||||
FROM location_road_-partition-
|
ORDER BY (ST_distance(geometry, p1)+
|
||||||
WHERE ST_DWithin(line, geometry, search_diameter)
|
ST_distance(geometry, p2)+
|
||||||
ORDER BY (ST_distance(geometry, p1)+
|
ST_distance(geometry, p3)) ASC limit 1
|
||||||
ST_distance(geometry, p2)+
|
|
||||||
ST_distance(geometry, p3)) 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
|
||||||
|
|
||||||
RAISE EXCEPTION 'Unknown partition %', in_partition;
|
RAISE EXCEPTION 'Unknown partition %', in_partition;
|
||||||
END
|
END
|
||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql IMMUTABLE;
|
||||||
|
|||||||
@@ -63,9 +63,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 getNearestParellelRoadFeature(out_partition, linegeo) LOOP
|
SELECT getNearestParallelRoadFeature(out_partition, linegeo)
|
||||||
out_parent_place_id := location.place_id;
|
INTO out_parent_place_id;
|
||||||
END LOOP;
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF out_parent_place_id IS NULL THEN
|
IF out_parent_place_id IS NULL THEN
|
||||||
|
|||||||
Reference in New Issue
Block a user