geocode_onemap {onemapsgapi} | R Documentation |
Geocode a dataframe of keywords
Description
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.
Usage
geocode_onemap(
df,
search_val,
return_geom = FALSE,
address_details = FALSE,
return_spatial = FALSE,
spatial_lnglat = TRUE,
parallel = FALSE
)
Arguments
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 = |
Value
Please note only the top result matching the search will be returned. If no error occurs:
- SEARCH_VAL
Detailed search name
- X
Longitude in SVY21. Returned only if
return_geom = TRUE
- Y
Latitude in SVY21. Returned only if
return_geom = TRUE
- LONGITUDE
Longitude in WGS84. Returned only if
return_geom = TRUE
- LATITUDE
Latitude in WGS84. Returned only if
return_geom = TRUE
- BLK_NO
Block number
- ROAD_NAME
Road Name
- BUILDING
Building Name
- ADDRESS
Address
- POSTAL
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.
Examples
# 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.