esp_get_railway {mapSpain} | R Documentation |
Get sf
LINESTRING
or POINT
with the railways of Spain
Description
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"
)
Arguments
year |
Release year. |
epsg |
projection of the map: 4-digit EPSG code. One of:
|
cache |
A logical whether to do caching. Default is |
update_cache |
A logical whether to update cache. Default is |
cache_dir |
A path to a cache directory. See About caching. |
verbose |
Logical, displays information. Useful for debugging,
default is |
spatialtype |
Spatial type of the output. Use |
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.
Source
IGN data via a custom CDN (see https://github.com/rOpenSpain/mapSpain/tree/sianedata).
See Also
Other infrastructure:
esp_get_roads()
Examples
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()