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 or as an sf tibble.

Usage

get_planning_polygon(token, lat, lon, year = NULL, return_spatial = FALSE)

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.

return_spatial

Optional, defaults to FALSE. If TRUE, result will be returned as a sf tibble, otherwise the raw JSON object will be returned.

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 an error occurs, the function throws an error with the API error message and status code.

Note

If the user specifies a return_spatial = TRUE but does not have the sf 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, return_spatial = TRUE)

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

onemapsgapi documentation built on June 8, 2025, 10:05 a.m.