View source: R/get_planning_polygon.R
get_planning_polygon | R Documentation |
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.
get_planning_polygon(token, lat, lon, year = NULL, return_spatial = FALSE)
token |
User's API token. This can be retrieved using |
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 |
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.
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.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.