0

Learning pgrouting, I would like to build a simple public transport routing engine.

Starting with a simple metro network (DC in my case, see excerpt below), I would like to combine the line geometries (LineStrings) and station geometries (Points) to produce a routable network following projects like these from @underdark!

What is not clear to me is if there is a way to utilize explicit station geometries as input to the pgr_createTopology function to create the network topolgy?

A screenshot of lines geometry overlayed with station locations: A screenshot of lines geometry overlayed with station locations.

1

You can't directly with pgr_createTopology, however you can map the generated node to stations. We cover this very exact problem in our upcoming book: http://locatepress.com/pgrouting

So what you would do is something like this:

ALTER TABLE dc_stations ADD COLUMN node_id integer;

UPDATE dc_stations 
    SET node_id = X.id
    FROM dc_lines_vertices_pgr X
    WHERE ST_DWithin(dc_stations.geom, X.the_geom, 0.000001);

The above code assumes your units are in degrees, if they are not, you'd want to increase the tolerance. It also assumes your linestrings are already broken at station stops (each station stop is the start or end of an edge). If not you'd have to break the linestrings at station node junctions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.