Learn R Programming

onemapsgapi (version 1.1.0)

get_planning_polygon: Get Planning Polygon for a Specific Point

Description

This function is a wrapper for the Planning Area Query API. It returns the spatial polygon data matching the specified location point, either in raw format, as an sf or sp object.

Usage

get_planning_polygon(token, lat, lon, year = NULL, read = "tibble")

Value

If the parameter read is not specified, the function returns a raw JSON object a list containing the planning area name and a geojson string representing the polygon.


If read = "sf", the function returns a 1 x 2 "sf" dataframe: "name" (name of planning area) and "geometry", which contains the simple feature.


If read = "rgdal", the function returns a SpatialPolygonsDataFrame of "sp" class. The names of the 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

lat

Latitude of location point

lon

Longitude of location point

year

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

read

Optional, defaults to tibble. Package to use to read geojson object. For "sf" objects, specify read = "sf" and for "sp" objects use read = "rgdal".

Examples

Run this code
# returns raw JSON object
if (FALSE) get_planning_polygon(token, lat = 1.429443081, lon = 103.835005)
if (FALSE) get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, year = 2008)

# returns dataframe of class "sf"
if (FALSE) get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, read = "sf")

# returns SpatialPolygonsDataFrame ("sp" object)
if (FALSE) get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, read = "rgdal")

# error: output is NULL, warning message shows status code
if (FALSE) get_planning_polygon("invalid_token")
if (FALSE) get_planning_polygon(token, "invalidlat", "invalidlon")

Run the code above in your browser using DataLab