data (#23) - How to prepare road data before running assign_vertex_id (#255) - Message List

How to prepare road data before running assign_vertex_id

Hi, I'm pretty new to everything geospatial related but been asked to get pgRouting to work with some road data I have for West Africa.

Am I right in thinking that before I run assign_vertex_id I need to process my data so that all intersections are the junction of three or more lines i.e. if two roads AB and CD intersect in their middle at a point E then I need to replace them by 4 segments AE, EB, CE and ED before I can run one of the routing algorithms on them?

And if this is so, what would be the best way of doing so (also need to keep all the attributes such as one-way information and road class on the new road segments) ?

Any help would be much appreciated,

Thanks

  • Message #910

    Look here: http://pgrouting.postlbs.org/wiki/WorkshopFOSS4G2008/ch06#Createnetworktopology

    If your network consists of linestrings (with geometry) you need to add source and target column. Then you can run the topology query. If your linestrings are badly digitalized you can increase the "tolerance" value to snap even start and end points of lines that are very close to each other but not connected.

    Which attributes you need depends on which algorithm you use. You can keep all attributes in one table, but you can also link to another table. I think it's a good idea to try the FOSS4G 2008 workshop once. It might answer many questions.

    • Message #915

      Hi Daniel,

      Thanks for getting back to me, I went through the workshop but still unclear about how the initial dataset has to be presented. I think an example might make it clearer, not sure I've explained it properly.

      Say you have 2 linestrings (-1 0, 1 0) and (0 1, 0 -1). They both intersect at (0 0) but will the topology query pick this up and create a vertex at (0 0) as well as new edges thus allowing me to find a route from (-1 0) to (0 -1)?

      Or do I need to replace the 2 original linestrings by 4 new linestrings (-1 0, 0 0), (0 1, 0 0), (1 0, 0 0) and (0 -1, 0 0) thus allowing the topology query to identify the vertex at (0 0)?

      • Message #917

        Hi Daniel,

        After some lucky googling (I was looking for something else entirely!) I found the answer I was looking for -  http://www.mail-archive.com/geotools-gt2-users@lists.sourceforge.net/msg00374.html. I guess my next question would be is there a script out there that splits the roads at intersections for me (while keeping attribute information, I'm trying to do it through OpenJump? but lose all attribute information in the new layer and for some weird reason matching up the original and new layers just doesn't work)?

        Thanks again, Ollie

        • Message #919

          Hi Ollie,

          It's a bit difficult to give a proper answer without knowing about your data.

          • If your data comes in Shape file format for example, you can use shp2psql to import the data into your database and you will get the linestring geometries automatically. Then you can run the assign_vertex_id function to create the topology.
          • If you use OpenStreetMap? data for example, you can use the osm2pgrouting import tool and it will parse the XML, and you will end up with tables ready to use for pgRouting.

          I'm not sure how your data looks like. If you already have topology information (start ID and end ID) for each linestring you can use Dijkstra algorithm even without running that topology function.
          What this function actually does is, it takes start and end point of each of your linestrings and looks for other linestrings that have start/end at the same point or very close (tolerance), so they will then get the same ID assigned.

          Did this help? If not, you could post some of your data in the mailing list for example.