install.packages("spanishoddata",
repos = c("https://e-kotov.r-universe.dev", "https://cloud.r-project.org"))
zones <- spanishoddata::spod_get_zones("gau", ver = 2)Invalid Geometries in Large Urban Areas Boundaries
spatial data
geometry
importance: medium
Status: ✅ resolved
Importance: 2 - medium
Summary: There are 3 invalid geometries in the Large Urban Areas boundaries dataset.
Expected Results: The dataset should not contain any invalid geometries.
Resolution: resolved with https://github.com/Robinlovelace/spanishoddata/pull/25 in {spanishoddata} R package.
To get valid spatial data, use spanishoddata::spod_get_zones()
Steps to Reproduce
- Load Data
Load libraries and define data files.
library(tidyverse)
library(sf)
library(here)
library(DT)
gau_boundaries_data_file <- here("data/raw_data/v2/zonificacion/zonificacion_GAU/zonificacion_gaus.shp")
gau_names_file <- here("data/raw_data/v2/zonificacion/zonificacion_GAU/nombres_gaus.csv")Load the data and join the Large Urban Areas names to the boundaries.
gau_boundaries <- read_sf(gau_boundaries_data_file)
gau_names <- read_delim(gau_names_file,
delim = "|", show_col_types = FALSE, name_repair = "unique_quiet")
gau_boundaries <- gau_boundaries |>
left_join(gau_names |> select(ID, name), by = c("ID"))- Identify Invalid Geometries
gau_boundaries_invalid <- !st_is_valid(gau_boundaries)Results
- Number of Invalid Geometries
sum(gau_boundaries_invalid)[1] 3
- Names of Large Urban Areas with Invalid Geometries
DT::datatable(gau_boundaries[gau_boundaries_invalid,] |> st_drop_geometry())Links to the original files
source(here("R/901-download-helpers.R"))
files <- load_latest_v2_xml()
# Filter relevant files
relevant_files <- files |>
filter(basename(local_path) %in% basename(c(gau_boundaries_data_file, gau_names_file)) )
# Create HTML links
relevant_files <- relevant_files |>
mutate(target_url = paste0("<a href='", target_url, "' target='_blank'>", target_url, "</a>"))
# Render the DT table with links
datatable(relevant_files, escape = FALSE, options = list(pageLength = 5))