質問編集履歴
1
コードを見やすく編集しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
```ここに言語を入力
|
|
2
1
|
実際のマップに最短経路の表示を行うプログラムでosmnxを使用しているのですが、
|
|
3
2
|
エラーが出てしまいます。また、anacondaを使用して環境構築した上です。
|
|
4
3
|
```
|
|
5
|
-
import os
|
|
4
|
+
```import os
|
|
6
5
|
from pathlib import Path
|
|
7
6
|
|
|
8
7
|
import folium
|
|
9
8
|
import osmnx as ox
|
|
10
9
|
|
|
11
|
-
# 対象地域検索クエリ (愛知県名古屋市中村区)
|
|
12
10
|
query = "Nakamuraku,Nagoya,Aichi,Japan"
|
|
13
11
|
|
|
14
|
-
# 各種出力ファイルパス
|
|
15
12
|
outdir_path = Path(query.replace(",", "_"))
|
|
16
13
|
os.makedirs(outdir_path, exist_ok=True)
|
|
17
|
-
|
|
18
|
-
# 道路グラフネットワーク取得
|
|
19
14
|
graphml_outfile = outdir_path / "road_network.graphml"
|
|
20
15
|
if not os.path.isfile(graphml_outfile):
|
|
21
|
-
# 走行可能な道路グラフネットワークを取得
|
|
22
16
|
G = ox.graph_from_place(query, network_type="drive")
|
|
23
|
-
# 取得データを再利用目的でGraphml形式にて保存
|
|
24
17
|
ox.save_graphml(G, filepath=graphml_outfile)
|
|
25
18
|
else:
|
|
26
|
-
|
|
19
|
+
|
|
27
20
|
G = ox.load_graphml(graphml_outfile)
|
|
28
21
|
|
|
29
|
-
# 道路グラフネットワーク可視化
|
|
30
22
|
fmap = ox.plot_graph_folium(G)
|
|
31
23
|
folium_outfile = outdir_path / "road_network.html"
|
|
32
24
|
fmap.save(outfile=str(folium_outfile))
|
|
@@ -35,14 +27,14 @@
|
|
|
35
27
|
opts = {"node_size": 5, "bgcolor": "white", "node_color": "blue", "edge_color": "blue"}
|
|
36
28
|
ox.plot_graph(G, show=False, save=True, filepath=png_outfile, **opts)
|
|
37
29
|
|
|
38
|
-
|
|
30
|
+
|
|
39
31
|
nodes, edges = ox.graph_to_gdfs(G)
|
|
40
32
|
nodes_csv_outfile = outdir_path / "road_network_nodes.csv"
|
|
41
33
|
nodes.to_csv(nodes_csv_outfile)
|
|
42
34
|
edges_csv_outfile = outdir_path / "road_network_edges.csv"
|
|
43
35
|
edges.to_csv(edges_csv_outfile)
|
|
44
36
|
|
|
45
|
-
|
|
37
|
+
|
|
46
38
|
start_point = (35.18253738854321, 136.85996828365532)
|
|
47
39
|
start_node = ox.get_nearest_node(G, start_point)
|
|
48
40
|
end_point = (35.16163249834248, 136.8824509819242)
|
|
@@ -50,7 +42,7 @@
|
|
|
50
42
|
|
|
51
43
|
shortest_path = ox.shortest_path(G, start_node, end_node)
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
|
|
54
46
|
new_fmap = ox.plot_route_folium(G, shortest_path, route_map=fmap, color="red")
|
|
55
47
|
folium.Marker(location=start_point, tooltip="start").add_to(new_fmap)
|
|
56
48
|
folium.Marker(location=end_point, tooltip="end").add_to(new_fmap)
|
|
@@ -60,6 +52,8 @@
|
|
|
60
52
|
path_png_outfile = outdir_path / "shortest_path_road_network.png"
|
|
61
53
|
ox.plot_graph_route(
|
|
62
54
|
G, shortest_path, show=False, save=True, filepath=path_png_outfile, **opts
|
|
55
|
+
)
|
|
56
|
+
```
|
|
63
57
|
|
|
64
58
|
### 発生している問題・エラーメッセージ
|
|
65
59
|
|