Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Jun 10, 2024
1 parent ef00087 commit 700f468
Show file tree
Hide file tree
Showing 42 changed files with 286 additions and 509 deletions.
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ references:
email: [email protected]
orcid: https://orcid.org/0000-0002-4035-0289
year: '2024'
identifiers:
- type: url
value: https://curl.se/libcurl/
- type: software
title: ggplot2
abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics'
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VignetteBuilder:
Config/Needs/check: curl
Config/Needs/coverage: covr
Config/Needs/website: ragg, reactable, rnaturalearth, tidyverse,
ropenspain/rostemplate, ropensci/rnaturalearthhires, devtools
ropenspain/rostemplate, ropensci/rnaturalearthhires, devtools, remotes
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: © EuroGeographics for the administrative boundaries. Atlas
Expand Down
87 changes: 17 additions & 70 deletions R/esp_getTiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,46 +154,19 @@
#' autoplot(cartodb, maxcell = Inf) +
#' geom_sf(data = segovia, fill = NA, color = "black", linewidth = 1)
#' }
esp_getTiles <- function(x,
type = "IDErioja",
zoom = NULL,
zoommin = 0,
crop = TRUE,
res = 512,
bbox_expand = 0.05,
transparent = TRUE,
mask = FALSE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
options = NULL) {
# nocov start

if (!requireNamespace("slippymath", quietly = TRUE)) {
stop("slippymath package required for using this function")
}
if (!requireNamespace("terra", quietly = TRUE)) {
stop("terra package required for using this function")
}
if (!requireNamespace("png", quietly = TRUE)) {
stop("png package required for using this function")
}
# nocov end
esp_getTiles <- function(x, type = "IDErioja", zoom = NULL, zoommin = 0,

Check notice

Code scanning / lintr

Functions should have cyclomatic complexity of less than 15, this has 37. Note

Functions should have cyclomatic complexity of less than 15, this has 37.

Check notice

Code scanning / lintr

Variable and function name style should match snake_case or symbols. Note

Variable and function name style should match snake_case or symbols.
crop = TRUE, res = 512, bbox_expand = 0.05,
transparent = TRUE, mask = FALSE, update_cache = FALSE,
cache_dir = NULL, verbose = FALSE, options = NULL) {
# Only sf and sfc objects allowed

if (!inherits(x, "sf") && !inherits(x, "sfc")) {
stop(
"Only sf and sfc ",
"objects allowed"
)
stop("Only sf and sfc objects allowed")
}

# If sfc convert to sf
if (inherits(x, "sfc")) {
x <- sf::st_as_sf(
data.frame(x = 1),
x
)
x <- sf::st_as_sf(data.frame(x = 1), x)
}


Expand Down Expand Up @@ -288,8 +261,6 @@ esp_getTiles <- function(x,
options <- options[ig]
}



url_pieces <- modifyList(url_pieces, options)
# Create new cache dir

Expand Down Expand Up @@ -333,39 +304,22 @@ esp_getTiles <- function(x,
newbbox <- esp_hlp_get_bbox(x, bbox_expand, typeprov)

if (typeprov == "WMS") {
rout <-
getwms(
newbbox,
url_pieces,
update_cache,
cache_dir,
verbose,
res,
transparent
)
rout <- getwms(
newbbox, url_pieces, update_cache, cache_dir, verbose,
res, transparent
)
} else {
rout <-
getwmts(
newbbox,
type,
url_pieces,
update_cache,
cache_dir,
verbose,
zoom,
zoommin,
transparent,
extra_opts
)
rout <- getwmts(
newbbox, type, url_pieces, update_cache, cache_dir, verbose,
zoom, zoommin, transparent, extra_opts
)
}

# Regenerate
# Display attributions

if (verbose && !is.null(attr)) {
message(
"\nData and map tiles sources:\n", attr
)
message("\nData and map tiles sources:\n", attr)
}

x <- xinit
Expand All @@ -375,10 +329,7 @@ esp_getTiles <- function(x,
if (!sf::st_crs(x) == sf::st_crs(rout)) {
# Sometimes it gets an error

rout_end <- try(terra::project(
rout,
terra::crs(x_terra)
), silent = TRUE)
rout_end <- try(terra::project(rout, terra::crs(x_terra)), silent = TRUE)

if (inherits(rout_end, "try-error")) {
if (verbose) message("Tile not reprojected.")
Expand All @@ -388,11 +339,7 @@ esp_getTiles <- function(x,
}
}

rout <- terra::clamp(rout,
lower = 0,
upper = 255,
values = TRUE
)
rout <- terra::clamp(rout, lower = 0, upper = 255, values = TRUE)


# crop management
Expand Down
4 changes: 2 additions & 2 deletions R/esp_get_capimun.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#' 2 or 3), ISO codes (corresponding to level 2 or 3) or `cpro`. See
#' [esp_codelist]
#'
#' When calling a higher level (province, CCAA or NUTS1) ,
#' all the municipalities of that level would be added.
#' When calling a higher level (province, CCAA or NUTS1), all the municipalities
#' of that level would be added.
#'
#' @export
#'
Expand Down
2 changes: 1 addition & 1 deletion R/esp_get_comarca.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or
#' "cpro" (see [esp_codelist]).
#'
#' When calling a superior level (Province, Autonomous Community or NUTS1) ,
#' When calling a higher level (Province, Autonomous Community or NUTS1),
#' all the comarcas of that level would be added.
#'
#' ## Legal Notice
Expand Down
4 changes: 2 additions & 2 deletions R/esp_get_munic.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#' 3), ISO codes (corresponding to level 2 or 3) or `"cpro"`
#' (see [esp_codelist]).
#'
#' When calling a superior level (Province, Autonomous Community or NUTS1) ,
#' all the municipalities of that level would be added.
#' When calling a higher level (Province, Autonomous Community or NUTS1), all
#' the municipalities of that level would be added.
#'
#' @examples
#' \donttest{
Expand Down
80 changes: 29 additions & 51 deletions R/esp_get_prov.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Get Provinces of Spain as [`sf`][sf::st_sf] polygons and points
#' Get Provinces of Spain as [`sf`][sf::st_sf] `POLYGON` or `POINT`
#'
#' @description
#' Returns
#' [provinces of Spain](https://en.wikipedia.org/wiki/Provinces_of_Spain)
#' as polygons and points at a specified scale.
#' as `POLYGON` or `POINT` at a specified scale.
#'
#' * [esp_get_prov()] uses GISCO (Eurostat) as source. Please use
#' - [esp_get_prov()] uses GISCO (Eurostat) as source. Please use
#' [giscoR::gisco_attributions()]
#'
#'
Expand All @@ -19,8 +19,8 @@
#'
#' @export
#'
#' @param prov A vector of names and/or codes for provinces
#' or `NULL` to get all the provinces. See **Details**.
#' @param prov A vector of names and/or codes for provinces or `NULL` to get all
#' the provinces. See **Details**.
#'
#' @inheritDotParams esp_get_nuts -nuts_level -region
#'
Expand All @@ -31,8 +31,8 @@
#'
#' Ceuta and Melilla are considered as provinces on this dataset.
#'
#' When calling a superior level (Autonomous Community or NUTS1) ,
#' all the provinces of that level would be added.
#' When calling a higher level (Autonomous Community or NUTS1), all the
#' provinces of that level would be added.
#'
#' @inheritSection esp_get_nuts About caching
#'
Expand All @@ -50,14 +50,10 @@
#' \donttest{
#' # Random Provinces
#'
#' Random <-
#' esp_get_prov(prov = c(
#' "Zamora",
#' "Palencia",
#' "ES-GR",
#' "ES521",
#' "01"
#' ))
#' Random <- esp_get_prov(prov = c(
#' "Zamora", "Palencia", "ES-GR",
#' "ES521", "01"
#' ))
#'
#'
#' ggplot(Random) +
Expand Down Expand Up @@ -223,14 +219,10 @@ esp_get_prov <- function(prov = NULL, moveCAN = TRUE, ...) {
"nuts1.name"
)])
data_sf <- merge(data_sf, dfnuts, all.x = TRUE)
data_sf <-
data_sf[, c(
colnames(df),
"nuts2.code",
"nuts2.name",
"nuts1.code",
"nuts1.name"
)]
data_sf <- data_sf[, c(
colnames(df), "nuts2.code", "nuts2.name",
"nuts1.code", "nuts1.name"
)]

# Order
data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ]
Expand All @@ -248,9 +240,9 @@ esp_get_prov <- function(prov = NULL, moveCAN = TRUE, ...) {
#'
#'
#' @description
#' * [esp_get_prov_siane()] uses CartoBase ANE as source, provided by Instituto
#' Geografico Nacional (IGN), <http://www.ign.es/web/ign/portal>. Years
#' available are 2005 up to today.
#' - [esp_get_prov_siane()] uses CartoBase ANE as source, provided by Instituto
#' Geografico Nacional (IGN), <http://www.ign.es/web/ign/portal>. Years
#' available are 2005 up to today.
#'
#' @source
#' IGN data via a custom CDN (see
Expand All @@ -259,23 +251,18 @@ esp_get_prov <- function(prov = NULL, moveCAN = TRUE, ...) {
#' @export
#'
#' @param year Release year. See [esp_get_nuts()] for [esp_get_prov()] and
#' **Details** for [esp_get_prov_siane()]
#' **Details** for [esp_get_prov_siane()].
#'
#' @inheritParams esp_get_ccaa
#'
#' @details
#' On [esp_get_prov_siane()], `year` could be passed as a single year ("YYYY"
#' format, as end of year) or as a specific date ("YYYY-MM-DD" format).
#' Historical information starts as of 2005.
esp_get_prov_siane <- function(prov = NULL,
year = Sys.Date(),
epsg = "4258",
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
resolution = "3",
moveCAN = TRUE,
esp_get_prov_siane <- function(prov = NULL, year = Sys.Date(), epsg = "4258",
cache = TRUE, update_cache = FALSE,
cache_dir = NULL, verbose = FALSE,
resolution = "3", moveCAN = TRUE,

Check notice

Code scanning / lintr

Variable and function name style should match snake_case or symbols. Note

Variable and function name style should match snake_case or symbols.
rawcols = FALSE) {
init_epsg <- as.character(epsg)
year <- as.character(year)
Expand All @@ -287,13 +274,8 @@ esp_get_prov_siane <- function(prov = NULL,

# Get Data from SIANE
data_sf <- esp_hlp_get_siane(
"prov",
resolution,
cache,
cache_dir,
update_cache,
verbose,
year
"prov", resolution, cache, cache_dir,
update_cache, verbose, year
)


Expand Down Expand Up @@ -327,14 +309,10 @@ esp_get_prov_siane <- function(prov = NULL,

# Paste nuts2
dfnuts <- mapSpain::esp_codelist
dfnuts <-
unique(dfnuts[, c(
"cpro",
"nuts2.code",
"nuts2.name",
"nuts1.code",
"nuts1.name"
)])
dfnuts <- unique(dfnuts[, c(
"cpro", "nuts2.code", "nuts2.name", "nuts1.code",
"nuts1.name"
)])
data_sf <- merge(data_sf, dfnuts, all.x = TRUE)


Expand Down
24 changes: 8 additions & 16 deletions R/esp_get_railway.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#' Get [`sf`][sf::st_sf] lines and points with the railways of Spain
#' Get [`sf`][sf::st_sf] `LINESTRING` or `POINT` with the railways of Spain
#'
#' @description
#' Loads a [`sf`][sf::st_sf] lines or point object representing the nodes and
#' railway lines of Spain.
#' Loads a [`sf`][sf::st_sf] `LINESTRING` or `POINT` object representing the
#' nodes and railway lines of Spain.
#'
#' @family infrastructure
#'
#' @return A [`sf`][sf::st_sf] line or point object.
#' @return A [`sf`][sf::st_sf] `LINESTRING` or `POINT` object.
#'
#' @source IGN data via a custom CDN (see
#' <https://github.com/rOpenSpain/mapSpain/tree/sianedata>).
Expand Down Expand Up @@ -59,13 +59,9 @@
#' )) +
#' theme_minimal()
#' }
esp_get_railway <- function(year = Sys.Date(),
epsg = "4258",
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
spatialtype = "line") {
esp_get_railway <- function(year = Sys.Date(), epsg = "4258", cache = TRUE,
update_cache = FALSE, cache_dir = NULL,
verbose = FALSE, spatialtype = "line") {
init_epsg <- as.character(epsg)
year <- as.character(year)

Expand All @@ -88,11 +84,7 @@ esp_get_railway <- function(year = Sys.Date(),
type <- paste0("ffcc", spatialtype)


data_sf <- esp_hlp_get_siane(type,
"3",
cache,
cache_dir,
update_cache,
data_sf <- esp_hlp_get_siane(type, "3", cache, cache_dir, update_cache,
verbose,
year = Sys.Date()
)
Expand Down
Loading

0 comments on commit 700f468

Please sign in to comment.