x <- c(-1.992148, 43.311305, -1.958436, 43.32748) # En 4326
count <- 1000 # Numero maximo a retornar
verbose <- FALSEGipuzkoa
Gipuzkoa
Servicio en https://b5m.gipuzkoa.eus/web5000/es/servicios-inspire/edificios
Ejemplo de llamada
Parámetros mínimos de entrada
Producto mínimo viable
# El bbox necesitamos que esté en 25830
x_mod <- x
class(x_mod) <- "bbox"
x_mod <- sf::st_as_sfc(x_mod)
sf::st_crs(x_mod) <- sf::st_crs(4326)
x_poly_25830 <- sf::st_transform(x_mod, 25830)
bbox_q <- sf::st_bbox(x_poly_25830)
# Construimos la query
api_entry <- "https://b5m.gipuzkoa.eus/inspire/wfs/gipuzkoa_wfs_bu?"
query_params <- list(
version = "2.0.0",
request = "GetFeature",
service = "WFS",
typeNames = "bu-ext2d:Building",
count = count,
SRSname = "EPSG:25830",
BBOX = paste0(bbox_q, collapse = ",")
)
# Construye la query final
q_text <- paste0(names(query_params), "=", query_params, collapse = "&")
api_end <- paste0(api_entry, q_text)
# Output temporal
out_temp <- tempfile(fileext = ".gml")
download.file(api_end, out_temp, quiet = !verbose)Resultado
# Hay errores en el archivo!
x_sf <- suppressWarnings(sf::read_sf(out_temp, quiet = TRUE))
# Hay columnas anidadas que dan problemas, de las vamos a eliminar
# TODO: Profundizar
the_df <- sf::st_drop_geometry(x_sf)
the_geom <- sf::st_geometry(x_sf)
unn <- vapply(the_df, class, FUN.VALUE = character(1))
cols_are_list <- as.integer(which(unn == "list"))
the_final_df <- the_df[, -cols_are_list]
# The sf regenerated
x_sf <- sf::st_sf(the_final_df, geometry = the_geom)
x_sf <- sf::st_transform(x_sf, 25830)Comprobación
library(ggplot2)
identical(sf::st_crs(x_poly_25830), sf::st_crs(x_sf))
#> [1] TRUE
ggplot() +
geom_sf(data = x_poly_25830, aes(color = "BBOX"), fill = NA, linewidth = 2) +
geom_sf(data = x_sf, aes(fill = "API Result")) +
scale_colour_manual(values = "black") +
labs(
fill = "",
color = ""
)NO FUNCIONA!!!