#' Import all data
#'
#' @param x parameter needs to be left empty
#'
#' @return Returns a spatial features point object containing all accidents available from Destatis
#' @export
#'
#'
#' @importFrom sf read_sf
#' @importFrom sf st_as_sf
#' @importFrom sf st_transform
#' @importFrom stats setNames
#' @importFrom utils download.file
#' @importFrom utils unzip
#' @importFrom plyr rbind.fill
#'
import_all <- function(x) {
temp <- tempfile()
download.file(
"https://unfallatlas.statistikportal.de/app/UnfalldatenDownload/Unfallorte2016_LinRef_Shapefile.zip",
temp
)
unzip(temp)
download.file(
"https://unfallatlas.statistikportal.de/app/UnfalldatenDownload/Unfallorte2017_LinRef_Shapefile.zip",
temp
)
unzip(temp)
download.file(
"https://unfallatlas.statistikportal.de/app/UnfalldatenDownload/Unfallorte2018_LinRef_Shapefile.zip",
temp
)
unzip(temp)
filenames <-
list.files("./Shapefile/", pattern = "*.shp$", full.names = TRUE)
y_all <- lapply(filenames, read_sf)
y_16 <-
c(
"ULAND",
"UREGBEZ",
"UKREIS",
"UGEMEINDE",
"UJAHR",
"UMONAT",
"USTUNDE",
"UWOCHENTAG",
"UKATEGORIE",
"UART",
"UTYP1",
"IstRad",
"IstPKW",
"IstFuss",
"IstKrad",
"IstSonstig",
"ULICHTVERH",
"STRZUSTAND",
"LINREFX",
"LINREFY",
"geometry"
)
y_17 <-
c(
"UIDENTSTLA",
"ULAND",
"UREGBEZ",
"UKREIS",
"UGEMEINDE",
"UJAHR",
"UMONAT",
"USTUNDE",
"UWOCHENTAG",
"UKATEGORIE",
"UART",
"UTYP1",
"IstRad",
"IstPKW",
"IstFuss",
"IstKrad",
"IstSonstig",
"ULICHTVERH",
"STRZUSTAND",
"LINREFX",
"LINREFY",
"geometry"
)
y_all[[1]] <- setNames(y_all[[1]], y_16)
y_all[[2]] <- setNames(y_all[[2]], y_17)
y_all <- rbind.fill(y_all)
y_all$UJAHR[y_all$UJAHR == "16"] <- "2016"
y_all<-st_as_sf(y_all)
y_all<-st_transform(y_all,25832)
return(y_all)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.