This function renames a `sf` with a minimal set of attributes with consistent naming with `code`, `name` and `codeType` columns and an optional `altCode` column. Renames all columns to be lower case, and makes sure the `area` column is calculated. It also loses any `Z` or `M` layers.
Usage
standardiseMap(
sf,
codeCol = "code",
nameCol = "name",
altCodeCol = NULL,
codeType = NA_character_,
...
)
Arguments
- sf
a non standard map
- codeCol
the name of the column containing the id or code
- nameCol
the name of the column containing the label (optional - defaults to the same as codeCol)
- altCodeCol
an optional column name containing another code type
- codeType
the "type" of the code - optional. defaults to NA
- ...
not used.
Value
a standardised map with exactly the following columns: `code`, `codeType`, `name`, `altCode`, `geometry` and `area`
Examples
# example code
if (interactive()) {
svc = "https://services1.arcgis.com/ESMARspQHYMw9BZ9/ArcGIS/rest/services"
fs = sprintf("%s/%s",svc,"Countries_December_2024_Boundaries_UK_BUC/FeatureServer")
layer = sprintf("%s/%s",fs,"0")
map = downloadGeojson(layer)
map %>% dplyr::glimpse()
map2 = map %>% standardiseMap(codeCol = CTRY24CD, nameCol = CTRY24NM)
map2 %>% dplyr::glimpse()
}