Skip to content

Commit

Permalink
Merge pull request #11 from CMAP-REPOS/update_geos
Browse files Browse the repository at this point in the history
Update data as of 2/12/23
  • Loading branch information
EthanJantz authored Feb 13, 2023
2 parents 3b97056 + 2859df6 commit ff47c1a
Show file tree
Hide file tree
Showing 50 changed files with 105 additions and 170 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Suggests:
ggplot2,
tidycensus
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
97 changes: 39 additions & 58 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#'
#' The Census Blocks within the 7-county Chicago Metropolitan Agency for
#' Planning (CMAP) region. From the US Census Bureau's TIGER/Line shapefiles,
#' 2021 vintage. **Use `block_sf` for data from the 2020 decennial census or the
#' American Community Survey (ACS) from 2020 onward. For data from the 2010
#' decennial census or ACS from 2010 through 2019, use `block_sf_2010`.**
#' 2022 vintage. **Use `block_sf` for data from the 2020 decennial census or the
#' American Community Survey (ACS) from 2020 onward.**
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -54,20 +53,11 @@
#' ggplot(block_sf) + geom_sf(lwd = 0.1) + theme_void()
"block_sf"

#' @rdname block_sf
#' @format `block_sf_2010` is a multipolygon `sf` object with
#' `r nrow(block_sf_2010)` rows and `r ncol(block_sf_2010)` variables.
"block_sf_2010"


#' Census Block Groups
#'
#' The Census Block Groups within the 7-county Chicago Metropolitan Agency for
#' Planning (CMAP) region. From the US Census Bureau's TIGER/Line shapefiles,
#' 2021 vintage. **Use `blockgroup_sf` for data from the 2020 decennial census
#' or the American Community Survey (ACS) from 2020 onward. For data from the
#' 2010 decennial census or ACS from 2010 through 2019, use
#' `blockgroup_sf_2010`.**
#' 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -114,19 +104,11 @@
#' ggplot(blockgroup_sf) + geom_sf(lwd = 0.1) + theme_void()
"blockgroup_sf"

#' @rdname blockgroup_sf
#' @format `blockgroup_sf_2010` is a polygon `sf` object with
#' `r nrow(blockgroup_sf_2010)` rows and `r ncol(blockgroup_sf_2010)` variables.
"blockgroup_sf_2010"


#' Census Tracts
#'
#' The Census Tracts within the 7-county Chicago Metropolitan Agency for
#' Planning (CMAP) region. From the US Census Bureau's TIGER/Line shapefiles,
#' 2021 vintage. **Use `tract_sf` for data from the 2020 decennial census or the
#' American Community Survey (ACS) from 2020 onward. For data from the 2010
#' decennial census or ACS from 2010 through 2019, use `tract_sf_2010`.**
#' 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -182,19 +164,11 @@
#' ggplot(tract_sf) + geom_sf(lwd = 0.1) + theme_void()
"tract_sf"

#' @rdname tract_sf
#' @format `tract_sf_2010` is a polygon `sf` object with `r nrow(tract_sf_2010)`
#' rows and `r ncol(tract_sf_2010)` variables.
"tract_sf_2010"


#' Census Public Use Microdata Areas (PUMAs)
#'
#' The Census PUMAs covering the 7-county Chicago Metropolitan Agency for
#' Planning (CMAP) region. From the US Census Bureau's TIGER/Line shapefiles,
#' 2021 vintage. **These PUMAs are valid for use with ACS PUMS data from 2012
#' through 2021. They will be superseded by the 2020 PUMAs when the 2022 ACS
#' data is published.**
#' 2022 vintage.
#'
#' Census Bureau description:
#'
Expand All @@ -203,14 +177,17 @@
#' census records that are screened to protect confidentiality. These extracts
#' are referred to as public use microdata sample (PUMS) files.*
#'
#' *"For the 2010 Census, each state, the District of Columbia, Puerto Rico, and
#' some Island Area participants delineated PUMAs for use in presenting PUMS
#' data based on a 5 percent sample of decennial census or American Community
#' Survey data. These areas are required to contain at least 100,000 people.
#' This is different from Census 2000 when two types of PUMAs were defined: a 5
#' percent PUMA as for 2010 and an additional super-PUMA designed to provide a 1
#' percent sample. The PUMAs are identified by a five-digit census code unique
#' within state."*
#' *"PUMAs are statistical geographic areas defined for the tabulation and
#' dissemination of American Community Survey (ACS) and Puerto Rico Community
#' Survey Public Use Microdata Sample (PUMS) data as well as ACS period
#' estimates, and decennial census data. Nesting within states or equivalent
#' entities, PUMAs cover the entirety of the United States, Puerto Rico, Guam,
#' and the U.S. Virgin Islands. PUMA delineations are subject to population
#' threshold criteria, “building block” geography criteria, and geographic
#' nesting criteria. State Data Centers (SDCs) define PUMAs with the cooperation
#' of regional, state, local, and tribal governments, organizations, and other
#' interested data users. Each PUMA must have a minimum population of 100,000 at
#' the time of delineation and throughout the decade.*
#'
#' @format
#' A multipolygon `sf` object with `r nrow(puma_sf)` rows and `r ncol(puma_sf)`
Expand Down Expand Up @@ -239,7 +216,7 @@
#'
#' The Census ZCTAs covering the 7-county Chicago Metropolitan Agency for
#' Planning (CMAP) region. From the US Census Bureau's TIGER/Line shapefiles,
#' 2021 vintage.
#' 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -287,10 +264,11 @@
#' Illinois State Senate Districts
#'
#' The Illinois General Assembly Senate Districts. From the US Census Bureau's
#' TIGER/Line shapefiles, 2021 vintage. **These districts were in effect for
#' TIGER/Line shapefiles, 2022 vintage. **These districts were in effect for
#' elections from 2012 through 2020 (i.e. the 98th through 102nd General
#' Assemblies). They will be superseded by new district boundaries for the 2022
#' election (for the 103rd General Assembly).**
#' election (for the 103rd General Assembly). Updated shapefiles from the Census
#' Bureau are expected in spring 2023.**
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -343,10 +321,12 @@
#' Illinois State House Districts
#'
#' The Illinois General Assembly House Districts. From the US Census Bureau's
#' TIGER/Line shapefiles, 2021 vintage. **These districts were in effect for
#' TIGER/Line shapefiles, 2022 vintage. **These districts were in effect for
#' elections from 2012 through 2020 (i.e. the 98th through 102nd General
#' Assemblies). They will be superseded by new district boundaries for the 2022
#' election (for the 103rd General Assembly).**
#' election (for the 103rd General Assembly). As with Illinois State Senate
#' districts, updated files are expected from the Census Bureau in spring
#' 2023.**
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -399,10 +379,10 @@
#' U.S. Congressional Districts
#'
#' The United States Congressional Districts in the state of Illinois. From the
#' US Census Bureau's TIGER/Line shapefiles, 2021 vintage. **These districts
#' US Census Bureau's TIGER/Line shapefiles, 2022 vintage. **These districts
#' were in effect for elections from 2012 through 2020 (i.e. the 113th through
#' 117th Congresses). They will be superseded by new district boundaries for the
#' 2022 election (for the 118th Congress).**
#' 2022 election (for the 118th Congress). Updates are expected in spring 2023.**
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -442,7 +422,7 @@
#' The 284 municipalities (also referred to as "incorporated places" in Census
#' Bureau terminology) that are at least partially within the 7-county Chicago
#' Metropolitan Agency for Planning (CMAP) region. From the US Census Bureau's
#' TIGER/Line shapefiles, 2021 vintage.
#' TIGER/Line shapefiles, 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -483,7 +463,7 @@
#' Bureau terminology) that are within the CMAP Metropolitan Planning Area
#' (MPA). (The MPA includes the 7 CMAP counties, plus Aux Sable Township in
#' Grundy County and Sandwich & Somonauk Townships in DeKalb County.) From the
#' US Census Bureau's TIGER/Line shapefiles, 2021 vintage.
#' US Census Bureau's TIGER/Line shapefiles, 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -526,7 +506,7 @@
#' The counties that are within the CMAP travel modeling area **or** the
#' "Chicago-Naperville-Elgin, IL-IN-WI" Metropolitan Statistical Area (as
#' defined by the United States Office of Management and Budget). From the US
#' Census Bureau's TIGER/Line shapefiles, 2021 vintage.
#' Census Bureau's TIGER/Line shapefiles, 2022 vintage.
#'
#' Census Bureau description:
#'
Expand Down Expand Up @@ -577,7 +557,7 @@
#' by the Illinois Department of Transportation (IDOT). Includes a column
#' indicating which of the five transportation regions each district belongs to.
#' Created using the county boundaries in the US Census Bureau's TIGER/Line
#' shapefiles, 2021 vintage.
#' shapefiles, 2022 vintage.
#'
#' @format
#' A polygon `sf` object with `r nrow(idot_sf)` rows and `r ncol(idot_sf)`
Expand Down Expand Up @@ -606,7 +586,7 @@

#' Chicago Community Areas (CCAs)
#'
#' The official boundaries of the Chicago Community Areas. Obtained 3/24/2021.
#' The official boundaries of the Chicago Community Areas. Obtained 2/12/2023.
#'
#' @format
#' A multipolygon `sf` object with `r nrow(cca_sf)` rows and `r ncol(cca_sf)`
Expand All @@ -631,7 +611,8 @@
#' Chicago Wards
#'
#' The official boundaries of the Chicago wards established in May of 2015.
#' Obtained 3/24/2021.
#' Obtained 2/12/2023. Updated boundaries will be provided once the 2023 wards
#' come into effect in May 2023.
#'
#' @format
#' A multipolygon `sf` object with `r nrow(ward_sf)` rows and `r ncol(ward_sf)`
Expand Down Expand Up @@ -679,7 +660,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/cmap-metropolitan-planning-area-september-2014)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/cmap-metropolitan-planning-area-september-2014)
#'
#' @examples
#' # Display the CMAP MPA counties with ggplot2
Expand Down Expand Up @@ -726,7 +707,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/councils-of-mayors-boundaries)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/councils-of-mayors-boundaries)
#'
#' @seealso
#' <https://www.cmap.illinois.gov/committees/advisory/council-of-mayors/subregional-councils>
Expand Down Expand Up @@ -772,7 +753,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/on-to-2050-layer-edas-disinvested-areas)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/on-to-2050-layer-edas-disinvested-areas)
#'
#' @seealso
#' <https://www.cmap.illinois.gov/2050/maps/eda>
Expand Down Expand Up @@ -811,7 +792,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/facility-planning-areas-fpa)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/facility-planning-areas-fpa)
#'
#' @seealso
#' <https://www.cmap.illinois.gov/programs/water/water-quality/wastewater-planning>
Expand Down Expand Up @@ -875,7 +856,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/cmap-modeling-zone-systems)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/cmap-modeling-zone-systems)
#'
#' @examples
#' # Display the subzones with ggplot2
Expand Down Expand Up @@ -915,7 +896,7 @@
#' }
#'
#' @source
#' [CMAP Data Hub](https://datahub.cmap.illinois.gov/dataset/cmap-modeling-zone-systems)
#' [CMAP Data Hub (temporarily offline)](https://datahub.cmap.illinois.gov/dataset/cmap-modeling-zone-systems)
#'
#' @examples
#' # Display the zones with ggplot2
Expand Down
11 changes: 6 additions & 5 deletions data-raw/generate_xwalks.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library(tidyverse)
devtools::load_all()

# Set parameters
tigerline_year <- 2021 # Latest TIGER/Line vintage
tigerline_year <- 2022 # Latest TIGER/Line vintage
lehd_year <- 2019 # Latest LEHD year available, for employment data
census_year <- 2020 # Latest Decennial Census
census_vars <- c("H1_001N", "H1_002N", "P1_001N") # HU, HH, POP vars in 2020 redistricting data
Expand Down Expand Up @@ -54,10 +54,11 @@ lehd_data <- lehdr::grab_lodes(
select(w_geocode, emp = C000)


### PROCESS LEHD EMPLOYMENT DATA USING 2010 CENSUS BLOCKS ###
# Note: this section is only needed until LEHD switches to use the 2020 blocks.
# As of the 2019 LEHD, it still uses the 2010 blocks. Once it switches, remove
# this section and the LEHD data will be joined to block_data directly.
### PROCESS LEHD EMPLOYMENT DATA USING 2010 CENSUS BLOCKS
### Note: this section is only needed until LEHD switches to use the 2020
# blocks. This is still needed as of February 12, 2023. As of the 2019 LEHD, it
# still uses the 2010 blocks. Once it switches, remove this section and the LEHD
# data will be joined to block_data directly.

# Get 2010 Census block geometries for entire modeling area
block2010_21co_sf <- tigris::blocks(state = "IL", county = counties_il, year = 2019) %>%
Expand Down
51 changes: 8 additions & 43 deletions data-raw/load_census_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ library(tidyverse)
devtools::load_all()

# Set common parameters
BASE_YEAR <- 2021 # TIGER/Line vintage to use by default
BASE_YEAR <- 2022 # TIGER/Line vintage to use by default
STATE <- "17" # Illinois
COUNTIES_7CO <- c("031", "043", "089", "093", "097", "111", "197") # CMAP 7
COUNTIES_MPO <- c(COUNTIES_7CO, "063", "037") # CMAP 7, plus Grundy and DeKalb
Expand Down Expand Up @@ -71,7 +71,7 @@ municipality_sf <- tigris::places(state = STATE, year = BASE_YEAR) %>%
arrange(geoid_place)

# Process Congressional Districts (U.S. House of Representatives)
# Note: still 2011 districts, as of 2020 TIGER/Line
# Note: still 2011 districts, as of 2022 TIGER/Line. Updates are expected in spring 2023.
congress_sf <- tigris::congressional_districts(year = BASE_YEAR) %>%
filter(STATEFP == STATE, LSAD == "C2") %>%
sf::st_transform(cmap_crs) %>%
Expand All @@ -86,7 +86,7 @@ congress_sf <- tigris::congressional_districts(year = BASE_YEAR) %>%
arrange(dist_num)

# Process IL House Districts (Illinois General Assembly)
# Note: still 2011 districts, as of 2020 TIGER/Line
# Note: still 2011 districts, as of 2022 TIGER/Line. Updates are expected in spring 2023.
ilga_house_sf <- tigris::state_legislative_districts(state = STATE, house = "lower", year = BASE_YEAR) %>%
filter(LSAD == "LL") %>%
sf::st_transform(cmap_crs) %>%
Expand All @@ -98,7 +98,7 @@ ilga_house_sf <- tigris::state_legislative_districts(state = STATE, house = "low
arrange(dist_num)

# Process IL Senate Districts (Illinois General Assembly)
# Note: still 2011 districts, as of 2020 TIGER/Line
# Note: still 2011 districts, as of 2022 TIGER/Line. Updates are expected in spring 2023.
ilga_senate_sf <- tigris::state_legislative_districts(state = STATE, house = "upper", year = BASE_YEAR) %>%
filter(LSAD == "LU") %>%
sf::st_transform(cmap_crs) %>%
Expand All @@ -110,18 +110,16 @@ ilga_senate_sf <- tigris::state_legislative_districts(state = STATE, house = "up
arrange(dist_num)

# Process Public Use Microddata Areas (PUMAs)
# Note: still 2010 boundaries, as of 2020 TIGER/Line
# Note: Now includes 2020 boundaries, as of 2022 TIGER/Line
puma_sf <- tigris::pumas(state = STATE, year = BASE_YEAR) %>%
sf::st_transform(cmap_crs) %>%
filter(intersects_cmap(.)) %>% # Restrict to CMAP region
rmapshaper::ms_erase(temp_lakemich_sf) %>% # Erase Lake Michigan
rename(geoid_puma = GEOID10,
name = NAMELSAD10) %>%
rename(geoid_puma = GEOID20,
name = NAMELSAD20) %>%
mutate(sqmi = unclass(sf::st_area(geometry) / sqft_per_sqmi)) %>%
select(geoid_puma, name, sqmi) %>%
arrange(geoid_puma) %>%
## Manually exclude one PUMA, which appears to mistakenly include a *tiny* block in McHenry
filter(geoid_puma != "1702901")
arrange(geoid_puma)

# Process ZIP Code Tabulation Areas (ZCTAs)
zcta_sf <- tigris::zctas(starts_with = "6", year = BASE_YEAR) %>%
Expand Down Expand Up @@ -187,36 +185,6 @@ block_sf <- tigris::blocks(state = STATE, county = COUNTIES_7CO, year = BASE_YEA
arrange(geoid_block)


# Process 2010 Census geographies (block, block group, tract)
# Note: remove these datasets from cmapgeo once 2021 1-year ACS is released
tract_sf_2010 <- tigris::tracts(state = STATE, county = COUNTIES_7CO, year = 2019) %>%
filter(TRACTCE != "990000") %>% # Exclude Lake Michigan tracts
sf::st_transform(cmap_crs) %>%
rename(geoid_tract = GEOID) %>%
mutate(county_fips = paste0(STATEFP, COUNTYFP),
sqmi = unclass(sf::st_area(geometry) / sqft_per_sqmi)) %>%
select(geoid_tract, county_fips, sqmi) %>%
arrange(geoid_tract)

blockgroup_sf_2010 <- tigris::block_groups(state = STATE, county = COUNTIES_7CO, year = 2019) %>%
filter(TRACTCE != "990000") %>% # Exclude Lake Michigan tracts
sf::st_transform(cmap_crs) %>%
rename(geoid_blkgrp = GEOID) %>%
mutate(county_fips = paste0(STATEFP, COUNTYFP),
sqmi = unclass(sf::st_area(geometry) / sqft_per_sqmi)) %>%
select(geoid_blkgrp, county_fips, sqmi) %>%
arrange(geoid_blkgrp)

block_sf_2010 <- tigris::blocks(state = STATE, county = COUNTIES_7CO, year = 2019) %>%
filter(TRACTCE10 != "990000") %>% # Exclude Lake Michigan tracts
sf::st_transform(cmap_crs) %>%
rename(geoid_block = GEOID10) %>%
mutate(county_fips = paste0(STATEFP10, COUNTYFP10),
sqmi = unclass(sf::st_area(geometry) / sqft_per_sqmi)) %>%
select(geoid_block, county_fips, sqmi) %>%
arrange(geoid_block)


# Save processed data to package's data dir
usethis::use_data(county_sf, overwrite = TRUE)
usethis::use_data(township_sf, overwrite = TRUE)
Expand All @@ -230,6 +198,3 @@ usethis::use_data(idot_sf, overwrite = TRUE)
usethis::use_data(tract_sf, overwrite = TRUE)
usethis::use_data(blockgroup_sf, overwrite = TRUE)
usethis::use_data(block_sf, overwrite = TRUE)
usethis::use_data(tract_sf_2010, overwrite = TRUE)
usethis::use_data(blockgroup_sf_2010, overwrite = TRUE)
usethis::use_data(block_sf_2010, overwrite = TRUE)
Loading

0 comments on commit ff47c1a

Please sign in to comment.