0

In documentation explain the restriction table for pgr_trsp function, and that way I can restrict left turn or right turn {target_id, from_edge}. But if I want to restrict multiple links it doesn't explain how fill the via_path

In this case all roads are one way, and you can't do the red turns. So {2190, 2034, 673814} and {673814, 673816, 2190} are forbidden.

How I fill restriction table?

enter image description here

CREATE TABLE restrictions (
    rid BIGINT NOT NULL,
    to_cost FLOAT,
    target_id BIGINT,
    from_edge BIGINT,
    via_path TEXT
);

COPY restrictions (rid, to_cost, target_id, from_edge, via_path) FROM stdin WITH NULL '__NULL__' DELIMITER ',';
1,100,7,4,__NULL__
1,100,11,8,__NULL__
1,100,10,7,__NULL__
2,4,8,3,5
3,100,9,16,__NULL__
\.
1

The complete query in the example in the documentation that uses the table like the posted one:

SELECT * FROM pgr_trsp(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edge_table',
    2, 7, false, false,
    'SELECT to_cost, target_id::int4,
    from_edge || coalesce('','' || via_path, '''') AS via_path
    FROM restrictions'
);

So the table that you posted is used like this in that query:

'SELECT to_cost, target_id::int4,
 FROM edge || coalesce('','' || via_path, '''') AS via_path

So, back to square one, how to fill the table:

From the documentation:

  • restrict_sql: (optional) a SQL query, which should return a set of rows with the following columns:

    SELECT to_cost, target_id, via_path FROM restrictions

  • to_cost: float8 turn restriction cost

  • target_id: int4 target id
  • via_path: text comma separated list of edges in the reverse order of rule

It never mentions if the target_id is an edge or a vertex, so based on the via_path, I'll suppose its an edge:

CREATE TABLE restrictions (
  rid BIGINT NOT NULL,
  to_cost FLOAT8,
  target_id BIGINT,
  via_path TEXT
);

From your image this are forbidden turns (all ids are edges):

  • 637814 -> 637816 -> 2190
  • 2190 -> 2034 -> 637814

I would insert the data to that table like this:

INSERT INTO restrictions (rid, target_id, via_path) VALUES
 (1, 300, 2190, '637816, 637814'),
 (2, 300, 637814, '637814, 2034');

So, these restrictions do not allow those U-turn, but still allow the following Left turns:

  • 637814 -> 637816
  • 2190 -> 2034

Using it with this new table:

SELECT * FROM pgr_trsp(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost FROM edge_table',
    2, 7, false, false,
    'SELECT to_cost, target_id::int4, via_path'
    FROM restrictions'
);

Notes:

  • My understanding of the documentation on that particular function is very limited.
  • I don't understand the advantages of having the design of the table restrictions the way the documentation has it.
  • There is no advantage on the table restrictions as I propose it here.
  • So you can remove the from_edge field? – Juan Carlos Oropeza Dec 8 '16 at 4:13
  • I saw your github, are you working in the next pgrouting release? – Juan Carlos Oropeza Dec 8 '16 at 4:26

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.