Invalid Geometries in Large Urban Areas Boundaries

spatial data
geometry
importance: medium
Author
Published

July 17, 2024

Modified

August 17, 2024


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()

install.packages("spanishoddata",
  repos = c("https://e-kotov.r-universe.dev", "https://cloud.r-project.org"))

zones <- spanishoddata::spod_get_zones("gau", ver = 2)

Steps to Reproduce

  1. 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"))
  1. Identify Invalid Geometries
gau_boundaries_invalid <- !st_is_valid(gau_boundaries)

Results

  1. Number of Invalid Geometries
sum(gau_boundaries_invalid)
[1] 3
  1. Names of Large Urban Areas with Invalid Geometries
DT::datatable(gau_boundaries[gau_boundaries_invalid,] |> st_drop_geometry())