ノードの切断を発生させず、ノード10~ノード20と、ノード30~ノード40を回避するダイクストラ計算を行うPostGISのクエリー

C:\Users\ebata\tomioka3B\src\others\main21.goでバトル中 

tomioka_db_c=# SELECT seq, node, edge, source, target, b.cost FROM pgr_dijkstra('SELECT gid as id, source, target, cost, reverse_cost FROM ways WHERE (source NOT BETWEEN 10 AND 20 AND target NOT BETWEEN 10 AND 20) AND (source NOT BETWEEN 30 AND 40 AND target NOT BETWEEN 30 AND 40)',1, 50, directed := false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;

seq | node | edge | source | target | cost
-----+------+------+--------+--------+------------------------
1 | 1 | 2 | 1 | 2 | 8.518550262944415e-05
2 | 2 | 3 | 2 | 3 | 0.0009420518456308501
3 | 3 | 4 | 3 | 4 | 0.00026662995399998605
4 | 4 | 5 | 4 | 5 | 0.00021389117484400878
5 | 5 | 6 | 5 | 6 | 4.656362881781325e-05
6 | 6 | 7 | 6 | 7 | 0.00013184236987589488
7 | 7 | 8 | 7 | 8 | 6.438782425766514e-05
8 | 8 | 1254 | 8 | 897 | 1.2290752319372595e-05
9 | 897 | 1380 | 897 | 969 | 0.00038637624148597305
10 | 969 | 1938 | 969 | 1389 | 2.250777644883257e-05
11 | 1389 | 694 | 1389 | 542 | 0.0002978010745492113
12 | 542 | 1251 | 542 | 895 | 0.00015951582993150323
13 | 895 | 1815 | 895 | 1305 | 0.0001303909506021454
14 | 1305 | 1021 | 1305 | 753 | 3.9356066874244885e-05
15 | 753 | 1381 | 753 | 971 | 0.0002850072862639029
16 | 971 | 1382 | 976 | 971 | 0.001276712172995213
17 | 976 | 1388 | 977 | 976 | 0.0004267486614026622
18 | 977 | 1389 | 986 | 977 | 0.0006757336753520132
19 | 986 | 1404 | 906 | 986 | 0.0003707891314505199
20 | 906 | 1275 | 906 | 907 | 0.0001959266189093194
21 | 907 | 1277 | 907 | 908 | 9.052734394018332e-05
22 | 908 | 1921 | 908 | 1376 | 5.400925846418281e-05
23 | 1376 | 1279 | 1376 | 909 | 1.8504323815069496e-05
24 | 909 | 1057 | 909 | 773 | 6.840328939622445e-05
25 | 773 | 1069 | 773 | 781 | 0.000535513050350553
26 | 781 | 1071 | 781 | 784 | 0.00014276168953525706
27 | 784 | 1087 | 784 | 793 | 0.0004430493335842619
28 | 793 | 1682 | 793 | 1192 | 7.9895243915049e-05
29 | 1192 | 1111 | 1192 | 808 | 0.0005876979547862221
30 | 808 | 1125 | 808 | 816 | 0.00047564125136792903
31 | 816 | 51 | 816 | 49 | 3.10328360877585e-05
32 | 49 | 52 | 49 | 50 | 0.00028187114581170033

一応、QGISで調べて、ノード切れが発生していないことは確認しました。


新規に作ったノード182~413を、ちゃんと無視できるかの実験。ベースは以下のメモの内容。

pgr_dijkstra()で、ダイクストラの順番を壊さずにルートの座標を得る方法(getDijkstraPath())

■無視前

tomioka_db_c=# SELECT seq, source, target, x1, y1, x2, y2 FROM pgr_dijkstra('SELECT gid as id, source, target, cost, reverse_cost FROM ways',1036, 1320, directed := false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;
seq | source | target | x1 | y1 | x2 | y2
-----+--------+--------+-----------------+----------------+-----------------+----------------
1 | 1036 | 182 | 139.6295688 | 35.3660511 | 139.62956342765 | 35.36605302299
2 | 182 | 183 | 139.62956342765 | 35.36605302299 | 139.62952386387 | 35.36602637499
3 | 183 | 184 | 139.62952386387 | 35.36602637499 | 139.62949515388 | 35.36599335049
4 | 184 | 185 | 139.62949515388 | 35.36599335049 | 139.62949783814 | 35.3658805722
5 | 185 | 186 | 139.62949783814 | 35.3658805722 | 139.629505074 | 35.36583679324
6 | 186 | 187 | 139.629505074 | 35.36583679324 | 139.62955514143 | 35.36580196041
7 | 187 | 188 | 139.62955514143 | 35.36580196041 | 139.62972133265 | 35.36574533322
8 | 188 | 189 | 139.62972133265 | 35.36574533322 | 139.62969285571 | 35.3656615823
9 | 189 | 190 | 139.62969285571 | 35.3656615823 | 139.62929978548 | 35.36461811112
10 | 190 | 191 | 139.62929978548 | 35.36461811112 | 139.62923349573 | 35.3644776355
11 | 191 | 192 | 139.62923349573 | 35.3644776355 | 139.62887730502 | 35.36401128513
12 | 192 | 193 | 139.62887730502 | 35.36401128513 | 139.62881288258 | 35.36394808968
13 | 193 | 194 | 139.62881288258 | 35.36394808968 | 139.62878113819 | 35.36393552673
14 | 194 | 195 | 139.62878113819 | 35.36393552673 | 139.62874285819 | 35.36391763403
15 | 195 | 196 | 139.62874285819 | 35.36391763403 | 139.62711549003 | 35.36370406459
16 | 196 | 1320 | 139.62711549003 | 35.36370406459 | 139.6270944 | 35.3636816
(16 rows)

■無視後

tomioka_db_c=# SELECT seq, source, target, x1, y1, x2, y2 FROM pgr_dijkstra('SELECT gid as id, source, target, cost, reverse_cost FROM ways WHERE (source NOT BETWEEN 182 AND 413 AND target NOT BETWEEN 182 AND 413) AND (source NOT BETWEEN 182 AND 413 AND target NOT BETWEEN 182 AND 413)',1036, 1320, directed := false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;
seq | source | target | x1 | y1 | x2 | y2
-----+--------+--------+-------------+------------+-------------+------------
1 | 1034 | 1036 | 139.6297237 | 35.365746 | 139.6295688 | 35.3660511
2 | 1034 | 1033 | 139.6297237 | 35.365746 | 139.6297007 | 35.3656671
3 | 1033 | 1325 | 139.6297007 | 35.3656671 | 139.6287884 | 35.3639297
4 | 1325 | 1320 | 139.6287884 | 35.3639297 | 139.6270944 | 35.3636816

うん、これを見ている限りは、大丈夫そうに見える。

 

2023,江端さんの技術メモ

Posted by ebata