ノード10~ノード20を回避して、ノード1から50までのダイクストラ計算を行うPostGISのクエリー

SELECT seq, node, edge, 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',
    1, 50, directed := false
) a
INNER JOIN ways b ON (a.edge = b.gid)
ORDER BY seq;

出力結果
seq | node | edge | cost
-----+------+------+------------------------
1 | 1 | 2 | 8.518550262944416e-06
2 | 2 | 3 | 9.420518456308501e-05
3 | 3 | 4 | 2.6662995399998606e-05
4 | 4 | 6 | 2.1389117484400878e-05
5 | 5 | 7 | 4.6563628817813256e-06
6 | 6 | 1313 | 7.188606587820858e-06
7 | 863 | 126 | 1.0007051975223507e-05
8 | 99 | 127 | 1.450451593740212e-05
9 | 100 | 129 | 7.160567611289415e-06
10 | 101 | 131 | 4.109420419283505e-05
11 | 102 | 133 | 2.934679929904221e-05
12 | 103 | 135 | 1.5514200871555155e-05
13 | 104 | 137 | 1.2955240951715268e-05
14 | 105 | 139 | 3.932409601088787e-05
15 | 106 | 141 | 3.756326743314803e-05
16 | 107 | 143 | 6.437495269868342e-05
17 | 108 | 145 | 3.580138401404371e-05
18 | 109 | 147 | 5.81727588604755e-05
19 | 110 | 148 | 4.310761927462597e-05
20 | 651 | 1196 | 0.00021148735186994806
21 | 780 | 995 | 0.00017553851429442523
22 | 653 | 997 | 5.381635439655622e-05
23 | 654 | 996 | 3.9727662820583996e-05
24 | 21 | 24 | 6.931684268013142e-06
25 | 22 | 25 | 7.70969814835397e-06
26 | 23 | 26 | 1.2029326750062135e-05
27 | 24 | 27 | 3.163056561909417e-05
28 | 25 | 28 | 3.715561627508799e-05
29 | 26 | 29 | 1.6759949788587843e-05
30 | 27 | 30 | 1.3935943447597369e-05
31 | 28 | 31 | 7.276956035534738e-06
32 | 29 | 32 | 1.2096545992840006e-05
33 | 30 | 33 | 4.534133154905821e-05
34 | 31 | 34 | 1.8836761764769703e-05
35 | 32 | 35 | 8.806681794688408e-06
36 | 33 | 36 | 7.526055852520615e-06
37 | 34 | 37 | 1.0243676427727028e-05
38 | 35 | 38 | 1.5622874238716658e-05
39 | 36 | 39 | 6.894091782961944e-06
40 | 37 | 40 | 1.786596350373829e-05
41 | 38 | 41 | 1.796453895498639e-05
42 | 39 | 42 | 6.566793603978039e-05
43 | 40 | 43 | 4.0144224056584715e-05
44 | 41 | 44 | 2.037304658526977e-05
45 | 42 | 45 | 1.643518634972223e-05
46 | 43 | 46 | 1.1916705412252495e-05
47 | 44 | 47 | 1.0031152210412222e-05
48 | 45 | 48 | 1.1949163674231717e-05
49 | 46 | 49 | 1.7529822253810993e-05
50 | 47 | 50 | 1.9115799546536715e-05
51 | 48 | 51 | 5.101757589403705e-05
52 | 49 | 53 | 2.8187114581170035e-05

2023,江端さんの技術メモ

Posted by ebata