Get sf
LINESTRING
or POINT
with the railways of Spain
Source: R/esp_get_railway.R
esp_get_railway.Rd
Loads a sf
LINESTRING
or POINT
object representing the
nodes and railway lines of Spain.
Usage
esp_get_railway(
year = Sys.Date(),
epsg = "4258",
cache = TRUE,
update_cache = FALSE,
cache_dir = NULL,
verbose = FALSE,
spatialtype = "line"
)
Source
IGN data via a custom CDN (see https://github.com/rOpenSpain/mapSpain/tree/sianedata).
Arguments
- year
Release year.
- epsg
projection of the map: 4-digit EPSG code. One of:
"4258"
: ETRS89."4326"
: WGS84."3035"
: ETRS89 / ETRS-LAEA."3857"
: Pseudo-Mercator.
- cache
A logical whether to do caching. Default is
TRUE
. See About caching.- update_cache
A logical whether to update cache. Default is
FALSE
. When set toTRUE
it would force a fresh download of the source file.- cache_dir
A path to a cache directory. See About caching.
- verbose
Logical, displays information. Useful for debugging, default is
FALSE
.- spatialtype
Spatial type of the output. Use
"line"
for extracting the railway as lines and"point"
for extracting stations.
Value
A sf
LINESTRING
or POINT
object.
About caching
You can set your cache_dir
with esp_set_cache_dir()
.
Sometimes cached files may be corrupt. On that case, try re-downloading
the data setting update_cache = TRUE
.
If you experience any problem on download, try to download the
corresponding .geojson file by any other method and save it on your
cache_dir
. Use the option verbose = TRUE
for debugging the API query.
See also
Other infrastructure:
esp_get_roads()
Examples
# \donttest{
provs <- esp_get_prov()
ccaa <- esp_get_ccaa()
# Railways
rails <- esp_get_railway()
# Stations
stations <- esp_get_railway(spatialtype = "point")
# Map
library(ggplot2)
ggplot(provs) +
geom_sf(fill = "grey99", color = "grey50") +
geom_sf(data = ccaa, fill = NA) +
geom_sf(
data = rails, aes(color = tipo),
show.legend = FALSE, linewidth = 1.5
) +
geom_sf(
data = stations,
color = "red", alpha = 0.5
) +
coord_sf(
xlim = c(-7.5, -2.5),
ylim = c(38, 41)
) +
scale_color_manual(values = hcl.colors(
length(unique(rails$tipo)), "viridis"
)) +
theme_minimal()
# }