Ticket #107 (closed feature request: fixed)

Opened 3 years ago

Last modified 19 months ago

Return path list with path segments in the correct direction

Reported by: daniel Owned by: anton
Priority: major Milestone: Version 1.1
Component: Dijkstra Version: 1.01
Keywords: Cc:

Description

Currently the result of the shortest path search returns a list of ordered links. The order of this link list is correct, but there are two cases how to pass each link: - from start to end - from end to start

To show animated routes (ie. play the path as a tour in Google Earth) each link needs to be passed in the correct direction. This might be also convenient for giving driving directions.

Change History

Changed 3 years ago by rodj59

This is something I wrote some time ago which is close to what is requested I think.

CREATE TYPE ordered_path_type AS (
    the_geom	geometry,
    edge_id	int,
    source	int,
    target	int,
    length_gd	float(4),
    time_gd	float(4)
);


CREATE OR REPLACE FUNCTION ordered_path_as_geometry(tab varchar,startp integer,target integer,geocol varchar,costcol varchar)
    RETURNS SETOF ordered_path_type AS
$$
    # each vertex_id occurs twice except for startp & target
    # the pair may occur as two sources, two targets , or a source and a target
    # method is to start at startp & follow until target is reached
    
    ordered_path = []
    last_vertex = startp
    ordered_indexes = {}

    # get the unordered path geometry
    dbrws = plpy.execute("select a.the_geom as the_geom,a.gid as edge_id,b.source as source,b.target as target,b.length_gd as length_gd,b.time_gd as time_gd from shortest_path_as_geometry('%s',%d,%d,'%s','%s') a,%s_edges b where b.id = a.gid" % (tab,startp,target,geocol,costcol,tab))
    rws= dbrws[:]
    stop = 1
    rng = range(len(rws))
    while stop < 999:  # failsafe to avoid hanging
        stop = stop + 1
        # loop until the target is found
        for i in rng:
            rw = rws[i]
            last_i = i
            if last_vertex == target:
                # we have reached the target vertex, return the ordered list
                return ordered_path
            if not ordered_indexes.has_key(rw['edge_id']) or startp == last_vertex: 
              if last_vertex == rw['source'] :
                # this is the edge which continues the path from last vertex
                last_vertex = rw['target']
                ordered_path.append(rw)
                ordered_indexes[rw['edge_id']] = 1  # dont consider this again
                break
              elif last_vertex == rw['target']:
                # ... ditto
                rw['target'] = rw['source']
                rw['source'] = last_vertex
                last_vertex = rw['target']
                ordered_path.append(rw)
                ordered_indexes[rw['edge_id']] = 1
                break
#        rws = rws[:last_i] + rws[last_i+1:]
    return ordered_path
$$
LANGUAGE 'plpythonu' ;

Changed 2 years ago by anton

  • status changed from new to closed
  • resolution set to fixed

Done - id field added to the output type. Being sorted by id result becomes ordered.

Changed 19 months ago by shafeer

select * from ordered_path_as_geometry(1?,2?,3?,4?,5?)

Can u please list out the parameters to be passed to this function. 1? (is it table name) 2 and 3 ( Hopefully source and target) 4? is it geometry column(if then why is it in varchar) 5? cost column (again why is it in var char) select * from ordered_path_as_geometry ('routingtext_demo',4352,4052,'geometry','rd_name')

Sorry, I knew the ticket is closed but dint find a proper place to ask the question.

Note: See TracTickets for help on using tickets.