I am working a routing based application where I need to create a route between two points of interest. The problem which I am facing occurs after calculating network topology using assign_vertex_id()
. When I run shortest_path
I get the path between vertexes and not from the point of interest (as shown in image).
Can you please help me out with this: how can I use this query or any other function to do it?
Thanks for any tips.
EDIT 1
I am using this function called multiline_locate_point()
similar to line_locate_point()
which helps me to find nearest LINESTRING from MULTILINESTRING to the point.
here it is:
-- Function: multiline_locate_point(geometry, geometry)
-- DROP FUNCTION multiline_locate_point(geometry, geometry);
CREATE OR REPLACE FUNCTION multiline_locate_point(amultils geometry, apoint geometry)
RETURNS geometry AS
$BODY$
DECLARE
mindistance float8;
nearestlinestring geometry;
nearestpoint geometry;
i integer;
BEGIN
mindistance := (distance(apoint,amultils)+100);
FOR i IN 1 .. NumGeometries(amultils) LOOP
if distance(apoint,GeometryN(amultils,i)) < mindistance THEN
mindistance:=distance(apoint,GeometryN(amultils,i));
nearestlinestring:=GeometryN(amultils,i);
END IF;
END LOOP;
nearestpoint:=line_interpolate_point(nearestlinestring,line_locate_point(nearestlinestring,apoint));
RETURN nearestpoint;
END;
$BODY$
LANGUAGE plpgsql IMMUTABLE STRICT
COST 100;
ALTER FUNCTION multiline_locate_point(geometry, geometry) OWNER TO postgres;
this gives me the_geom()
of point on line. Now the problem is shortest_path()
only takes vertex (integer number) as input to create route. So how can I pass this point to shortest_path()
so that it creates route from the point and not from any vertex ??
No comments:
Post a Comment