Learn R Programming

onemapsgapi (version 1.1.0)

get_planning_areas: Get Planning Areas (All)

Description

This function is a wrapper for the Planning Area Polygons API. It returns the data either in raw format or a combined sf or sp object.

Usage

get_planning_areas(token, year = NULL, read = NULL)

Value

If the parameter read is not specified, the function returns a raw JSON object with planning names and geojson string vectors.


If read = "sf", the function returns a single "sf" dataframe with 2 columns: "name" (name of planning area) and "geometry", which contains the simple features.


If read = "rgdal", the function returns a SpatialPolygonsDataFrame of "sp" class. The names of each planning area is recorded in the "name" column of the dataframe.


If an error occurs, the function returns NULL and a warning message is printed.

Arguments

token

User's API token. This can be retrieved using get_token

year

Optional, check documentation for valid options. Invalid requests will are ignored by the API.

read

Optional, which package to use to read geojson object. For "sf" objects, specify read = "sf" and for "sp" objects use read = "rgdal". Note that if used, any missing geojson objects will be dropped (this affects the "Others" planning area returned by the API).

Examples

Run this code
# returns raw JSON object
if (FALSE) get_planning_areas(token)
if (FALSE) get_planning_areas(token, 2008)

# returns dataframe of class "sf"
if (FALSE) get_planning_areas(token, read = "sf")

# returns SpatialPolygonsDataFrame ("sp" object)
if (FALSE) get_planning_areas(token, read = "rgdal")

# error: output is NULL, warning message shows status code
if (FALSE) get_planning_areas("invalid_token")

Run the code above in your browser using DataLab