R Code for Regional Analysis: Interactive Flow Mapping of Public Transport Infrastructure using Leaflet and GTFS Data 地域分析のためのRコード:LeafletとGTFSデータを用いた公共交通インフラのインタラクティブな地図化(流線図)

Read full text
Authors: Yasutoshi Moteki
Cited by: 3
References: 3

Abstract

地域分析のためのRコード:LeafletとGTFSデータを用いた公共交通インフラのインタラクティブな地図化(流線図) 概要(Description) 1. 本プログラムの目的 本プログラムは、愛知県知多郡東浦町のコミュニティバス「う・ら・ら」の「静的GTFS(GTFS Static)」データを活用し、R言語およびLeafletを用いてインタラクティブな路線図・バス停マップを生成するための最小構成のひな形(テンプレート)である。 GTFS(General Transit Feed Specification)は、公共交通機関の時刻表と地理的情報に関する世界共通のフォーマットであり、もともとGoogleによって策定された仕様である。地域分析の第一歩として、複雑な専門ライブラリに依存せず、地理情報システムの標準的なパッケージのみを用いることで、GTFSのデータ構造を直接理解し、かつ将来にわたる高い再現性を確保することを目的としている。本手法の構築にあたっては、中島円(2025)によるGTFSデータの活用手法から着想を大きく得ている。具体的には、同氏の著書『GIS入門 この一冊で「統計マップ」が自在に作れる』(ベレ出版、2025年) https://ndlsearch.ndl.go.jp/books/R100000137-I9784860647933の第7章「バスの流線図の作成(278-290頁)」における解説が、本スクリプトの開発に大きな影響を与えた。当該箇所では、山梨県を事例として、QGISのGTFS-GOプラグインを用いたGTFS-JPデータの可視化プロセスが詳述されている。特に、公共交通データの標準規格であるGTFSをQGIS上で展開し、実務的な流線図へと落とし込む一連の手法は、書籍による日本のGTFSデータ活用の先駆的な例として、本研究のアルゴリズムおよび実装プロトコルの発想上の基礎となっている。 本バージョン(V2)では、この基礎的な可視化手法をさらに発展させ、町役場のある緒川地区の「緒川駅東口」を中心駅のバス停として定義し、同所へのアクセス性を重視した描画モデルを採用している。「緒川駅東口」行きについて、バス停の時刻表表示の便に★マークを付与した。線描画については、中心駅へ向かう「上り」と中心駅から離れる「下り」を微小な空間オフセットによって分離描画するとともに、運行頻度(便数)を路線の太さに動的に反映させるアルゴリズムを独自に実装した。これにより、日常的な「全日(ベース)」運行と限定便を含む「全便(最大)」ポテンシャルの差を視覚的に比較することが可能となり、地域の交通供給力の厚みと方向性をより直感的に理解できる分析ツールへと進化を遂げている。スクリプトの公開を先行するため、以下の節の説明はV1のまま変更してない場合がある。 【最新版のお知らせ:V3公開】 本プログラム(V2)をさらに発展させ、ワークショップにおける将来計画の策定や対話的なシナリオ検討を可能にする最新バージョン「V3: Scenario Modeling Edition」を公開した。本V2が既存の公共交通網の解析(流線図による供給力の可視化)を主眼としているのに対し、V3は「お絵かき機能」によって新規路線案の描画やシミュレーションを可能にする、住民参加型の対話型モデリングツールである。解析から創造(設計)への進化を遂げたV3は、以下のリンクから利用可能である。 V3(Scenario Modeling Edition)はこちら: https://doi.org/10.5281/zenodo.20130390 国際的文脈における位置づけ:動的アクセシビリティ評価の設計思想 中島円らによる国内の議論を背景としつつ、国際的文脈においては、英国ウェールズの研究グループが提案した以下の動的なアクセシビリティ評価ツールの設計思想と通底するものである。 Webb, L., Langford, M., Higgs, G., & Berry, R. (2025). The design of a dynamic web-based solution to measure accessibility via public transport under different travel scenarios. Case Studies on Transport Policy, 21, 101561. https://doi.org/10.1016/j.cstp.2025.101561 Webb et al. (2025) は、オープンソース技術を統合し、特定のバス路線の廃止や新設、あるいは運行事業者の撤退といった異なる移動シナリオが、公共交通のアクセシビリティ(サービスへの到達性)に与える影響を、政策立案者が動的に分析・比較できるインタラクティブなWeb-GISツールを提案している 。 本コードの独自性:複雑なインフラを排した「簡便な実装」 筆者の本コードは、バス停の配置やルートの変更が地域に与える影響をシミュレーションし、EBPM(証拠に基づく政策立案)に資する視覚的証拠を得るという、同論文の目的と軌を一にしている 。一方で、実装アプローチにおいては以下の決定的な違いを有する。 インフラフリーの追求: Webbらのシステムは、バックエンドにPostgreSQL/PostGIS、OpenTripPlanner、GeoServer、PHPといった多層的なサーバーサイド・インフラを要求する「重厚な設計」である 。これに対し、本コードはR言語の標準的な環境のみで動作し、複雑なデータベース管理やサーバー構築を一切必要としない「簡便な実装」を追求している。 現場への適応性: 重厚なインフラを排したことで、専門的なITスキルのない行政担当者や、制約の多いワークショップ現場においても、GTFSデータさえあれば即座にシナリオ検討を開始できる高い機動性を確保している。 2. データ出典および作成者 本プログラムで使用しているサンプルデータは、以下のオープンデータに基づいている。 データの作成者: 東浦町 データ入手先: 標準的なバス情報フォーマット(GTFS)データ集(東浦町) https://gtfs-data.jp/search?&agencyId=higashiuratown ファイル名: feed_higashiuratown_communitybus_20260227_20260327151527.zip 表の列「URLs」の「GTFS」の項目をクリックする。 3. 使用データファイルの構成 本プログラムの対象となるGTFSデータは、以下のテキストファイル群で構成されている。これらのファイルの機能を理解することが、GTFSを用いた地域公共交通の分析において重要となる。上述のzipファイルを展開(解凍)しRの作業ディレクトリにすべてのファイルを移動させる。 agency.txt(運行エージェンシー情報) calendar.txt / calendar_dates.txt(運行スケジュール・カレンダー情報) fare_attributes.txt / fare_rules.txt(運賃属性・ルール情報) feed_info.txt(フィード自体に関する情報) routes.txt(路線情報) shapes.txt(路線の描画形状情報) stop_times.txt(各停留所の通過時刻情報) stops.txt(停留所の名称・座標情報) transfers.txt(乗り換え情報) translations.txt(翻訳情報) trips.txt(便の情報) 4. 本手法の独自性と簡便性 (v2.0) Rを用いたGTFSデータの分析・可視化においては、通常 tidytransit や gtfsio といった専門ライブラリを利用することが一般的である(先行事例:tidytransitパッケージを用いた分析手法 https://uribo.hatenablog.com/entry/2019/12/05/064942 )。これに対し、本スクリプトはあえてこれらを使用せず、sf (Simple Features)、tidyverse、leaflet という汎用パッケージのみで構成されている。 解析プロセスの透明性の確保: tidytransit 等の専門ライブラリが内部で行っているデータの結合(Join)や空間オブジェクトへの変換プロセスを、あえて標準的なコードで明示している。特にV2で実装した「上下線の空間オフセット」や「便数に基づく動的な線幅演算」についても、ブラックボックス化した関数に頼らず標準的な座標演算とデータ処理の組み合わせで実現した。これにより、地理的な描画の背後にある数学的・論理的な仕組みを、利用者がソースコードから直接トレースし、深い理解を得ることを可能にしている。 低依存性(ポータビリティ): 特定の交通分析パッケージのアップデートや仕様変更に左右されにくいため、長期的な学術資産としての保存や、プログラミング教育の現場における「最初のたたき台」としての導入に適している。 探索型インターフェース: 本バージョンでは単一の分析結果を提示するのではなく、利用者自身が「全日(ベース)」と「全便(最大)」を切り替え、マウスカーソルを動かしてバス停の利便性や路線の重なりを確かめる仕様を採用している。データと直接対話することで、地域の交通供給力の厚みや方向性を発見するプロセスを重視している。 本コードは、Google Geminiのコード支援を用い、実装した。 5. 仕様および制限事項(v2.0) 本バージョンはV1を大幅に修正し、バスの本数(供給力)によって描画を動的に変化させる機能実装(流線図化)を優先しており、以下の挙動を仕様としている 。 ポップアップによる系統識別: 本バージョンでは、描画ロジックの簡素化を優先したため、路線(ライン)を選択して詳細な便数や系統名を表示する機能は実装していない。情報の確認はバス停の時刻表ポップアップを中心に行う仕様となっている 。 オフセットの視覚的限界: 道路が複雑に密集する地点や、急カーブが連続する区間では、上下線のオフセット(ずれ)が視覚的に重なって見える場合がある 。 今後の課題(Future Challenges) 時間帯別の動的フィルタリング: 朝夕のラッシュ時と昼間の閑散時でサービスレベルが大きく変わるため、時刻による表示の切り替え機能の実装 。 需要データ(人口メッシュ等)との統合: 交通供給力(バスの本数)と、実際の利用者数や周辺居住人口データを重ね合わせ、需要と供給のミスマッチを特定する分析機能の追加 。 道路ネットワークへの空間集約: 現在の shape_id 単位の描画から、実際の道路セグメントごとに全便数を合算して表示する、より厳密な流線図アルゴリズムへの改良 。 6. 学術的・実務的価値 本スクリプトは、東浦町地域公共交通会議『楽しい公共交通のはじめかた』の公共交通ざっくりマップと照合し、一定のデータ整合性を確認済みである(V1段階)。「まずは手元のGTFSを地図にして、自分の目で確かめてみる」ための最初のたたき台として、他の自治体や交通研究者、学生が即座に活用できる汎用的なツールとなっている。なお、公式の「公共交通ざっくりマップ」と路線図の描画色は連動している(GTFSデータに設定が含まれている)。 ファイル構成(v2.0) GTFS_Leaflet_BUSViz_Higashiura_v2.R: Rスクリプト本体 (v2.0) GTFS_Leaflet_busroute_Higashiura_zenjitsu_base.png: 路線出力例(全日ベース) GTFS_Leaflet_busroute_Higashiura_max.png: 路線出力例(全便最大) GTFS_Leaflet_busroute_Higashiura_stop.png: バス停時刻表の出力例(★マーク付) [English] Description 1. Purpose of the Program This program provides a minimalist template for generating interactive bus route and stop maps using R and Leaflet, utilizing "GTFS Static" data from the community bus service "U-ra-ra" in Higashiura Town, Aichi Prefecture. GTFS (General Transit Feed Specification) is a universal format for public transportation timetables and geographic information, originally developed by Google. As a primary step in regional analysis, this study aims to facilitate a direct understanding of the GTFS data structure and ensure high long-term reproducibility by relying solely on standard Geographic Information System (GIS) packages, rather than depending on complex specialized libraries. The development of the current script was significantly inspired by the methodologies for GTFS data utilization presented by Madoka Nakajima (2025) https://ndlsearch.ndl.go.jp/books/R100000137-I9784860647933. Specifically, the discussion in Chapter 7, "Creating Bus Flow Maps" (pp. 278–290), of the book Introduction to GIS: Create "Statistical Maps" at Will with This Single Volume (Beret Publishing, 2025), had a major impact on the design of this script. In that chapter, Nakajima details the visualization process of GTFS-JP data using the GTFS-GO plugin in QGIS, using Yamanashi Prefecture as a case study. The series of techniques—deploying the standard GTFS format within QGIS to generate practical flow maps—stands as a pioneering example of GTFS data application in Japan and serves as the conceptual foundation for the algorithms and implementation protocols developed in this research. In this version (V2), we have further developed this basic visualization method by defining "Ogawa Station East Exit" in the Ogawa district—where the Town Hall is located—as the "central station" bus stop. We have adopted a rendering model that emphasizes accessibility to this central location. For trips bound for "Ogawa Station East Exit," a "★" mark has been added to the timetables displayed at each bus stop. Regarding the line rendering, we have independently implemented an algorithm that separately depicts "inbound" trips toward the central station and "outbound" trips away from it using a minute spatial offset. Furthermore, the service frequency (number of trips) is dynamically reflected in the line thickness. This enables a visual comparison between standard "Daily (Base)" operations and "All Trips (Maximum)" potential, which includes limited-service trips. Consequently, the script has evolved into an analytical tool that allows for a more intuitive understanding of the depth and directionality of local transit supply. Please note that to prioritize the release of this updated script, descriptions in the following sections may remain unchanged from Version 1. Notice of Latest Version: V3 Release We have released the latest version, "V3: Scenario Modeling Edition," as a significant evolution of this program (V2), designed to facilitate the formulation of future plans and interactive scenario assessments in workshop settings. While V2 primarily focused on the analysis of existing public transport networks (visualizing supply capacity through flow mapping), V3 serves as a participatory, interactive modeling tool that enables the drawing and simulation of new route proposals via an integrated "drawing function". Representing a transition from analysis to creation (design), V3 is accessible via the link below. V3 (Scenario Modeling Edition): https://doi.org/10.5281/zenodo.20130390 International Context: Design Philosophy of Dynamic Accessibility Evaluation While drawing upon domestic discussions led by Madoka Nakashima et al., this tool’s design philosophy aligns with the international context—specifically with the dynamic accessibility evaluation framework proposed by a research group at the University of South Wales, UK: Webb, L., Langford, M., Higgs, G., & Berry, R. (2025). The design of a dynamic web-based solution to measure accessibility via public transport under different travel scenarios. Case Studies on Transport Policy, 21, 101561. https://doi.org/10.1016/j.cstp.2025.101561 Webb et al. (2025) proposed an interactive Web-GIS tool that integrates various open-source technologies, enabling policymakers to dynamically analyze and compare the impacts of different travel scenarios—such as the withdrawal of transit agencies or the removal/addition of specific bus routes—on public transport accessibility . Uniqueness of This Tool: "Straightforward Implementation" Free of Complex Infrastructure The author’s R code shares the core objective of Webb et al. (2025): simulating how changes in bus stop placement and route configurations impact a region to provide visual evidence for Evidence-Based Polic

Publication details

Journal / source
Zenodo (CERN European Organization for Nuclear Research)
Publication date
11 May 2026
Language
EN