diff --git a/R/get_eurostat_geospatial.R b/R/get_eurostat_geospatial.R index 281a3b35..37a2a0db 100755 --- a/R/get_eurostat_geospatial.R +++ b/R/get_eurostat_geospatial.R @@ -1,4 +1,4 @@ -#' @title Download Geospatial Data from GISGO +#' @title Download Geospatial Data from GISCO #' @description Downloads either a simple features (sf), SpatialPolygonDataFrame or a #' data_frame preprocessed using #' \code{broom::tidy()}. @@ -14,7 +14,7 @@ #' @param nuts_level Level of NUTS classification of the geospatial data. One of #' "0", "1", "2", "3" or "all" (mimics the original behaviour) #' @param year NUTS release year. One of -#' "2003", "2006", "2010", "2013" or "2016" +#' "2003", "2006", "2010", "2013", "2016" or "2021" #' @param cache a logical whether to do caching. Default is \code{TRUE}. Affects #' only queries from the bulk download facility. #' @param update_cache a locigal whether to update cache. Can be set also with @@ -24,6 +24,12 @@ #' 'eurostat' directory in the temporary directory from #' \code{\link{tempdir}}. Directory can also be set with #' \code{option} eurostat_cache_dir. +#' @param crs projection of the map: 4-digit \href{http://spatialreference.org/ref/epsg/}{EPSG code}. One of: +#' \itemize{ +#' \item "4326" - WGS84 +#' \item "3035" - ETRS89 / ETRS-LAEA +#' \item "3857" - Pseudo-Mercator +#' } #' @export #' @details The data source URL is \url{http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units}. #' @author Markus Kainu @@ -37,7 +43,7 @@ get_eurostat_geospatial <- function(output_class="sf", resolution="60", nuts_level = "all", year = "2016", cache = TRUE, update_cache = FALSE, - cache_dir = NULL){ + cache_dir = NULL, crs = "4326"){ # Check if you have access to ec.europe.eu. if (!check_access_to_data()){ message("You have no access to ec.europe.eu. @@ -66,13 +72,19 @@ Please check your connection and/or review your proxy settings") # Check year is of correct format year <- as.character(year) - if (!as.numeric(year) %in% c(2003, 2006, 2010, 2013, 2016)) { - stop("Year should be one of 2003, 2006, 2010, 2013 or 2016") + if (!as.numeric(year) %in% c(2003, 2006, 2010, 2013, 2016, 2021)) { + stop("Year should be one of 2003, 2006, 2010, 2013, 2016 or 2021") } if (as.numeric(year) == 2003 & as.numeric(resolution) == 60) { stop("NUTS 2003 is not provided at 1:60 million resolution. Try 1:1 million, 1:3 million, 1:10 million or 1:20 million") } + + # Check crs is of correct format + crs <- as.character(crs) + if (!as.numeric(crs) %in% c(4326, 3035, 3857)) { + stop("crs should be one of 4326, 3035 or 3857") + } # message(" # COPYRIGHT NOTICE @@ -101,7 +113,7 @@ Please check your connection and/or review your proxy settings") # information regarding their licence agreements. # ") - if (resolution == "60" && year == 2016){ + if (resolution == "60" && year == 2016 && crs == "4326"){ if (nuts_level %in% c("all")){ shp <- eurostat_geodata_60_2016 @@ -157,7 +169,7 @@ Please check your connection and/or review your proxy settings") if (!cache || update_cache || !file.exists(cache_file)){ if (nuts_level %in% c("0","all")){ - url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_0.geojson") + url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_",crs,"_LEVL_0.geojson") resp <- RETRY("GET", url, terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) @@ -167,7 +179,7 @@ Please check your connection and/or review your proxy settings") } } if (nuts_level %in% c("1","all")){ - url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_1.geojson") + url <- paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_",crs,"_LEVL_1.geojson") resp <- RETRY("GET", url, terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) @@ -177,7 +189,7 @@ Please check your connection and/or review your proxy settings") } } if (nuts_level %in% c("2","all")){ - resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_2.geojson"), terminate_on = c(404)) + resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_",crs,"_LEVL_2.geojson"), terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { @@ -186,7 +198,7 @@ Please check your connection and/or review your proxy settings") } } if (nuts_level %in% c("3","all")){ - resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_4326_LEVL_3.geojson"), terminate_on = c(404)) + resp <- RETRY("GET", paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v2/nuts/geojson/NUTS_RG_",resolution,"M_",year,"_",crs,"_LEVL_3.geojson"), terminate_on = c(404)) if (httr::http_error(resp)) { stop(paste("The requested url cannot be found within the get_eurostat_geospatial function:", url)) } else { @@ -251,7 +263,7 @@ Please check your connection and/or review your proxy settings") } } - if (resolution == "60" & year == 2016){ + if (resolution == "60" & year == 2016 & crs == "4326"){ if (output_class == "sf") message("sf at resolution 1:60 read from local file") if (output_class == "df") message("data_frame at resolution 1:60 read from local file") if (output_class == "spdf") message("SpatialPolygonDataFrame at resolution 1:60 read from local file") diff --git a/man/get_eurostat_geospatial.Rd b/man/get_eurostat_geospatial.Rd index 09c9aea3..8ea081e7 100755 --- a/man/get_eurostat_geospatial.Rd +++ b/man/get_eurostat_geospatial.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_eurostat_geospatial.R \name{get_eurostat_geospatial} \alias{get_eurostat_geospatial} -\title{Download Geospatial Data from GISGO} +\title{Download Geospatial Data from GISCO} \usage{ get_eurostat_geospatial( output_class = "sf", @@ -11,7 +11,8 @@ get_eurostat_geospatial( year = "2016", cache = TRUE, update_cache = FALSE, - cache_dir = NULL + cache_dir = NULL, + crs = "4326" ) } \arguments{ @@ -30,7 +31,7 @@ either \code{sf} \code{simple features}, \code{df} (\code{data_frame}) or "0", "1", "2", "3" or "all" (mimics the original behaviour)} \item{year}{NUTS release year. One of -"2003", "2006", "2010", "2013" or "2016"} +"2003", "2006", "2010", "2013", "2016" or "2021"} \item{cache}{a logical whether to do caching. Default is \code{TRUE}. Affects only queries from the bulk download facility.} @@ -43,6 +44,13 @@ The \code{NULL} (default) uses and creates 'eurostat' directory in the temporary directory from \code{\link{tempdir}}. Directory can also be set with \code{option} eurostat_cache_dir.} + +\item{crs}{projection of the map: 4-digit \href{http://spatialreference.org/ref/epsg/}{EPSG code}. One of: +\itemize{ +\item "4326" - WGS84 +\item "3035" - ETRS89 / ETRS-LAEA +\item "3857" - Pseudo-Mercator +}} } \value{ a sf, data_frame or SpatialPolygonDataFrame.