[pgrouting-users] isochrone map traversing partial lines

Ian itangert at gmail.com
Mon Jun 4 14:16:17 PDT 2012


hi all,



i'd like to implement something to do partial edge traversal at the end 
of each route so my function isn't limited to all or nothing edges.  I 
saw the implementation of starting from the nearest edge point here 
<http://lists.osgeo.org/pipermail/pgrouting-users/2012-January/000927.html> 
(as opposed to the nearest node and i will implement that, thanks 
steve).  does anyone have any suggestions on how i could do partial edge 
traversal at the end of the routes based on the function i'm currently 
using? also, has this been done already and i just missed it along the 
way?  a few things about the function i'm currently using:

a friend and i came up with a function that takes a lon, lat, and 
distance parameters and returns all the lines possible to traverse 
within the distance parameter.  (attached).  in the function the edge 
table is named lines, and the cost column is named distancecolumn, which 
has values for each edge as the length of the edge in feet. also, this 
function finds the nearest node to start from rather than the nearest 
point on the nearest edge.  the lines table is in epsg 4269 and the 
input lat lon are meant to be in epsg 4326.

thanks,

ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20120604/ec420c29/attachment.html>
-------------- next part --------------
CREATE TYPE networkcalcrs AS
(
  gid integer,
  the_geom geometry,
  source integer,
  target integer
);

CREATE OR REPLACE FUNCTION _jmsnetworkcalc(double precision, double precision, double precision)
  RETURNS SETOF networkcalcrs AS
$BODY$
  DECLARE
    inLon ALIAS FOR $1;
    inLat ALIAS FOR $2;
    distance ALIAS FOR $3;

    sourceID integer;
    returnNetwork networkCalcRS;
  BEGIN
    CREATE TEMP TABLE path
    (
      gid integer NOT NULL,
      the_geom geometry NOT NULL,
      vertex_id integer NOT NULL
    );

    CREATE TEMP TABLE network
    (
      gid integer NOT NULL,
      the_geom geometry NOT NULL,
      source integer NOT NULL, 
      target integer NOT NULL
    );

    SELECT INTO sourceID v.id
    FROM (SELECT st_transform(ST_SetSRID(ST_Point(inLon, inLat), 4326), 4269) As the_geom) As b, vertices_tmp as v
    ORDER BY ST_Distance(v.the_geom, b.the_geom)
    LIMIT 1;

    INSERT INTO path(gid, the_geom, vertex_id)
    SELECT rd.gid, rd.the_geom, dd.vertex_id
    FROM driving_distance('SELECT gid AS id, source, target, distancecolumn::double precision AS cost 
		           FROM lines', sourceID, distance, false, false) dd, cinciroad rd
    WHERE rd.gid = dd.edge_id;
    
    INSERT INTO network(gid, the_geom, source, target)
    SELECT rd.gid, rd.the_geom, rd.source, rd.target
    FROM path firstPath
    CROSS JOIN path secondPath
    INNER JOIN lines rd
    ON firstPath.vertex_id = rd.source
    AND secondPath.vertex_id = rd.target;

    FOR returnNetwork IN SELECT * FROM network LOOP
        RETURN NEXT returnNetwork;
    END LOOP;
  END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION _jmsnetworkcalc(double precision, double precision, double precision) OWNER TO postgres;

SELECT gid, the_geom, source, target FROM _jmsnetworkcalc(X, Y, DISTANCE);


More information about the Pgrouting-users mailing list