# create_geometry_lookup.R
# One-time script. Extracts account_number -> geometry from the manually
# corrected QGIS file and saves as a stable lookup table.
# Re-run only if geometry ever needs to be corrected.
# Output: data-raw/addresses/geometry_lookup.rds

library(sf)
library(dplyr)

raw <- st_read(
  "./data-raw/addresses/owners_moved.gpkg",
  layer = "owners_raw",
  quiet = TRUE
)
cat("Columns:", paste(names(raw), collapse = ", "), "\n")

lookup <- raw |>
  select(account_number)

cat("Lookup rows:", nrow(lookup), "\n")
cat("Any duplicate account numbers:", anyDuplicated(lookup$account_number) > 0, "\n")

saveRDS(lookup, "./data-raw/addresses/geometry_lookup.rds")
cat("Saved to data-raw/addresses/geometry_lookup.rds\n")
