knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
library(dplyr)
library(DT)
library(TDX)
client_id=read.csv("./key.txt", header=F)[1,2]
client_secret=read.csv("./key.txt", header=F)[2,2]
access_token=get_token(client_id, client_secret)

Overview

include_graphics("./figure/TDX_icon.png")

This package can be used to connect transportation data from TDX (Transport Data eXchange) in a neat and efficient way. TDX platform is supported by Ministry of Transportation and Communications (MOTC) in Taiwan, which provides lots of API for the members download the transportation data. Before using the function provided in this package, the authentication key is a must, which can be applied from TDX platform. After being a member of TDX, you will soon get the Client Id and Client Secret, please check out in the API key Dashboard.

Installation

Please install the package from Github (ChiaJung-Yeh/NYCU_TDX).
If you are Python user, please refer to here for Python package via PyPi.

install.packages("devtools")
devtools::install_github("ChiaJung-Yeh/NYCU_TDX")
library(TDX)

Usage

All functions provided in this package are summarized in the table below.

TDX_table=data.frame(data=c(rep("軌道", 7), rep("公車", 8), rep("自行車", 4), rep("航空與航運", 4), rep("高速公路", 2), "停車場","觀光點位", "道路路網", "地理編碼","人口","所得","行政區","GTFS"), type=c("軌道站點","軌道路線站點","軌道站點出口","軌道路線線型","軌道班表","軌道票價","軌道站間旅行時間","公車站點","公車路線","公車路線線型","公車班表","公車站間旅行時間","公車票價","公車車輛","公車動態","公共自行車站點","自行車路網","公共自行車站點歷史動態","臺北市公共自行車租借紀錄","航空班表","港口點位","航運航線","航線靠港順序","高快速公路線型","高速公路 etag 與 VD","停車場點位資訊","景點、餐廳、旅館點位","道路路網線型","地理編碼服務","人口(含各年齡層與性別資料)","所得(各村里)","行政區疆域","公共運輸標準格式"), class=c(rep("點", 3),"線",rep("文字", 3),"點","文字","線",rep("文字", 4),"點","點","線",rep("文字", 3),"點",rep("文字", 2),"線","文字","點","點","線","點", rep("文字", 2), "面","文字"), functiona=c("`Rail_Station()`", "`Rail_StationOfLine()`","`Rail_StationExit()`", "`Rail_Shape()`", "`Rail_TimeTable()`", "`Rail_ODFare()`", "`Rail_TravelTime()`", "`Bus_StopOfRoute()`", "`Bus_Route()`", "`Bus_Shape()`", "`Bus_Schedule()`", "`Bus_TravelTime()`","`Bus_RouteFare()`","`Bus_Vehicle()`","`Bus_RealTime()`", "`Bike_Station()`", "`Bike_Shape()`", "`Bike_Remain_His()`", "`Bike_OD_His()`", "`Air_Schedule()`", "`Ship_Port()`", "`Ship_Route()`", "`Ship_StopOfRoute()`", "`Freeway_Shape()`","`Freeway_History()`","`Car_Park()`", "`Tourism()`","`Road_Network()`","`Geocoding()`","`Population()`","`Income()`","`District_Shape()`","`gtfs()`"))

colnames(TDX_table)=c("資料","資料細目","資料型態","函式")
kable(TDX_table, booktabs=T)%>%
  kable_styling(bootstrap_options=c("striped", "hover"), font_size=14)%>%
  column_spec(1, bold=T)%>%
  collapse_rows(columns=c(1:4))%>%
  row_spec(0, bold=T, color="white", background="#8E8E8E")

Data retrieving process requires an access token to obtain the data from TDX platform. Most function in this package should use function get_token() in advance to obtain the token by entering your Client ID and Client Secret first. Note that the access token will expire in 1 day.

Take retrieving MRT stations of Taipei Metro System for example. The code is shown below. Here the argument CLIENT_ID and CLIEN_SECRET is the authentication key applied from TDX.

# get the access token first
access_token=get_token("CLIENT_ID", "CLIEN_SECRET")

# retrieve Taipei MRT station
TRTC_station=Rail_Station(access_token, "TRTC")

# historical data
# TRTC_station=Rail_Station(access_token, "TRTC", dates="2023-01-01")

head(TRTC_station)

The result is shown as followings.

TRTC_station=Rail_Station(access_token, "TRTC")
head(TRTC_station)

Usages of other functions can be found in the TDX Guide website.

Support

This package takes advantage of API service provided by TDX, MOTC.

include_graphics("./figure/TDX.png")

Contact

For questions, bugs, and other discussion, please feel free to contact the package maintainer, Chia Jung, Yeh.
Email: chia-jung.yeh@sydney.edu.au



ChiaJung-Yeh/NYCU_TDX documentation built on Aug. 28, 2024, 10:43 p.m.