Skip to content

Commit

Permalink
Prepare for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Feb 13, 2023
1 parent 382597c commit dbb48d2
Show file tree
Hide file tree
Showing 26 changed files with 2,011 additions and 2,005 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/cran-status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ jobs:
issue-assignees: "dieghernan"
# Create an issue if one or more of the following
# statuses are reported on the check report.
status-types: "WARNING,ERROR"

statuses: "WARNING,ERROR"
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message: 'To cite package "giscoR" in publications use:'
type: software
license: GPL-3.0-only
title: 'giscoR: Download Map Data from GISCO API - Eurostat'
version: 0.3.2.9000
version: 0.3.3
doi: 10.5281/zenodo.4317946
abstract: Tools to download data from the GISCO (Geographic Information System of
the Commission) Eurostat database <https://ec.europa.eu/eurostat/web/gisco>. Global
Expand All @@ -31,7 +31,7 @@ preferred-citation:
affiliation: rOpenGov
doi: 10.5281/zenodo.4317946
year: '2023'
version: 0.3.2.9000
version: 0.3.3
url: https://ropengov.github.io/giscoR/
abstract: Tools to download data from the GISCO (Geographic Information System of
the Commission) Eurostat database <https://ec.europa.eu/eurostat/web/gisco>. Global
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: giscoR
Title: Download Map Data from GISCO API - Eurostat
Version: 0.3.2.9000
Version: 0.3.3
Authors@R: c(
person("Diego", "Hernangómez", , "diego.hernangomezherrero@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8457-4658", affiliation = "rOpenGov")),
Expand Down
20 changes: 12 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# giscoR (development version)

- Fix broken urls on
`gisco_get_healthcare()` (#51).
# giscoR 0.3.3

- Fix broken urls on `gisco_get_healthcare()` (#51).

# giscoR 0.3.2

Expand All @@ -26,9 +24,14 @@

# giscoR 0.3.0

- Now **giscoR** is part of [rOpenGov](https://ropengov.org/). Repo has been transferred.
- Caching improvements: new function `gisco_set_cache_dir()` based on `rappdirs::user_cache_dir()`. Now the `cache_dir` path is stored and it is not necessary to set it up again on a new session. Also added `gisco_clear_cache()`.
- Fix an error when `cache = FALSE`. Now files are loaded instead throwing an error.
- Now **giscoR** is part of [rOpenGov](https://ropengov.org/). Repo has been
transferred.
- Caching improvements: new function `gisco_set_cache_dir()` based on
`rappdirs::user_cache_dir()`. Now the `cache_dir` path is stored and it is
not necessary to set it up again on a new session. Also added
`gisco_clear_cache()`.
- Fix an error when `cache = FALSE`. Now files are loaded instead throwing an
error.
- New tests with `testthat`.
- Update on docs. New examples
- Refactor documents and codes for the previous `gisco_get` doc.
Expand Down Expand Up @@ -84,7 +87,8 @@
- `gisco_get_ports()`
- `gisco_get_units()`

- Now `gisco_get_countries()` and `gisco_get_nuts()` uses `gisco_get_units()` for individual files, making the call much faster.
- Now `gisco_get_countries()` and `gisco_get_nuts()` uses `gisco_get_units()`
for individual files, making the call much faster.

# giscoR 0.1.1

Expand Down
312 changes: 156 additions & 156 deletions R/gisco_bulk_download.R
Original file line number Diff line number Diff line change
@@ -1,156 +1,156 @@
#' Bulk download from GISCO API
#'
#' @concept political
#'
#' @family political
#'
#' @description
#' Downloads zipped data from GISCO and extract them on the `cache_dir` folder.
#'
#' @return Silent function.
#'
#' @param year Release year of the file. See Details
#'
#' @param id_giscoR Type of dataset to be downloaded. Values supported are:
#' * "coastallines"
#' * "communes"
#' * "countries"
#' * "lau"
#' * "nuts"
#' * "urban_audit"
#'
#' @inheritParams gisco_get_countries
#'
#' @inheritSection gisco_get_countries About caching
#'
#' @param ext Extension of the file(s) to be downloaded. Formats available are
#' "geojson", "shp", "svg", "json", "gdb". See **Details**.
#'
#' @param recursive Tries to unzip recursively the zip files (if any) included
#' in the initial bulk download (case of `ext = "shp"`).
#'
#' @details
#'
#' See the years available in the corresponding functions:
#' * [gisco_get_coastallines()]
#' * [gisco_get_communes()]
#' * [gisco_get_countries()]
#' * [gisco_get_lau()]
#' * [gisco_get_nuts()]
#' * [gisco_get_urban_audit()]
#'
#'
#' The usual extension used across **giscoR** is "geojson",
#' however other formats are already available on GISCO.
#'
#'
#' @source <https://gisco-services.ec.europa.eu/distribution/v2/>
#'
#'
#' @examples
#' \dontrun{
#'
#' # Countries 2016 - It would take some time
#' gisco_bulk_download(id_giscoR = "countries", resolution = "60")
#' }
#' @export
gisco_bulk_download <- function(id_giscoR = "countries",
year = "2016",
cache_dir = NULL,
update_cache = FALSE,
verbose = FALSE,
resolution = "10",
ext = "geojson",
recursive = TRUE) {
valid <- c(
"coastallines",
"communes",
"countries",
"lau",
"nuts",
"urban_audit"
)
alias <-
c("coastline", "communes", "countries", "lau", "nuts", "urau")

if (!(id_giscoR %in% valid)) {
stop(
"id_giscoR values should be one of ",
paste0("'", sort(valid), "'", collapse = ",")
)
}

availext <- c("geojson", "shp", "svg", "json", "gdb")
if (!(ext %in% availext)) {
stop("ext should be one of ", paste0(availext, collapse = ", "))
}

# Standard parameters for the call
year <- as.character(year)
epsg <- "4326"
spatialtype <- "RG"
level <- "all"
if (id_giscoR == "urban_audit" & year < "2014") {
level <- "CITY"
}

routes <- gsc_api_url(
id_giscoR,
year,
epsg,
resolution,
spatialtype,
"geojson",
nuts_level = "all",
level = level,
verbose = verbose
)

api_entry <- unlist(strsplit(routes, "/geojson/"))[1]
remain <- unlist(strsplit(routes, "/geojson/"))[2]

api_entry <- file.path(api_entry, "download")
getalias <- alias[valid == id_giscoR]

# Clean names
remain2 <- gsub(spatialtype, "", remain)
remain2 <- gsub(epsg, "", remain2)
remain2 <- gsub(year, "", remain2)
remain2 <- gsub(".geojson", "", remain2)
remain2 <- gsub(level, "", remain2)
remain2 <- (unlist(strsplit(remain2, "_")))[-1]
remain2 <- tolower(paste0(remain2, collapse = ""))

# Create url
zipname <- paste0(
"ref-",
getalias,
"-",
year,
"-",
remain2,
".",
ext,
".zip"
)
url <- file.path(api_entry, zipname)


destfile <- gsc_api_cache(
url,
zipname, cache_dir, update_cache,
verbose
)

# Clean cache dir name for extracting
unzip_dir <- gsub(paste0("/", zipname), "", destfile)

# Unzip
gsc_unzip(
destfile,
unzip_dir, ext,
recursive,
verbose,
update_cache
)
}
#' Bulk download from GISCO API
#'
#' @concept political
#'
#' @family political
#'
#' @description
#' Downloads zipped data from GISCO and extract them on the `cache_dir` folder.
#'
#' @return Silent function.
#'
#' @param year Release year of the file. See Details
#'
#' @param id_giscoR Type of dataset to be downloaded. Values supported are:
#' * "coastallines"
#' * "communes"
#' * "countries"
#' * "lau"
#' * "nuts"
#' * "urban_audit"
#'
#' @inheritParams gisco_get_countries
#'
#' @inheritSection gisco_get_countries About caching
#'
#' @param ext Extension of the file(s) to be downloaded. Formats available are
#' "geojson", "shp", "svg", "json", "gdb". See **Details**.
#'
#' @param recursive Tries to unzip recursively the zip files (if any) included
#' in the initial bulk download (case of `ext = "shp"`).
#'
#' @details
#'
#' See the years available in the corresponding functions:
#' * [gisco_get_coastallines()]
#' * [gisco_get_communes()]
#' * [gisco_get_countries()]
#' * [gisco_get_lau()]
#' * [gisco_get_nuts()]
#' * [gisco_get_urban_audit()]
#'
#'
#' The usual extension used across **giscoR** is "geojson",
#' however other formats are already available on GISCO.
#'
#'
#' @source <https://gisco-services.ec.europa.eu/distribution/v2/>
#'
#'
#' @examples
#' \dontrun{
#'
#' # Countries 2016 - It would take some time
#' gisco_bulk_download(id_giscoR = "countries", resolution = "60")
#' }
#' @export
gisco_bulk_download <- function(id_giscoR = "countries",
year = "2016",
cache_dir = NULL,
update_cache = FALSE,
verbose = FALSE,
resolution = "10",
ext = "geojson",
recursive = TRUE) {
valid <- c(
"coastallines",
"communes",
"countries",
"lau",
"nuts",
"urban_audit"
)
alias <-
c("coastline", "communes", "countries", "lau", "nuts", "urau")

if (!(id_giscoR %in% valid)) {
stop(
"id_giscoR values should be one of ",
paste0("'", sort(valid), "'", collapse = ",")
)
}

availext <- c("geojson", "shp", "svg", "json", "gdb")
if (!(ext %in% availext)) {
stop("ext should be one of ", paste0(availext, collapse = ", "))
}

# Standard parameters for the call
year <- as.character(year)
epsg <- "4326"
spatialtype <- "RG"
level <- "all"
if (id_giscoR == "urban_audit" && year < "2014") {
level <- "CITY"
}

routes <- gsc_api_url(
id_giscoR,
year,
epsg,
resolution,
spatialtype,
"geojson",
nuts_level = "all",
level = level,
verbose = verbose
)

api_entry <- unlist(strsplit(routes, "/geojson/"))[1]
remain <- unlist(strsplit(routes, "/geojson/"))[2]

api_entry <- file.path(api_entry, "download")
getalias <- alias[valid == id_giscoR]

# Clean names
remain2 <- gsub(spatialtype, "", remain)
remain2 <- gsub(epsg, "", remain2)
remain2 <- gsub(year, "", remain2)
remain2 <- gsub(".geojson", "", remain2)
remain2 <- gsub(level, "", remain2)
remain2 <- (unlist(strsplit(remain2, "_")))[-1]
remain2 <- tolower(paste0(remain2, collapse = ""))

# Create url
zipname <- paste0(
"ref-",
getalias,
"-",
year,
"-",
remain2,
".",
ext,
".zip"
)
url <- file.path(api_entry, zipname)


destfile <- gsc_api_cache(
url,
zipname, cache_dir, update_cache,
verbose
)

# Clean cache dir name for extracting
unzip_dir <- gsub(paste0("/", zipname), "", destfile)

# Unzip
gsc_unzip(
destfile,
unzip_dir, ext,
recursive,
verbose,
update_cache
)
}
Loading

0 comments on commit dbb48d2

Please sign in to comment.