1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
/* :file: This file is part of the pgRouting project.
:copyright: Copyright (c) 2016-2026 pgRouting developers
:license: Creative Commons Attribution-Share Alike 3.0 https://creativecommons.org/licenses/by-sa/3.0 */
/* -- q1 */
SELECT * FROM pgr_lineGraph(
'SELECT id, source, target, cost, reverse_cost
FROM edges WHERE id IN (2,4,5,8)',
false);
seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
1 | 2 | 4 | 1 | -1
2 | 2 | 5 | 1 | -1
3 | 4 | 8 | 1 | -1
4 | 5 | 8 | 1 | -1
(4 rows)
/* -- q2 */
CREATE TABLE edges_shared (
id BIGINT,
source BIGINT,
target BIGINT,
cost FLOAT,
reverse_cost FLOAT,
geom geometry
);
CREATE TABLE
INSERT INTO edges_shared (id, source, target, cost, reverse_cost, geom) VALUES
(102, 1, 2, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))),
(104, 1, 4, 1, -1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))),
(301, 3, 1, 1, -1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))),
(203, 2, 3, 1, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))),
(304, 3, 4, 1, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0)));
INSERT 0 5
SELECT seq, source, target, cost, reverse_cost
FROM pgr_lineGraph(
'SELECT id, source, target, cost, reverse_cost FROM edges_shared',
true);
seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
1 | 102 | 203 | 1 | -1
2 | 104 | 304 | 1 | -1
3 | 203 | 203 | 1 | 1
4 | 203 | 301 | 1 | -1
5 | 203 | 304 | 1 | 1
6 | 301 | 102 | 1 | -1
7 | 301 | 104 | 1 | -1
8 | 304 | 301 | 1 | -1
9 | 304 | 304 | 1 | 1
(9 rows)
/* -- q3 */
CREATE TABLE edges_unique (
id BIGINT,
source BIGINT,
target BIGINT,
cost FLOAT,
geom geometry
);
CREATE TABLE
INSERT INTO edges_unique (id, source, target, cost, geom) VALUES
(102, 1, 2, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))),
(104, 1, 4, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))),
(301, 3, 1, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))),
(203, 2, 3, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))),
(304, 3, 4, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 0))),
(302, 3, 2, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(2, 2))),
(403, 4, 3, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0)));
INSERT 0 7
SELECT seq, source, target, cost, reverse_cost
FROM pgr_lineGraph(
'SELECT id, source, target, cost FROM edges_unique',
true);
seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
1 | 102 | 203 | 1 | -1
2 | 104 | 403 | 1 | -1
3 | 203 | 301 | 1 | -1
4 | 203 | 304 | 1 | -1
5 | 301 | 102 | 1 | -1
6 | 301 | 104 | 1 | -1
7 | 302 | 203 | 1 | 1
8 | 304 | 403 | 1 | 1
9 | 403 | 301 | 1 | -1
10 | 403 | 302 | 1 | -1
(10 rows)
/* -- q4 */
ROLLBACK;
ROLLBACK
|