get_planning_polygon: Get Planning Polygon for a Specific Point

View source: R/get_planning_polygon.R

get_planning_polygonR Documentation

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")

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".

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.

Note

If the user specifies a read method but does not have the corresponding package installed, the function will return the raw JSON and print a warning message.

Examples

# returns raw JSON object
## Not run: get_planning_polygon(token, lat = 1.429443081, lon = 103.835005)
## Not run: get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, year = 2008)

# returns dataframe of class "sf"
## Not run: get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, read = "sf")

# returns SpatialPolygonsDataFrame ("sp" object)
## Not run: get_planning_polygon(token, lat = 1.429443081, lon = 103.835005, read = "rgdal")

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

onemapsgapi documentation built on Nov. 29, 2022, 9:06 a.m.