Skip to content

Commit

Permalink
handle 2020 urban area geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed May 27, 2023
1 parent bb8109f commit 8db55e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions R/census.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,13 @@ get_decennial <- function(geography,

} else {

geom <- try(suppressMessages(use_tigris(geography = geography, year = year,
state = state, county = county, ...)))
if (geography == "urban area" && year == 2020) {
geom <- try(suppressMessages(use_tigris(geography = geography, year = year,
state = state, county = county, criteria = "2020", ...)))
} else {
geom <- try(suppressMessages(use_tigris(geography = geography, year = year,
state = state, county = county, ...)))
}

if ("try-error" %in% class(geom)) {
stop("Your geometry data download failed. Please try again later or check the status of the Census Bureau website at https://www2.census.gov/geo/tiger/", call. = FALSE)
Expand Down
11 changes: 10 additions & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,18 @@ use_tigris <- function(geography, year, cb = TRUE, resolution = "500k",
# Right now, urban areas are not defined for 2020 and are not in the CB file
if (year == 2020) cb <- FALSE

# The 2020 decennial Census uses the 2020 urban areas, but the 2020 ACS
# does not, so we will need to figure that out in the get_decennial side
# Pass that through as a keyword argument

ua <- urban_areas(cb = cb, year = year, class = "sf", ...)

ua <- rename(ua, GEOID = GEOID10)
if ("GEOID20" %in% names(ua)) {
ua <- rename(ua, GEOID = GEOID20)
} else {
ua <- rename(ua, GEOID = GEOID10)
}


return(ua)

Expand Down

0 comments on commit 8db55e9

Please sign in to comment.