directed
flag
When the graph is undirected, it ignores the directed
flag, and has negative identifiers for the source and target
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 | -8 | -4 | 1 | 1
2 | -8 | 8 | 1 | 1
3 | -4 | 4 | 1 | 1
4 | -2 | 4 | 1 | -1
5 | 5 | -8 | 1 | -1
(5 rows)
Expected
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
Works well when the input is directed and with unique edges
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)
expected 12 edges total
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)
Edges with negative identifiers
The same graph as above but represented with shared identifiers on the edges
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 | -304 | -203 | 1 | 1
2 | -304 | 301 | 1 | -1
3 | -203 | 203 | 1 | 1
4 | 102 | 203 | 1 | -1
5 | 104 | -304 | 1 | -1
6 | 203 | 301 | 1 | -1
7 | 301 | 102 | 1 | -1
8 | 301 | 104 | 1 | -1
9 | 304 | -304 | 1 | 1
(9 rows)
Expected original ids
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)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4