diff --git a/.Rbuildignore b/.Rbuildignore index c0679c7..6de7dc8 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -16,3 +16,6 @@ vignette\.Rmd\.orig ^LICENSE\.md$ ^CONTRIBUTING\.md$ ^CITATION\.cff$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/.gitignore b/.gitignore index 847eaa4..e366eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ inst/doc /data-raw/eu_dem* /joss-paper/*.pdf *.log +docs diff --git a/DESCRIPTION b/DESCRIPTION index ac0a65e..2c642f6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,18 @@ Package: RCzechia Type: Package Title: Spatial Objects of the Czech Republic -Version: 1.11.2.999999999 -Date: 2023-XX-XX +Version: 1.12.0 +Date: 2023-10-29 Authors@R: c( person("Jindra", "Lacko", , "jindra.lacko@gmail.com", role = c("aut", "cre"), - comment = c(ORCID = "0000-0002-0375-5156")), + comment = c(ORCID = "0000-0002-0375-5156")), person("Nick", "Bearman", role = "rev", - comment = "Nick reviewed the package for JOSS, providing helpful comments leading to significant improvement of the package.")) + comment = c(ORCID = "0000-0002-8396-4061", + "Nick reviewed the package for JOSS, providing helpful comments leading to significant improvement of the package.")) + ) Maintainer: Jindra Lacko Description: Administrative regions and other spatial objects of the Czech Republic. -URL: https://github.com/jlacko/RCzechia +URL: https://rczechia.jla-data.net BugReports: https://github.com/jlacko/RCzechia/issues License: MIT + file LICENSE Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 9546c4b..db5dd0c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(casti) export(chr_uzemi) export(geocode) export(geomorfo) +export(historie) export(kraje) export(lesy) export(obce_body) diff --git a/NEWS.md b/NEWS.md index 51e1c0e..d1ab5b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,12 @@ -## version 1.11.2 (2023-XX-XX) +## version 1.12.0 (2023-10-29) + + - [!] introduced an option for persistent local caching via setting the `RCZECHIA_HOME` environment variable; this has to be set manually - either directly or via a set_home() function call + + - added history() function providing historical admin areas, together with census data - - updated documentation for the geomorfo function + - updated documentation for the geomorfo() function + + - introduced pkgdown documentation on https://rczechia.jla-data.net ## version 1.11.1 (2023-03-04) diff --git a/R/KFME_grid.R b/R/KFME_grid.R index 11e3805..6fe1309 100644 --- a/R/KFME_grid.R +++ b/R/KFME_grid.R @@ -2,7 +2,9 @@ #' #' Function returning grid covering the Czech Republic according to the Kartierung der Flora Mitteleuropas methodology. #' -#' The function returns a {sf} data frame of grid cells. Depending on the value of parameter `resolution` either low resolution (26×42 cells - default) with labels in 4 digit format (e.g. Hrčava = 6479) or high resolution (104×168 cells) with labels in 4 digit + 1 letter format (e.g Hrčava = 6479c). +#' The function returns a `sf` data frame of grid cells. Depending on the value of parameter `resolution` either low resolution (26×42 cells - default) with labels in 4 digit format (e.g. Hrčava = 6479) or high resolution (104×168 cells) with labels in 4 digit + 1 letter format (e.g Hrčava = 6479c). +#' +#' Raw version of the dataset is available for download for use in non-R setting on . #' #' @param resolution Should the function return high or low resolution shapefile? Allowed values are "low" and "high". Default is "low". #' diff --git a/R/casti.R b/R/casti.R index e38234a..446e6bb 100644 --- a/R/casti.R +++ b/R/casti.R @@ -1,9 +1,11 @@ -#' City Parts +#' City Districts #' #' Function taking no parameters and returning data frame of districts of Prague and other major cities as `sf` polygons. #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021. Downloaded size is 1.5 MB. #' #' diff --git a/R/downloader.R b/R/downloader.R deleted file mode 100644 index e7416ee..0000000 --- a/R/downloader.R +++ /dev/null @@ -1,40 +0,0 @@ -#' Internal function - generic downloader, used to serve the rds files from S3 -#' -#' The function utilizes environment variable RCZECHIA_MIRROR as a mirror location of remote files; to configure an alternative (possibly local) repository use `Sys.setenv("RCZECHIA_MIRROR" = "file:///someplace/local")` -#' -#' @param file file to be downloaded (or not...) from S3 -#' @keywords internal - -.downloader <- function(file) { - network <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE)) # dummy variable to allow testing of network - - remote_path <- Sys.getenv("RCZECHIA_MIRROR", unset = "https://rczechia.jla-data.net/") # remote archive - - remote_file <- paste0(remote_path, file) # path to AWS S3 - local_file <- file.path(tempdir(), file) # local file - in tempdir - - if (file.exists(local_file)) { - message("RCzechia: using temporary local dataset.") - } else { - if (!.ok_to_proceed(remote_file) | !network) { # network is down -# message("No internet connection.") - return(NULL) - } - - # proceed to download via curl - message("RCzechia: downloading remote dataset.") - curl::curl_download(url = remote_file, - destfile = local_file, - quiet = F) - } # /if - local file exists - - # everything except rasters - if(tools::file_ext(local_file) == "rds") local_df <- readRDS(local_file) - - # rasters, and rasters only - if(tools::file_ext(local_file) == "tif") local_df <- terra::rast(local_file) - - # serve the result back - local_df - -} # /function diff --git a/R/geomorfo.R b/R/geomorfo.R index f320c19..f03800b 100644 --- a/R/geomorfo.R +++ b/R/geomorfo.R @@ -23,6 +23,17 @@ #' #' @source CENIA / INSPIRE, via Mgr. Vojtěch Blažek, Ph.D. #' +#' @examples +#' +#' \donttest{ +#' library(sf) +#' +#' soustavy <- RCzechia::geomorfo("subprovincie") +#' +#' plot(soustavy["kod"]) +#' +#' } +#' #' @export geomorfo <- function(level) { diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..dccbb05 --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,36 @@ +#' Set the local cache directory +#' +#' The function sets the environment variable RCZECHIA_HOME to be used as a local cache for RCzechia remote files; if unset tempdir() is used instead, with persistence for current session only. +#' +#' Note that when set (it is unset by default) the remote files will be cached to local file system and persist between R sessions, for good or bad. +#' +#' Also note that you can set the value of RCZECHIA_HOME environment variable directly, either via a \code{Sys.setenv()} call or via your \code{.Renviron} file. +#' +#' @param path file to be downloaded (or not...) from S3 +#' +#' @return TRUE for success and FALSE for failure; returned silently + +set_home <- function(path) { + + if(file.access(path, mode = 2) == 0) { + Sys.setenv("RCZECHIA_HOME" = path) + invisible(TRUE) + } else { + warning("'path' not found or not writeable; default will be used instead") + invisible(FALSE) + } + +} + +#' Unset the local cache directory +#' +#' The function unsets the environment variable RCZECHIA_HOME, meaning tempdir() will be used in future function calls, and no persistent data will be stored locally. +#' +#' @return TRUE for success and FALSE for failure; returned silently + +unset_home <- function() { + + Sys.unsetenv("RCZECHIA_HOME") + invisible(TRUE) + +} diff --git a/R/historie.R b/R/historie.R new file mode 100644 index 0000000..33386b6 --- /dev/null +++ b/R/historie.R @@ -0,0 +1,67 @@ +#' Historical censuses of the Czech Republic +#' +#' Function returning historical admin areas of the Czech Republic, together with relevant census data as specified by parameter **era**. +#' +#' The census data structure is too complex to fully list here; most of the fields are self documenting (for Czech speakers) - and when in doubt please consult the original metadata at , or the original journal article at . +#' +#' Of notable interest is the 1930 census, which was the last before WWII - and thus the last one to include Czechoslovak citizens of German ethnicity. +#' +#' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +#' +#' +#' @param era a historical era of interest. +#' +#' @return `sf` data frame with historical admin area names & census data + geometry; namely: +#' +#' \describe{ +#' \item{okresy_1921}{soudní okresy + census 1921; 328 rows / 92 columns + geometry} +#' \item{okresy_1930}{soudní okresy + census 1931; 330 rows / 90 columns + geometry} +#' \item{okresy_1947}{politické okresy + census 1947; 162 rows / 16 columns + geometry} +#' \item{okresy_1950}{správní okresy + census 1950; 193 rows / 57 columns + geometry} +#' \item{okresy_1961}{správní okresy + census 1960; 76 rows / 105 columns + geometry} +#' \item{okresy_1970}{správní okresy + census 1970; 76 rows / 144 columns + geometry} +#' \item{okresy_1980}{správní okresy + census 1980; 76 rows / 148 columns + geometry} +#' \item{okresy_1991}{správní okresy + census 1991; 76 rows / 155 columns + geometry} +#' \item{okresy_2001}{správní okresy + census 2001; 77 rows / 174 columns + geometry} +#' \item{okresy_2011}{správní okresy + census 2011; 77 rows / 176 columns + geometry} +#' \item{kraje_1950}{kraje + census 1950; 13 rows / 55 columns + geometry} +#' \item{kraje_1961}{kraje + census 1960; 8 rows / 103 columns + geometry} +#' \item{kraje_1970}{kraje + census 1970; 8 rows / 144 columns + geometry} +#' \item{kraje_1980}{kraje + census 1980; 8 rows / 146 columns + geometry} +#' \item{kraje_1991}{kraje + census 1991; 8 rows / 153 columns + geometry} +#' \item{kraje_2001}{kraje + census 2001; 14 rows / 172 columns + geometry} +#' \item{kraje_2011}{kraje + census 2011; 14 rows / 174 columns + geometry} +#' } +#' +#' Credits: +#' 1) „Tento výstup vznikl v rámci řešení projektu číslo DF12P01OVV033 Zpřístupnění historických prostorových a statistických dat v prostředí GIS řešeného v rámci programu Aplikovaného výzkumu a vývoje národní a kulturní identity (NAKI), jehož poskytovatel je Ministerstvo kultury České republiky.“ +#' 2) „JÍCHOVÁ, J., SOUKUP, M., NEMEŠKAL, J., OUŘEDNÍČEK, M., POSPÍŠILOVÁ, L., SVOBODA, P., ŠPAČKOVÁ, P. a kol. (2014): Geodatabáze historických statistických a prostorových dat Česka ze Sčítání lidu, domů a bytů 1921−2011. Urbánní a regionální laboratoř, Přírodovědecká fakulta Univerzity Karlovy v Praze, Praha.“ +#' +#' @source Urbánní a regionální laboratoř (UrRlab) působící na katedře sociální geografie a regionálního rozvoje Přírodovědecké fakulty Univerzity Karlovy v Praze +#' +#' @examples +#' +#' \donttest{ +#' library(sf) +#' +#' pre_war <- RCzechia::historie("okresy_1930") +#' +#' plot(pre_war[, 47], main = "Residents of German ethnicity") +#' +#' } +#' +#' @export + +historie <- function(era) { + + if(missing(era)) { + stop("historical era is an obligatory parameter!") + } + + if (!is.element(era, c("okresy_1921", "okresy_1930", "okresy_1947", "okresy_1950", "okresy_1961", "okresy_1970", "okresy_1980", "okresy_1991", "okresy_2001", "okresy_2011", "kraje_1950", "kraje_1961", "kraje_1970", "kraje_1980", "kraje_1991", "kraje_2001", "kraje_2011"))) { + stop(paste(era, "is not a valid historical era!")) + } + + result <- .downloader(paste0("history_", era, ".rds")) + result +} diff --git a/R/internals.R b/R/internals.R new file mode 100644 index 0000000..3954d97 --- /dev/null +++ b/R/internals.R @@ -0,0 +1,95 @@ +#' Internal function - generic downloader, used to serve the rds files from S3 +#' +#' The function utilizes environment variable RCZECHIA_MIRROR as a mirror location of remote files; to configure an alternative (possibly local) repository use `Sys.setenv("RCZECHIA_MIRROR" = "file:///someplace/local")` +#' +#' @param file file to be downloaded (or not...) from S3 +#' @keywords internal + +.downloader <- function(file) { + network <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE)) # dummy variable to allow testing of network + remote_path <- Sys.getenv("RCZECHIA_MIRROR", unset = "https://rczechia.jla-data.net/") # remote archive + local_dir <- Sys.getenv("RCZECHIA_HOME", unset = tempdir()) # local cache directory - or tempdir if unset + + remote_file <- paste0(remote_path, file) # path to AWS S3 + local_file <- file.path(local_dir, file) # local file - in tempdir, or local cache if set + + if (file.exists(local_file) & network) { + message(paste("RCzechia: using dataset stored locally in", local_dir)) + } else { + if (!.ok_to_proceed(remote_file) | !network) { # network is down +# message("No internet connection.") + return(NULL) + } + + # proceed to download via curl + message("RCzechia: downloading remote dataset.") + curl::curl_download(url = remote_file, + destfile = local_file, + quiet = F) + } # /if - local file exists + + # everything except rasters + if(tools::file_ext(local_file) == "rds") local_df <- readRDS(local_file) + + # rasters, and rasters only + if(tools::file_ext(local_file) == "tif") local_df <- terra::rast(local_file) + + # serve the result back + local_df + +} # /function + +#' Internal function - tests availability of internet resources +#' +#' @param remote_file resource to be tested +#' @keywords internal + +.ok_to_proceed <- function(remote_file) { + + # local files are OK to proceed by definiton + if (grepl("file:///", remote_file)) return(TRUE) + + # remote files require testing + try_head <- function(x, ...) { + tryCatch( + httr::HEAD(url = x, httr::timeout(10), ...), + error = function(e) conditionMessage(e), + warning = function(w) conditionMessage(w) + ) + } + + is_response <- function(x) { + class(x) == "response" + } + + network <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE)) # dummy variable to allow testing of network + + # First check internet connection + if (!curl::has_internet() | !network) { + message("No internet connection.") + return(FALSE) + } + # Then try for timeout problems + resp <- try_head(remote_file) + if (!is_response(resp)) { + message("Timeout reached; external data source likely broken.") + return(FALSE) + } + # Then stop if status > 400 + if (httr::http_error(resp)) { + message("Data source broken.") + return(FALSE) + } + + # safe to proceed + TRUE +} + +# check the environment variable & report back + +.onAttach <- function(libname, pkgname) { + + home <- Sys.getenv("RCZECHIA_HOME") + + if(home != "") packageStartupMessage("Using local RCzechia cache at ", home, appendLF = TRUE) +} diff --git a/R/kraje.R b/R/kraje.R index c73409c..fef1594 100644 --- a/R/kraje.R +++ b/R/kraje.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size of high resolution shapefile is <1 MB. #' #' @param resolution Should the function return high or low resolution shapefile? Allowed values are "high" (default) and "low". This parameter affects only the geometry column, all other fields remain the same. @@ -21,8 +23,19 @@ #' @examples #' library(sf) #' -#' hranice <- kraje("low") -#' plot(hranice, col = "white", max.plot = 1) +#' colors <- rainbow(14) # legend colors +#' +#' hranice <- RCzechia::kraje("low") +#' +#' plot(hranice["KOD_CZNUTS3"], +#' col = colors, +#' main = "Czech Regions", +#' xlim = st_bbox(hranice)[c(1, 3)] * c(1, 1.1)) +#' +#' legend("right", +#' hranice$KOD_CZNUTS3, +#' fill = colors, +#' bty = "n") #' #' @export diff --git a/R/obce_body.R b/R/obce_body.R index 13cd1fc..57dc9b3 100644 --- a/R/obce_body.R +++ b/R/obce_body.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is <1 MB. #' #' @return `sf` data frame with 6.258 rows of 14 variables + geometry diff --git a/R/obce_polygony.R b/R/obce_polygony.R index 88f6b8f..87a5205 100644 --- a/R/obce_polygony.R +++ b/R/obce_polygony.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is 13.3 MB (so use with caution, and patience). #' #' @return `sf` data frame with 6.258 rows of 14 variables + geometry diff --git a/R/ok_to_proceed.R b/R/ok_to_proceed.R deleted file mode 100644 index 4780720..0000000 --- a/R/ok_to_proceed.R +++ /dev/null @@ -1,45 +0,0 @@ -#' Internal function - tests availability of internet resources -#' -#' @param remote_file resource to be tested -#' @keywords internal - -.ok_to_proceed <- function(remote_file) { - - # local files are OK to proceed by definiton - if (grepl("file:///", remote_file)) return(TRUE) - - # remote files require testing - try_head <- function(x, ...) { - tryCatch( - httr::HEAD(url = x, httr::timeout(10), ...), - error = function(e) conditionMessage(e), - warning = function(w) conditionMessage(w) - ) - } - - is_response <- function(x) { - class(x) == "response" - } - - network <- as.logical(Sys.getenv("NETWORK_UP", unset = TRUE)) # dummy variable to allow testing of network - - # First check internet connection - if (!curl::has_internet() | !network) { - message("No internet connection.") - return(FALSE) - } - # Then try for timeout problems - resp <- try_head(remote_file) - if (!is_response(resp)) { - message("Timeout reached; external data source likely broken.") - return(FALSE) - } - # Then stop if status > 400 - if (httr::http_error(resp)) { - message("Data source broken.") - return(FALSE) - } - - # safe to proceed - TRUE -} diff --git a/R/okresy.R b/R/okresy.R index 82e53ab..99c217c 100644 --- a/R/okresy.R +++ b/R/okresy.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size of high resolution shapefile 2.1 MB. #' #' @param resolution Should the function return high or low resolution shapefile? Allowed values are "high" (default) and "low". This parameter affects only the geometry column, all other fields remain the same. diff --git a/R/orp_polygony.R b/R/orp_polygony.R index 1c521e3..7ce4c3a 100644 --- a/R/orp_polygony.R +++ b/R/orp_polygony.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is 3.1 MB. #' #' @return `sf` data frame with 206 rows of 5 variables + geometry diff --git a/R/republika.R b/R/republika.R index f1f9763..a8b9471 100644 --- a/R/republika.R +++ b/R/republika.R @@ -4,6 +4,8 @@ #' #' Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). #' +#' The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on (in Czech only). +#' #' The data is current to June 2021. Downloaded size of high resolution shapefile is <1 MB. #' #' @param resolution Should the function return high or low resolution shapefile? Allowed values are "high" (default) and "low". This parameter affects only the geometry column, all other fields remain the same. diff --git a/R/revgeo.R b/R/revgeo.R index 3b8d2f2..bd7df39 100644 --- a/R/revgeo.R +++ b/R/revgeo.R @@ -36,6 +36,8 @@ #' pupek_brna <- st_centroid(brno) # calculate centroid #' #' adresa_pupku <- revgeo(pupek_brna)$revgeocoded # address of the center +#' +#' print(adresa_pupku) #' } #' @export diff --git a/R/silnice.R b/R/silnice.R index 0c9bd43..cb32aeb 100644 --- a/R/silnice.R +++ b/R/silnice.R @@ -9,7 +9,15 @@ #' @return `sf` data frame with 59.594 rows of 3 variables + geometry: #' #' \describe{ -#' \item{TRIDA}{Class of the road: highway = dálnice, speedway = rychlostní silnice, 1st class road = silnice I. třídy, 2nd class road = silnice II. třídy, 3rd class road = silnice III. třídy, other road = neevidovaná silnice} +#' \item{TRIDA}{Class of the road:} +#' \itemize{ +#' \item highway = dálnice, +#' \item speedway = rychlostní silnice, +#' \item 1st class road = silnice I. třídy, +#' \item 2nd class road = silnice II. třídy, +#' \item 3rd class road = silnice III. třídy, +#' \item other road = neevidovaná silnice +#' } #' \item{CISLO_SILNICE}{Local road code} #' \item{MEZINARODNI_OZNACENI}{International road code} #' } @@ -17,6 +25,7 @@ #' @source Mapový podklad – Data200, 2021 © Český úřad zeměměřický a katastrální. #' #' @export +#' @md silnice <- function() { result <- .downloader("Silnice-D200-2021-07.rds") diff --git a/R/vyskopis.R b/R/vyskopis.R index 3e8ef2a..3ac2296 100644 --- a/R/vyskopis.R +++ b/R/vyskopis.R @@ -1,8 +1,8 @@ #' Vyskopis #' -#' Terrain of the Czech Republic as a {terra} package object. +#' Terrain of the Czech Republic as a `terra` package object. #' -#' The function returns a raster file of either actual terrain (values are meters above sea level) or rayshaded relief.. +#' The function returns a raster file of either actual terrain (values are meters above sea level) or rayshaded relief. #' #' The raster is created from EU DEM 1.1 file by Copernicus Land Monitoring service. The original file has pixel resolution 25×25 meters, which is too detailed for purposes of the package and was downsampled by factor of 4. #' diff --git a/R/zip_codes.R b/R/zip_codes.R index 4342092..ec7ae6f 100644 --- a/R/zip_codes.R +++ b/R/zip_codes.R @@ -10,6 +10,8 @@ #' #' The data is current to February 2021 (last update was in January 2020). Downloaded size of high resolution shapefile is 45 MB, size of the low res object is 2 MB. #' +#' Raw version of the dataset is available for download for use in non-R setting on . +#' #' @param resolution Should the function return high or low resolution shapefile? Allowed values are "high" (default) and "low". This parameter affects only the geometry column, all other fields remain the same. #' #' @return `sf` data frame with 2 671 rows of 2 variables + geometry diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..e1d10b7 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: https://rczechia.jla-data.net +template: + bootstrap: 5 + diff --git a/data-raw/Dockerfile b/data-raw/Dockerfile index fd70e36..81942ab 100644 --- a/data-raw/Dockerfile +++ b/data-raw/Dockerfile @@ -72,7 +72,4 @@ RUN R -e "options(warn=2); install.packages('rlang', repos = 'https://packageman RUN R -e "options(warn=2); install.packages('terra', repos = 'https://packagemanager.rstudio.com/cran/2022-12-01')" # bleeding edge RCzechia, current CRAN (not really frozen in time, but under control) -RUN R -e "install.packages('RCzechia')" - - - +RUN R -e "install.packages('RCzechia')" \ No newline at end of file diff --git "a/data-raw/confirmation P\305\230FUK.pdf" "b/data-raw/confirmation P\305\230FUK.pdf" new file mode 100644 index 0000000..f4ac87c Binary files /dev/null and "b/data-raw/confirmation P\305\230FUK.pdf" differ diff --git a/data-raw/run_ozymandias.sh b/data-raw/run_ozymandias.sh index b90b1b1..8f15fde 100755 --- a/data-raw/run_ozymandias.sh +++ b/data-raw/run_ozymandias.sh @@ -4,7 +4,7 @@ docker run \ -v $(pwd)/../:/home/rstudio/ \ --rm \ -p 8787:8787 \ - ozymandias + ghcr.io/jlacko/rczechia:latest # clean up detritus... rm -rf ../.config diff --git a/man/KFME_grid.Rd b/man/KFME_grid.Rd index 5860a55..f2adf12 100644 --- a/man/KFME_grid.Rd +++ b/man/KFME_grid.Rd @@ -20,7 +20,9 @@ KFME_grid(resolution = "low") Function returning grid covering the Czech Republic according to the Kartierung der Flora Mitteleuropas methodology. } \details{ -The function returns a {sf} data frame of grid cells. Depending on the value of parameter \code{resolution} either low resolution (26×42 cells - default) with labels in 4 digit format (e.g. Hrčava = 6479) or high resolution (104×168 cells) with labels in 4 digit + 1 letter format (e.g Hrčava = 6479c). +The function returns a \code{sf} data frame of grid cells. Depending on the value of parameter \code{resolution} either low resolution (26×42 cells - default) with labels in 4 digit format (e.g. Hrčava = 6479) or high resolution (104×168 cells) with labels in 4 digit + 1 letter format (e.g Hrčava = 6479c). + +Raw version of the dataset is available for download for use in non-R setting on \url{https://rczechia.jla-data.net/kfme_czechia.gpkg}. } \examples{ library(ggplot2) diff --git a/man/casti.Rd b/man/casti.Rd index 20c4983..8c53174 100644 --- a/man/casti.Rd +++ b/man/casti.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/casti.R \name{casti} \alias{casti} -\title{City Parts} +\title{City Districts} \source{ © ČÚZK, 2021 \url{https://vdp.cuzk.cz/} } @@ -25,5 +25,7 @@ Function taking no parameters and returning data frame of districts of Prague an \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021. Downloaded size is 1.5 MB. } diff --git a/man/dot-downloader.Rd b/man/dot-downloader.Rd index cd54cc5..5b75847 100644 --- a/man/dot-downloader.Rd +++ b/man/dot-downloader.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/downloader.R +% Please edit documentation in R/internals.R \name{.downloader} \alias{.downloader} \title{Internal function - generic downloader, used to serve the rds files from S3} diff --git a/man/dot-ok_to_proceed.Rd b/man/dot-ok_to_proceed.Rd index e484915..e4f0092 100644 --- a/man/dot-ok_to_proceed.Rd +++ b/man/dot-ok_to_proceed.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ok_to_proceed.R +% Please edit documentation in R/internals.R \name{.ok_to_proceed} \alias{.ok_to_proceed} \title{Internal function - tests availability of internet resources} diff --git a/man/geomorfo.Rd b/man/geomorfo.Rd index 272b32c..613afd0 100644 --- a/man/geomorfo.Rd +++ b/man/geomorfo.Rd @@ -34,3 +34,15 @@ Due to package size constraints the data are stored externally (and a working in The data is current to 2014 (3rd edition of Demek & Mackovčin's \emph{Zeměpisný lexikon ČR. Hory a nížiny.}) Downloaded size is < 1 MB for any of the hierarchy levels. } +\examples{ + +\donttest{ +library(sf) + +soustavy <- RCzechia::geomorfo("subprovincie") + +plot(soustavy["kod"]) + +} + +} diff --git a/man/historie.Rd b/man/historie.Rd new file mode 100644 index 0000000..14725d3 --- /dev/null +++ b/man/historie.Rd @@ -0,0 +1,65 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/historie.R +\name{historie} +\alias{historie} +\title{Historical censuses of the Czech Republic} +\source{ +Urbánní a regionální laboratoř (UrRlab) působící na katedře sociální geografie a regionálního rozvoje Přírodovědecké fakulty Univerzity Karlovy v Praze \url{https://www.historickygis.cz/} +} +\usage{ +historie(era) +} +\arguments{ +\item{era}{a historical era of interest.} +} +\value{ +\code{sf} data frame with historical admin area names & census data + geometry; namely: + +\describe{ +\item{okresy_1921}{soudní okresy + census 1921; 328 rows / 92 columns + geometry} +\item{okresy_1930}{soudní okresy + census 1931; 330 rows / 90 columns + geometry} +\item{okresy_1947}{politické okresy + census 1947; 162 rows / 16 columns + geometry} +\item{okresy_1950}{správní okresy + census 1950; 193 rows / 57 columns + geometry} +\item{okresy_1961}{správní okresy + census 1960; 76 rows / 105 columns + geometry} +\item{okresy_1970}{správní okresy + census 1970; 76 rows / 144 columns + geometry} +\item{okresy_1980}{správní okresy + census 1980; 76 rows / 148 columns + geometry} +\item{okresy_1991}{správní okresy + census 1991; 76 rows / 155 columns + geometry} +\item{okresy_2001}{správní okresy + census 2001; 77 rows / 174 columns + geometry} +\item{okresy_2011}{správní okresy + census 2011; 77 rows / 176 columns + geometry} +\item{kraje_1950}{kraje + census 1950; 13 rows / 55 columns + geometry} +\item{kraje_1961}{kraje + census 1960; 8 rows / 103 columns + geometry} +\item{kraje_1970}{kraje + census 1970; 8 rows / 144 columns + geometry} +\item{kraje_1980}{kraje + census 1980; 8 rows / 146 columns + geometry} +\item{kraje_1991}{kraje + census 1991; 8 rows / 153 columns + geometry} +\item{kraje_2001}{kraje + census 2001; 14 rows / 172 columns + geometry} +\item{kraje_2011}{kraje + census 2011; 14 rows / 174 columns + geometry} +} + +Credits: +\enumerate{ +\item „Tento výstup vznikl v rámci řešení projektu číslo DF12P01OVV033 Zpřístupnění historických prostorových a statistických dat v prostředí GIS řešeného v rámci programu Aplikovaného výzkumu a vývoje národní a kulturní identity (NAKI), jehož poskytovatel je Ministerstvo kultury České republiky.“ +\item „JÍCHOVÁ, J., SOUKUP, M., NEMEŠKAL, J., OUŘEDNÍČEK, M., POSPÍŠILOVÁ, L., SVOBODA, P., ŠPAČKOVÁ, P. a kol. (2014): Geodatabáze historických statistických a prostorových dat Česka ze Sčítání lidu, domů a bytů 1921−2011. Urbánní a regionální laboratoř, Přírodovědecká fakulta Univerzity Karlovy v Praze, Praha.“ +} +} +\description{ +Function returning historical admin areas of the Czech Republic, together with relevant census data as specified by parameter \strong{era}. +} +\details{ +The census data structure is too complex to fully list here; most of the fields are self documenting (for Czech speakers) - and when in doubt please consult the original metadata at \url{https://cuni.maps.arcgis.com/home/item.html?id=c2f19cd1146747a9a8daf5b900e7747b}, or the original journal article at \url{https://doi.org/10.14712/23361980.2015.93}. + +Of notable interest is the 1930 census, which was the last before WWII - and thus the last one to include Czechoslovak citizens of German ethnicity. + +Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +} +\examples{ + +\donttest{ +library(sf) + +pre_war <- RCzechia::historie("okresy_1930") + +plot(pre_war[, 47], main = "Residents of German ethnicity") + +} + +} diff --git a/man/kraje.Rd b/man/kraje.Rd index 4180d39..a7ebe16 100644 --- a/man/kraje.Rd +++ b/man/kraje.Rd @@ -27,12 +27,25 @@ Function returning data frame of NUTS3 administrative units for the Czech Republ \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size of high resolution shapefile is <1 MB. } \examples{ library(sf) -hranice <- kraje("low") -plot(hranice, col = "white", max.plot = 1) +colors <- rainbow(14) # legend colors + +hranice <- RCzechia::kraje("low") + +plot(hranice["KOD_CZNUTS3"], + col = colors, + main = "Czech Regions", + xlim = st_bbox(hranice)[c(1, 3)] * c(1, 1.1)) + +legend("right", + hranice$KOD_CZNUTS3, + fill = colors, + bty = "n") } diff --git a/man/obce_body.Rd b/man/obce_body.Rd index 0a72c72..ef6b512 100644 --- a/man/obce_body.Rd +++ b/man/obce_body.Rd @@ -33,5 +33,7 @@ Function returning data frame of LAU2 administrative units for the Czech Republi \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is <1 MB. } diff --git a/man/obce_polygony.Rd b/man/obce_polygony.Rd index 94b9bc4..55650f6 100644 --- a/man/obce_polygony.Rd +++ b/man/obce_polygony.Rd @@ -33,6 +33,8 @@ Function returning data frame of LAU2 administrative units for the Czech Republi \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is 13.3 MB (so use with caution, and patience). } \examples{ diff --git a/man/okresy.Rd b/man/okresy.Rd index c55cc23..d3a6f79 100644 --- a/man/okresy.Rd +++ b/man/okresy.Rd @@ -30,6 +30,8 @@ Function returning data frame of LAU1 administrative units for the Czech Republi \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size of high resolution shapefile 2.1 MB. } \examples{ diff --git a/man/orp_polygony.Rd b/man/orp_polygony.Rd index 2b89fb8..3bd7116 100644 --- a/man/orp_polygony.Rd +++ b/man/orp_polygony.Rd @@ -26,5 +26,7 @@ Function returning data frame of municipalities with extended powers (obce s roz \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021 (i.e changes introduced by act 51/2020 Sb. are reflected). Downloaded size is 3.1 MB. } diff --git a/man/republika.Rd b/man/republika.Rd index e83f70e..e89a78f 100644 --- a/man/republika.Rd +++ b/man/republika.Rd @@ -21,6 +21,8 @@ Boundaries of the Czech Republic as \code{sf} polygon. \details{ Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). +The dataset is based on RUIAN data by the Czech cadastral office. If necessary you can download the most up to date raw dataset in VFR format (a special case of XML which is understood by GDAL) on \url{https://vdp.cuzk.cz/vdp/ruian/vymennyformat} (in Czech only). + The data is current to June 2021. Downloaded size of high resolution shapefile is <1 MB. } \examples{ diff --git a/man/revgeo.Rd b/man/revgeo.Rd index 6093836..f06a5a4 100644 --- a/man/revgeo.Rd +++ b/man/revgeo.Rd @@ -46,5 +46,7 @@ brno <- obce_polygony() \%>\% # shapefile of Brno pupek_brna <- st_centroid(brno) # calculate centroid adresa_pupku <- revgeo(pupek_brna)$revgeocoded # address of the center + +print(adresa_pupku) } } diff --git a/man/set_home.Rd b/man/set_home.Rd new file mode 100644 index 0000000..defb878 --- /dev/null +++ b/man/set_home.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{set_home} +\alias{set_home} +\title{Set the local cache directory} +\usage{ +set_home(path) +} +\arguments{ +\item{path}{file to be downloaded (or not...) from S3} +} +\value{ +TRUE for success and FALSE for failure; returned silently +} +\description{ +The function sets the environment variable RCZECHIA_HOME to be used as a local cache for RCzechia remote files; if unset tempdir() is used instead, with persistence for current session only. +} +\details{ +Note that when set (it is unset by default) the remote files will be cached to local file system and persist between R sessions, for good or bad. + +Also note that you can set the value of RCZECHIA_HOME environment variable directly, either via a \code{Sys.setenv()} call or via your \code{.Renviron} file. +} diff --git a/man/silnice.Rd b/man/silnice.Rd index 5d9bc94..2f2a5bf 100644 --- a/man/silnice.Rd +++ b/man/silnice.Rd @@ -13,7 +13,15 @@ silnice() \code{sf} data frame with 59.594 rows of 3 variables + geometry: \describe{ -\item{TRIDA}{Class of the road: highway = dálnice, speedway = rychlostní silnice, 1st class road = silnice I. třídy, 2nd class road = silnice II. třídy, 3rd class road = silnice III. třídy, other road = neevidovaná silnice} +\item{TRIDA}{Class of the road:} +\itemize{ +\item highway = dálnice, +\item speedway = rychlostní silnice, +\item 1st class road = silnice I. třídy, +\item 2nd class road = silnice II. třídy, +\item 3rd class road = silnice III. třídy, +\item other road = neevidovaná silnice +} \item{CISLO_SILNICE}{Local road code} \item{MEZINARODNI_OZNACENI}{International road code} } diff --git a/man/unset_home.Rd b/man/unset_home.Rd new file mode 100644 index 0000000..6e6299f --- /dev/null +++ b/man/unset_home.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{unset_home} +\alias{unset_home} +\title{Unset the local cache directory} +\usage{ +unset_home() +} +\value{ +TRUE for success and FALSE for failure; returned silently +} +\description{ +The function unsets the environment variable RCZECHIA_HOME, meaning tempdir() will be used in future function calls, and no persistent data will be stored locally. +} diff --git a/man/vyskopis.Rd b/man/vyskopis.Rd index fd3b187..5695c81 100644 --- a/man/vyskopis.Rd +++ b/man/vyskopis.Rd @@ -18,10 +18,10 @@ vyskopis(format = "rayshaded", cropped = TRUE) \code{terra} package SpatRaster } \description{ -Terrain of the Czech Republic as a {terra} package object. +Terrain of the Czech Republic as a \code{terra} package object. } \details{ -The function returns a raster file of either actual terrain (values are meters above sea level) or rayshaded relief.. +The function returns a raster file of either actual terrain (values are meters above sea level) or rayshaded relief. The raster is created from EU DEM 1.1 file by Copernicus Land Monitoring service. The original file has pixel resolution 25×25 meters, which is too detailed for purposes of the package and was downsampled by factor of 4. diff --git a/man/zip_codes.Rd b/man/zip_codes.Rd index ce5f6ec..7179be0 100644 --- a/man/zip_codes.Rd +++ b/man/zip_codes.Rd @@ -31,6 +31,8 @@ The geometry type is MULTIPOLYGON, as there are a number of non continuous areas Due to package size constraints the data are stored externally (and a working internet connection is required to use the package). The data is current to February 2021 (last update was in January 2020). Downloaded size of high resolution shapefile is 45 MB, size of the low res object is 2 MB. + +Raw version of the dataset is available for download for use in non-R setting on \url{https://rczechia.jla-data.net/zip_codes.gpkg}. } \examples{ \donttest{ diff --git a/tests/testthat/test-1-historie.R b/tests/testthat/test-1-historie.R new file mode 100644 index 0000000..8f01da2 --- /dev/null +++ b/tests/testthat/test-1-historie.R @@ -0,0 +1,80 @@ +library(dplyr) +library(httr) + + +test_that("historie platí", { + + skip_on_cran() + + eras <- c("okresy_1921", + "okresy_1930", + "okresy_1947", + "okresy_1950", + "okresy_1961", + "okresy_1970", + "okresy_1980", + "okresy_1991", + "okresy_2001", + "okresy_2011", + "kraje_1950", + "kraje_1961", + "kraje_1970", + "kraje_1980", + "kraje_1991", + "kraje_2001", + "kraje_2011") + + entities <- c("okresy_1921" = 328, + "okresy_1930" = 330, + "okresy_1947" = 163, + "okresy_1950" = 182, + "okresy_1961" = 76, + "okresy_1970" = 76, + "okresy_1980" = 76, + "okresy_1991" = 76, + "okresy_2001" = 77, + "okresy_2011" = 77, + "kraje_1950" = 13, + "kraje_1961" = 8, + "kraje_1970" = 8, + "kraje_1980" = 8, + "kraje_1991" = 8, + "kraje_2001" = 14, + "kraje_2011" = 14) + + + for (doba in eras) { + + Sys.setenv("NETWORK_UP" = FALSE) + expect_message(historie(doba), "internet") # zpráva o chybějícím internetu + Sys.setenv("NETWORK_UP" = TRUE) + + expect_true(is.data.frame(historie(doba))) + + expect_s3_class(historie(doba), "sf") + + expect_equal(nrow(historie(doba)), unname(entities[doba])) + + expect_equal(st_crs(historie(doba))$input, "EPSG:4326") + + expect_true(all(st_is_valid(historie(doba)))) + + # sloupece obsahují geometrii (ne geom nebo x) + expect_true("geometry" %in% colnames(historie(doba))) + + # území je pokryté + expect_equal(sum(st_area(historie(doba))), st_area(republika("high")), tolerance = 5/100) + + } + +}) + + +test_that("chyby zadání", { + + expect_error(geomorfo("bflm")) # neznámá úroveň + expect_error(geomorfo()) # povinný argument bez defaultu + +}) + + diff --git a/vignettes/vignette.Rmd b/vignettes/vignette.Rmd index 74a1941..adb5eff 100644 --- a/vignettes/vignette.Rmd +++ b/vignettes/vignette.Rmd @@ -7,7 +7,7 @@ output: toc: true self_contained: no vignette: > - %\VignetteIndexEntry{Solving real world issues with RCzechia} + %\VignetteIndexEntry{Solving Real World Issues With RCzechia} %\VignetteDepends{readxl} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}