Created
February 8, 2024 11:39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 東海道新幹線のルートを青線で描写し、各駅にマーカーを立てるスクリプト(folium/GeoJSON) | |
import geopandas as gpd | |
import folium | |
# 東海道新幹線の経路データの読み込み | |
geojson_path = '/content/drive/MyDrive/国土数値情報_鉄道/N02-22_RailroadSection.geojson' # N02-22_RailroadSection.geojson の箇所を指定 | |
railways = gpd.read_file(geojson_path) | |
# 東海道新幹線の駅の情報が含まれる GeoJSON ファイルの読み込み | |
stations_geojson_path = '/content/drive/MyDrive/国土数値情報_鉄道/N02-22_Station.geojson' # N02-22_Station.geojson の箇所を指定 | |
stations_data = gpd.read_file(stations_geojson_path) | |
# 東海道新幹線の駅の情報を抽出 | |
tokaido_stations = stations_data[stations_data['N02_003'].str.contains('東海道新幹線')] | |
# foliumの地図を作成 | |
m = folium.Map(location=[34.7101, 137.7256], zoom_start=8) # 例として浜松の緯度経度を設定 | |
# 東海道新幹線の経路を青色の線で表示 | |
for feature in railways.iterrows(): | |
geometry = feature[1]['geometry'] | |
if geometry.geom_type == 'MultiLineString' and '東海道新幹線' in feature[1]['N02_003']: | |
for line_string in geometry: | |
coords = list(line_string.coords) | |
coords = [(coord[1], coord[0]) for coord in coords] | |
folium.PolyLine(locations=coords, color='blue', weight=5).add_to(m) | |
elif '東海道新幹線' in feature[1]['N02_003']: | |
coords = list(geometry.coords) | |
coords = [(coord[1], coord[0]) for coord in coords] | |
folium.PolyLine(locations=coords, color='blue', weight=5).add_to(m) | |
# 東海道新幹線の駅の位置情報をマップ上に追加 | |
for i, row in tokaido_stations.iterrows(): | |
coords = (row.geometry.coords[0][1], row.geometry.coords[0][0]) | |
folium.Marker(location=coords, popup=row['N02_005']).add_to(m) #マーカーのポップアップに駅名情報('N02_005')を表示 | |
# 地図を保存 | |
m.save('tokaido_map_with_stations_geojson.html') | |
# 地図を表示 | |
m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment