readme.md

OneMapSGAPI

Maintenance CRAN version !Downloads

Getting Started

Introduction

The OneMapSGAPI package provides useful wrappers for the OneMapSG API client. It allows users to easily query spatial data from the API in a tidy format and provides additional functionalities to allow easy data manipulation.

:tada: Version 1.1.0 is now available! Version update features greater options to return results in spatial formats, including features to return decoded route geometry for spatial analysis and visualisation.

The OneMapSg API package is now available on CRAN-R! :tada: :confetti_ball: To download the release version, run:

install.packages("onemapsgapi")

The development version can be downloaded via:

# install.packages("devtools")
devtools::install_github("jolene-lim/onemapsgapi")

The development version is recommended as this package is early in its lifecycle. Please submit any problems via a github issues. Pull requests are also encouraged for anyone looking to contribute!

Features

Status

Currently, the following API endpoints are supported:

| API | Coverage | Supported Endpoints | | --- | --- | --- | | Post | :white_check_mark: Full | getToken | | Themes | :white_check_mark: Full | checkThemeStatus, getThemeInfo, getAllThemesInfo, retrieveTheme | Planning Area | :white_check_mark: Full | getAllPlanningarea, getPlanningareaNames, getPlanningarea | Population Query | :white_check_mark: Full | getEconomicStatus, getEducationAttending, getEthnicGroup, getHouseholdMonthlyIncomeWork, getHouseholdSize, getHouseholdStructure, getIncomeFromWork, getIndustry, getLanguageLiterate, getMaritalStatus, getModeOfTransportSchool, getModeOfTransportWork, getOccupation, getPopulationAgeGroup, getReligion, getSpokenAtHome, getTenancy, getTypeOfDwellingHousehold, getTypeOfDwellingPop | Routing Service | :white_check_mark: Full | route Note: Route Decoder V1.1.0 features internal decoding capabilities via the googlePolylines package

Usage

Authentication

In order to query data, most API endpoints in the OneMapSG API require a token. First-time users can register themselves using the OneMapSG registration form. Subsequently, they can retrieve their tokens using the get_token() function with their email and password, for example:

token <- get_token("user@email.com",  "password")

The function will also print a message informing users of the token's expiry date and time.

Themes

Themes in the OneMap SG API refer to types of locations, such as kindergartens, parks, hawker centres etc. This package provides functions related to querying themes:

# example: returns named logical if theme has been updated at time of query

get_theme_status(token, "hotels")
# example: returns character vector related to kindergaterns theme

get_theme_info(token, "kindergartens")
# example: return all themes related to "hdb" or "parks"
search_themes(token, "hdb", "parks")

# example: return all possible themes
search_themes(token)
# example: return the location coordinates + other data of all hotels in Singapore
get_theme(token, "hotels")

Planning Area

Planning Area API endpoints allow users to get spatial data and data related to the planning areas in Singapore. This package provides users with the ability to query the data and optionally handles necessary spatial data wrangling on behalf of the user.

# example: return dataframe of class "sf" for planning areas in 2014
get_planning_areas(token, 2014, read = "sf")
# example: return dataframe of planning areas in 2014
get_planning_names(token, 2014)
# example: return spatial polygon of class "sf" for planning area matching the input point in 2014
get_planning_polygon(token, 1.3, 103.8, 2014, read = "sf")

Population Query

Population Query API endpoints allow users to pull socio-economic datasets by planning area, which each endpoint representing a dataset (e.g. getPopulationAgeGroup provides age group summary statistics by planning area). This package combines querying different Popquery API endpoints into a single function.

# example: return occupation summary data and literacy summary data for Bedok and Yishun towns in year 2010
get_pop_queries(token, c("getOccupation", "getLanguageLiterate"), c("Bedok", "Yishun"), "2010")

Route Service

The Route Service API provides users a way to query the route taken from one point to another. It provides information about the total time and distance taken for the route, route instructions and other infomation e.g. elevation, for a variety of routes (public transport, drive, walk, cycle). This package provides three different functions associated with this API, each serving different purposes.

# example: return route data only in tibble format
get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive")

# example: return route data (tibble) and status information (list) as list of 2
get_route(token, c(1.319728, 103.8421), c(1.319728905, 103.8421581), "drive", status_info = TRUE)

For large queries, allowing parallel iterations is recommended as it can halve the return time. Note that for queries involving a large volume of API calls, return time will still be limited by the API call speed.

# example: return tibble named df
get_travel(token, df,
    "start_lat", "start_lon", "end_lat", "end_lon",
    routes = c("cycle", "walk"))


jolene-lim/onemapsgapi documentation built on Dec. 8, 2022, 12:42 a.m.