1

I have a river network shapefile and I use pgRouting 2.0 to route it. I use the following sql code to make it routable,

alter table tc_15000_w_area add column source integer;
alter table tc_15000_w_area add column target integer;
select pgr_createTopology('tc_15000_w_area', 0.0001, 'the_geom', 'gid');

All I want is a routable table contains source/target and the direction from all sources to targets is the same as the direction of the river. Here's the schematic photo,

enter image description here

the purple line is the river

the red dots are nodes(vertices)

the red numbers are numbers of the nodes

every river segment has its source(node) and target

But I check the resulting table, I find that node#11 is always the target. This will make at least one of the edges has wrong direction(flow direction).

enter image description here

Can pgRouting assign numbers of source and target and make the direction from source to target the same as the flow direction? If not, what can I do?

I have used different tolerances in sql code, but got the same result, and I also got the same result using pgRouting version 1.x under PostgreSQL 8.4.

Heinz
  • 2,415
  • 6
  • 26
  • 34

1 Answers1

0

Tolerance defines the minimum distance between two points that will get merged into a single point. For example if you have two point and the distance between them in datbase units is less than tolerance then they will be considered the same point and will get assigned the same number.

given an edge segment in your geometry table before you run pgr_createtopology() how do you know the direction of flow? based on the direction of digitization? We do not look at this in assigning numbers. Numbers are assigned on a first come first assigned basis as we process the edges.

To solve your problem, you probably need to write a node renumbering algorithm, that works something like this: 1. run pgr_createtopology() 2. from the network sink (ie: the drain of river network) do a depth first search and assign numbers in reverse order (largest from the drain, smaller as you move upstream).

I would create new node source and target columns for this. There might be a better way to solve this problem but it is not obvious at the moment.

Stephen Woodbridge
  • 1,100
  • 1
  • 8
  • 16
  • If I know the position of every edge, then I can check their "source --> target" direction by flow direction. So the basic problem to this is not about the number pgRouting assigned to the vertex, it's about role of source(or target) pgRouting assigned vertex to be. – Heinz May 28 '14 at 06:36
  • To assign the numbers the way you want them can NOT be done by pgr_createtopology(). What you are looking for is the result of some graph analysis algorithm like I described above. Lets simplify the problem to a single edge. How do I assign the numbers to this edge? Which end is the source and which end is the sink/drain? – Stephen Woodbridge May 29 '14 at 13:51
  • I found a post seems to fix this problem, http://dirkraffel.com/2011/09/06/fixing-wrong-direction-of-segments-in-pgrouting-output/#comments but I don't know if this could used by the driving_distance function, because the code in the post seems not to reassign numbers of sources and targets? – Heinz Jun 19 '14 at 02:23