mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-15 19:07:58 +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;
|
||||
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
|
||||
r nearfeature%rowtype;
|
||||
search_diameter FLOAT;
|
||||
r RECORD;
|
||||
search_diameter FLOAT;
|
||||
p1 GEOMETRY;
|
||||
p2 GEOMETRY;
|
||||
p3 GEOMETRY;
|
||||
BEGIN
|
||||
|
||||
IF st_geometrytype(line) not in ('ST_LineString') THEN
|
||||
RETURN;
|
||||
IF ST_GeometryType(line) not in ('ST_LineString') THEN
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
|
||||
p1 := ST_LineInterpolatePoint(line,0);
|
||||
@@ -265,25 +268,22 @@ BEGIN
|
||||
IF in_partition = -partition- THEN
|
||||
search_diameter := 0.0005;
|
||||
WHILE search_diameter < 0.01 LOOP
|
||||
FOR r IN
|
||||
SELECT place_id, null, null, null,
|
||||
ST_Distance(geometry, line) as distance, null as isguess
|
||||
FROM location_road_-partition-
|
||||
WHERE ST_DWithin(line, geometry, search_diameter)
|
||||
ORDER BY (ST_distance(geometry, p1)+
|
||||
ST_distance(geometry, p2)+
|
||||
ST_distance(geometry, p3)) ASC limit 1
|
||||
FOR r IN
|
||||
SELECT place_id FROM location_road_-partition-
|
||||
WHERE ST_DWithin(line, geometry, search_diameter)
|
||||
ORDER BY (ST_distance(geometry, p1)+
|
||||
ST_distance(geometry, p2)+
|
||||
ST_distance(geometry, p3)) ASC limit 1
|
||||
LOOP
|
||||
RETURN NEXT r;
|
||||
RETURN;
|
||||
RETURN r.place_id;
|
||||
END LOOP;
|
||||
search_diameter := search_diameter * 2;
|
||||
END LOOP;
|
||||
RETURN;
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
-- end
|
||||
|
||||
RAISE EXCEPTION 'Unknown partition %', in_partition;
|
||||
END
|
||||
$$
|
||||
LANGUAGE plpgsql;
|
||||
LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
Reference in New Issue
Block a user