# NOT RUN {
sf <- get_eurostat_geospatial(
output_class = "sf",
resolution = "60",
nuts_level = "all"
)
df <- get_eurostat_geospatial(
output_class = "df",
resolution = "20",
nuts_level = "0"
)
# }
# NOT RUN {
# }
# NOT RUN {
spdf <- get_eurostat_geospatial(
output_class = "spdf",
resolution = "10",
nuts_level = "3"
)
# }
# NOT RUN {
# }
# NOT RUN {
# -------------------------------------------------------------------
# Minimal example to demonstrate reason/effect of 'make_valid = TRUE'
# Spatial data set; rectangle spanning the entire globe with a constant value of 1L.
# Requires the R package sf.
library("sf")
d <- c(-180, -90, -180, 90, 180, 90, 180, -90, -180, -90)
poly <- st_polygon(list(matrix(d, ncol = 2, byrow = TRUE)))
data <- st_sf(data.frame(geom = st_sfc(poly), data = 1L),
crs = st_crs(4326)
)
# Causing an error: Self-intersection of some points of the geometry
NUTS2_A <- get_eurostat_geospatial("sf", 60,
nuts_level = 2, year = 2013,
crs = 4326, make_valid = FALSE
)
res <- tryCatch(st_interpolate_aw(data, NUTS2_A, extensive = FALSE),
error = function(e) e
)
print(res)
# Resolving the problem using
# make_valid = TRUE. 'extensive = FALSE' returns
# average over each area, thus resulting in a
# constant value of 1 for each geometry in NUTS2_B.
NUTS2_B <- get_eurostat_geospatial("sf", 60,
nuts_level = 2, year = 2013,
crs = 4326, make_valid = TRUE
)
res <- st_interpolate_aw(data, NUTS2_B, extensive = FALSE)
print(head(res))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab