Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GTFSのデータを Streamlitで可視化してみた
Search
NearMeの技術発表資料です
PRO
April 19, 2024
Programming
0
300
GTFSのデータを Streamlitで可視化してみた
Streamlitを用いてGTFSの可視化を行なった資料になります。今回では、東京都内のバス停を可視化、そしてリアルタイムでのバスの位置情報の可視化を行なっています。
NearMeの技術発表資料です
PRO
April 19, 2024
Tweet
Share
More Decks by NearMeの技術発表資料です
See All by NearMeの技術発表資料です
Box-Muller法
nearme_tech
PRO
0
6
Kiro触ってみた
nearme_tech
PRO
0
25
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
330
ReactNative のアップグレード作業が (意外に)楽しかった話
nearme_tech
PRO
2
89
強化学習アルゴリズムPPOの改善案を考えてみた
nearme_tech
PRO
0
22
Apple Containerについて調べて触ってみた
nearme_tech
PRO
0
310
Rust 並列強化学習
nearme_tech
PRO
0
28
並列で⽣成AIにコーディングをやらせる
nearme_tech
PRO
1
190
希望休勤務を考慮したシフト作成
nearme_tech
PRO
0
47
Other Decks in Programming
See All in Programming
どの様にAIエージェントと 協業すべきだったのか?
takefumiyoshii
2
630
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
210
CSC509 Lecture 02
javiergs
PRO
0
410
オープンソースソフトウェアへの解像度🔬
utam0k
11
2.3k
Six and a half ridiculous things to do with Quarkus
hollycummins
0
140
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
130
Devvox Belgium - Agentic AI Patterns
kdubois
1
100
エンジニアとして高みを目指す、 利益を生み出す設計の考え方 / design-for-profit
minodriven
24
12k
NixOS + Kubernetesで構築する自宅サーバーのすべて
ichi_h3
0
460
登壇は dynamic! な営みである / speech is dynamic
da1chi
0
240
CSC305 Lecture 03
javiergs
PRO
0
240
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
320
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
45
2.5k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
9
860
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
RailsConf 2023
tenderlove
30
1.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
32
2.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
9
590
The Invisible Side of Design
smashingmag
301
51k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Transcript
0 GTFSのデータを Streamlitで可視化してみた 2024-04-19 第87回NearMe技術勉強会 Kenji Hosoda
1 GTFSとは • GTFS (General Transit Feed Specification) は、交通システムに関する関連情報を利⽤者に配 信するために使⽤される”オープン標準”
• 路線、時刻表、運賃、地理的な乗り換えを表現する「GTFS Schedule」とトリップの更新、⾞ 両位置、サービスアラートなどのリアルタイム情報を提供する「GTFS Realtime」という⼆つ の主要な仕様がある • それに加えて、様々なニーズに対応するために拡張されたフォーマットが存在
2 GTFS-JPについて • GTFSの国際標準をベースにしつつ、⽇本独特の交通システムや⾔語、運賃体系に対応 するためにカスタマイズされている • 以下のサイトからデータを取得可能 https://tshimada291.sakura.ne.jp/transport/gtfs-list.html
3 今回は都営バスのデータを可視化してみる • GTFS-JP • https://ckan.odpt.org/dataset/b_bus_gtfs_jp-toei • GTFS Realtime •
https://ckan.odpt.org/dataset/b_bus_gtfs_rt-toei
4 セットアップ • こちらのコードをダウンロード • https://gist.github.com/kenji4569/ea42817d05980d2508963e66b297d03b • 以下を実⾏ • pip
install streamlit streamlit-folium folium pydeck pandas requests geopy gtfs-realtime-bindings • streamlit run gtfs-viewer-app.py • (オプション)公共交通オープンデータセンターにて開発者登録してアクセストークンを取得 (2営 業⽇かかる) • https://developer.odpt.org/ • 実⾏時にアクセストークンをセット • ACCESS_TOKEN=<your_access_token> streamlit run gtfs-viewer-app.py
5 実⾏結果 GTFS-JPのダウンロード バス停の表示 リアルタイムバス位置の表示 更新頻度 表示対象の絞り込み マップの種類
6 (表⽰対象の絞り込みとマップの切り替えについて) • データ数が多いのでfoliumだと動きが遅い → pydeckに変更 • (ただし、現状pydeckの⽅がリアルタイムの更新は苦⼿?)
7 コード解説1 GTFS-JPのダウンロード def download_gtfs_jp (): ... url = (
f"https://api.odpt.org/api/v4/files/Toei/data/ToeiBus-GTFS.zip?acl:consumerKey= {ACCESS_TOKEN}" if ACCESS_TOKEN else "https://api-public.odpt.org/api/v4/files/Toei/data/ToeiBus-GTFS.zip" ) with ( requests.get(url) as res, io.BytesIO(res.content) as bytes_io, zipfile.ZipFile(bytes_io) as zip, ): zip.extractall(GTFS_JP_DATA_DIR ) • ToeiBus-GTFS.zipファイルをダウンロード • ファイルを展開して./data以下に保存 ダウンロードしたデータ
8 コード解説2 GTFS Realtime のダウンロード from google.transit import gtfs_realtime_pb2 def
download_gtfs_realtime (time_steps): ... feed = gtfs_realtime_pb2.FeedMessage() records = [] with urllib.request.urlopen(url) as res: feed.ParseFromString( res.read()) for entity in feed.entity: record = [ entity.id, entity.vehicle.trip.trip_id, entity.vehicle.trip.route_id, entity.vehicle.trip.direction_id, entity.vehicle.position.latitude, entity.vehicle.position.longitude, entity.vehicle.current_stop_sequence, entity.vehicle.timestamp, entity.vehicle.stop_id, ] records.append(record) • ToeiBusのリアルタイムフィード (Protocol Buffers形式)をライブラリ を介して取得 参考:https://nttdocomo-developers.jp/entry/20231218_1
9 今後の展望 https://www.linkedin.com/posts/mobilitydata_gtfs-demandrespo nsivetransportation-drt-activity-7175942816848588800-JX9v • 「GTFS-Flex」来るか? • オンデマンド交通などフレキシブルなルートを扱うことが可能になる • NearMeの配⾞もルート検索アプリに表⽰できるようになる?
10 Thank you