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, as an sf or sp object.
get_planning_polygon(token, lat, lon, year = NULL, read = "tibble")
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. |
read |
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 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.
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.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.