install.packages("spanishoddata",
repos = c("https://e-kotov.r-universe.dev", "https://cloud.r-project.org"))
<- spanishoddata::spod_get_zones("gau", ver = 2) zones
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)
<- here("data/raw_data/v2/zonificacion/zonificacion_GAU/zonificacion_gaus.shp")
gau_boundaries_data_file <- here("data/raw_data/v2/zonificacion/zonificacion_GAU/nombres_gaus.csv") gau_names_file
Load the data and join the Large Urban Areas names to the boundaries.
<- read_sf(gau_boundaries_data_file)
gau_boundaries
<- read_delim(gau_names_file,
gau_names 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
<- !st_is_valid(gau_boundaries) gau_boundaries_invalid
Results
- Number of Invalid Geometries
sum(gau_boundaries_invalid)
[1] 3
- Names of Large Urban Areas with Invalid Geometries
::datatable(gau_boundaries[gau_boundaries_invalid,] |> st_drop_geometry()) DT
Links to the original files
source(here("R/901-download-helpers.R"))
<- load_latest_v2_xml()
files
# Filter relevant files
<- files |>
relevant_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))