View source: R/geocode_onemap.R
geocode_onemap | R Documentation |
This function is a wrapper for the Search API. It allows for geocoding of data such as postal codes or address information. Users input a dataframe with a column to geocode (e.g. postal codes, address information).
It returns a tibble with additional columns of coordinate data. Optionally, it can also return the output as an sf
object.
geocode_onemap(
df,
search_val,
return_geom = FALSE,
address_details = FALSE,
return_spatial = FALSE,
spatial_lnglat = TRUE,
parallel = FALSE
)
df |
Input tibble with column to be geocoded |
search_val |
Column name containing keyword(s) to be geocoded, e.g. column of postal codes |
return_geom |
Default = |
address_details |
Default = |
return_spatial |
Default = |
spatial_lnglat |
Default = |
parallel |
Default = |
Please note only the top result matching the search will be returned. If no error occurs:
Detailed search name
Longitude in SVY21. Returned only if return_geom = TRUE
Latitude in SVY21. Returned only if return_geom = TRUE
Longitude in WGS84. Returned only if return_geom = TRUE
Latitude in WGS84. Returned only if return_geom = TRUE
Block number
Road Name
Building Name
Address
Postal Code
If an error occurs, an empty result will be returned for that row. A warning message will be printed with the serach value, API error message and status code.
# sample dataframe. the last record does not return any API results.
df <- data.frame(
places = c("a", "b", "c", "d"),
address = c("raffles place mrt", "suntec city", "nus", "100353")
)
# Returns the original df with additional columns
## Not run: geocode_onemap(df, "address",
return_geom=TRUE, address_details = TRUE, return_spatial=TRUE)
## End(Not run)
# If an error occurs for any of the rows, an empty row will be returned.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.