There is a newer version of the record available.

Published July 7, 2026 | Version v2.1

R Code for Regional Analysis: GTFS shapes.txt Generation from GPS Logs and Open Bus-Stop/Timetable Data

  • 1. ROR icon Nanzan University

Description

(日本語概要V1.2)本スクリプトは、公共交通のオープンデータ形式である GTFS の shapes.txt を R で読み込み、国土地理院タイルを背景とした対話的な地図上に路線形状を可視化するツールである。カラーバリアフリー対応の単色表示に対応しており、GIS ソフトで利用可能な Shapefile 形式への変換・保存も可能である。設定パラメータを変更するだけで全国の自治体の GTFS データに対応でき、東浦町・知多市の GTFS データで動作確認済みである。

このツールの開発には Anthropic の Claude (claude.ai)とGemini をコード支援として使用しました。

This repository provides tools for generating and validating GTFS shapes.txt for community bus services in Japan, developed around the Agui Town (Aichi Prefecture) community bus "Agupii-go."

The associated preprint — a Data Descriptor documenting both workflows, the complete corrected GTFS feed (feed_version 5.0), and a pre-registered field validation protocol — is available on SSRN: https://ssrn.com/abstract=7105058

Version 2.1 Updated

Version 2.1 adds a complete, corrected GTFS feed for the Agupii-go community bus (nine files, feed_version 5.0, distributed as output_agui_gtfs.zip), together with a reproducible R script (make_complete_feed.R, base R only, no external packages) that builds the feed from the previously published V4.3 GTFS files (see the predecessor record, DOI: 10.5281/zenodo.20575685) combined with this repository's network-based shapes.txt and shape_index.csv.

The script performs four groups of corrections: (1) it reassigns per-trip shape_id values so that each of the ten distinct stop patterns — including two loop-direction variants of the same stop set and short-turn services — references its correct geometry, and adds direction_id; (2) it resolves duplicate stop_id entries in stops.txt (143 rows reduced to 77 unique stops), selecting among conflicting coordinates by a deterministic nearest-to-shape rule; (3) it appends the missing terminal stops of trips 108 (Fukuzumien-Takadai-Minami) and 207 (Shinden-mae), identified by cross-checking the feed against the operator's official printed timetable; and (4) it adds route_color, agency_lang, and a newly created feed_info.txt (a GTFS-JP required file), and extends the service period to cover all listed calendar exceptions.

All corrections are recorded as data inside the script, so the feed can be regenerated deterministically from the inputs. The published output_agui_gtfs.zip was verified to be byte-identical to the script's output in an independent environment. Zenodo record v2.1 corresponds to GTFS feed_version 5.0; this record now supersedes the GTFS files in the predecessor record, which is frozen as the dataset accompanying its SSRN preprint.

Version 2.0 Updated

Version 2.0 adds a network-based method for generating shapes.txt directly from openly published bus-stop coordinates and timetable data, without requiring a GPS survey. Stop-to-stop paths are derived as shortest paths over a road-network graph built from MLIT's National Land Numerical Information bus-route data (N07), with stops snapped onto the network. An optional via.csv file lets users correct segments — such as one-way turnaround loops with no intermediate stop — where the shortest path deviates from the actual route; this correction mechanism, and its rationale, is a general-purpose addition intended to be reusable for other municipalities. To our knowledge, this is among the first published, reusable methods for generating GTFS shapes from open bus-stop and timetable data alone, offering a resource-free alternative for small municipal bus operators that cannot afford a dedicated GPS survey.

Both an R implementation (make_shapes.R, using igraph) and a Python implementation (make_shapes.py, using networkx) are provided, following the same algorithm and producing the same output format. During development, the two implementations were confirmed to produce byte-identical output on the author's environment (R 4.3.3 / Python 3.12, Linux); this was a one-time developer-side check, and the Python version has not been independently re-verified by the author since. Users of the Python script are encouraged to compare its output against the R version's shapes.txt in their own environment before relying on it.

Quantitative validation is planned as future work: on-board GPS ride logs will be acquired on all Agupii-go routes using the logging application in this repository and compared against the network-based shapes; the logs and results will be added in a future version.

Full usage instructions, input/output specifications, and the via.csv format are documented as comments at the top of each script (make_shapes.R, make_shapes.py, make_map.R).

Note on file naming: As of v2.0, the files shapes.txt and shape_index.csv in this repository refer to the network-based method described above. The v1.2 fieldwork GPS log (gps_log_20260620_004858.gpx) and its generation script (V1_2_gpx_to_gtfs_shapes.R) remain available; the GPS-derived shapes.txt can be regenerated from them at any time.

Earlier versions (v1.0–v1.2): This tool reads GTFS shapes.txt, a standard open data format for public transportation, using R, and visualizes route shapes on an interactive map with the Geospatial Information Authority of Japan (GSI) tiles as a background. It supports color-barrier-free single-color display and can convert and save data in Shapefile format for use in GIS software. By modifying the configuration parameters, the tool is compatible with GTFS data from municipalities across Japan, and has been tested with GTFS data from Higashiura Town and Chita City.

Version 1.1 added a web-based application that enables users to reliably record GPS coordinates in real time during field surveys and export them as standard GPX logs, so that post-fieldwork logs can be visualized together with GTFS spatial routes (shapes.txt) for desktop review. Live demo: https://moteki.shinyapps.io/gpxlog/

Version 1.2 added a streamlined workflow to automatically generate GTFS shapes.txt from raw GPX logs, enabling direct creation of high-precision spatial routes through actual passenger tracking on community buses. Additionally, the dynamic GPS visualization script was updated to align with rail transport characteristics for realistic train operation simulation. By incorporating a sequential velocity-based filtering algorithm, this version efficiently filters out instantaneous GPS jump coordinates caused by multipath errors to ensure smooth, unidirectional track rendering. The interface was further refined with standardized English controls and a locked 500-millisecond refresh cycle, delivering a highly stable, artifact-free desktop playback experience for rigorous transport analysis. Live demo: https://moteki.shinyapps.io/gps_player/

 

AI disclosure: This work was developed interactively via claude.ai, using Anthropic's Claude and Google's Gemini across versions. For v2.0 specifically: code development (the R and Python shapes.txt generation scripts, the map-visualization script, and the via.csv correction mechanism) was carried out using Claude Fable 5; this documentation was prepared using Claude Sonnet 5.

Files

check_shapes_map_example.png

Files (4.8 MB)

Name Size Download all
md5:cc056ff0fe8ad43c0397864a72d2eab0
77.1 kB Download
md5:46f0e19279264ba45cd0b3026ffa9b02
4.6 kB Download
md5:c6265386acb9192e93591f5e89ffb749
1.0 MB Preview Download
md5:3b919d61b195538367e7f42a96251544
3.2 kB Download
md5:38585b5500d045b4faf0152e8ea65a70
140.9 kB Download
md5:6b7ca25ed7ca74e9dd8e56cf9c75ecf1
6.2 kB Download
md5:2d34ed1b8e6463b03414f47d2ae79694
12.1 kB Download
md5:6119aec80f4e80173e3315eb449f43c6
4.6 kB Download
md5:a0afab93ec0382084b7d8aeb5785397e
8.4 kB Download
md5:6a2136538c89e5c75128b95839f37839
13.2 kB Download
md5:b70287273778342ef0501f09fc3e6e02
31.6 kB Preview Download
md5:1f08edbb720f1282624b766ffafe1213
10.6 kB Preview Download
md5:1b962c9ec091812dd0793b90a4e0b4e5
1.0 kB Preview Download
md5:c3294fcdf874959f636c4ee5c05e802e
144.5 kB Preview Download
md5:e721ce73fd64c231060d55bf41467d07
4.3 kB Download
md5:540bc555af42c32b42c192d04e37d468
10.4 kB Download
md5:d39cad3495a682ce9bd4e6b9390c65e2
1.4 MB Preview Download
md5:9eeaceae0e97dcfbc8a2a651ae01d07a
1.2 MB Preview Download
md5:b3a58dcde03e759dd755ad507427f2b1
4.7 kB Download
md5:dacd9e71ab7e8542cdf67a194c5680e2
656.1 kB Preview Download
md5:4879314e17049be41a7f476720e867ea
152 Bytes Preview Download
md5:6b09171f20696c7d5ddc4722636168b8
7.1 kB Download

Additional details

Related works

Is supplement to
Software: 10.5281/zenodo.20070687 (DOI)
Preprint: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=7105058 (URL)
References
Software: 10.5281/zenodo.20277603 (DOI)

Software

Programming language
R