Skip to content

Commit

Permalink
feat: Add neighborhoods_2020 + baltimore_census_xwalk data
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Nov 7, 2023
1 parent b6c1b39 commit a82ef25
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 4 deletions.
5 changes: 3 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## New data

* Added `buildings_21stc` (2023-04-28), `main_streets` (2023-10-16), and `rec_centers` (2023-10-19)
* Added `buildings_21stc` (2023-04-28), `main_streets` (2023-10-16), `rec_centers` (2023-10-19), and `neighborhoods_2020` (2023-11-06) spatial data.
* Added `baltimore_area_xwalk` (2023-11-06) reference data.

## Updated data

Expand All @@ -15,7 +16,7 @@

* Add `get_neighborhood()` and refactor `get_baltimore_area()` for more consistency with `{getdata}` parameter names (2023-05-26).

## other
## Other

* Update package logo and switch pkgdown site to rendering with GitHub actions (2023-06-13)

Expand Down
45 changes: 44 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' by local community or neighborhood associations as an area of responsibility
#' or membership recruitment.
#'
#' @format A data frame with 278 rows and 2 variables:
#' @format A data frame with 278 rows and 6 variables:
#' \describe{
#' \item{`name`}{Neighborhood name}
#' \item{`type`}{Type of area, with options including residential, industrial area, park/open space, institutionl area and business park)}
Expand All @@ -62,6 +62,28 @@
#' @source [Maryland Baltimore City Neighborhoods (MD iMap)](https://data.imap.maryland.gov/datasets/fc5d183b20a145009eae8f8b171eeb0d_0)
"neighborhoods"


#' Neighborhood Boundaries for Baltimore City (2020)
#'
#' Baltimore City neighborhoods (officially known as Neighborhood Statistical
#' Areas) established by the Baltimore City Department of Planning based on the
#' 2020 U.S. Decennial Census. This is an updated version of the 2010
#' Neighborhood Statistical Areas.
#'
#' @format A data frame with 279 rows and 8 variables:
#' \describe{
#' \item{`name`}{Neighborhood name}
#' \item{`name_alt`}{2010 neighborhood name}
#' \item{`type`}{Type of area, with options including residential, industrial area, park/open space, institutionl area and business park)}
#' \item{`acres`}{Area of the neighborhood (acres)}
#' \item{`osm_id`}{Open Street Map (OSM) relation identifier}
#' \item{`wikidata`}{Wikidata entity identifier}
#' \item{`color_id`}{Color identifier}
#' \item{`geometry`}{MULITPOLYGON boundary geometry}
#' }
#' @source [NSA_Feb2023_service](https://services1.arcgis.com/43Lm3JYE3nM91DAF/arcgis/rest/services/NSA_March2023/FeatureServer/0)
"neighborhoods_2020"

#' U.S. Census Block-to-Tract Crosswalk with 2010 Block Household Population
#'
#' A crosswalk file used to generate `xwalk_neighborhood2tract`.
Expand Down Expand Up @@ -1169,3 +1191,24 @@
#'}
#' @source <https://services1.arcgis.com/UWYHeuuJISiGmgXx/arcgis/rest/services/recreationCenter2023/FeatureServer>
"rec_centers"

#' Crosswalk for Baltimore areas and Census geography
#'
#' A pre-built crosswalk data frame that can be filtered by geography and then
#' used with the [getACS::use_area_xwalk()] function. Crosswalk uses the 2010
#' City Council district boundaries, 2010 and 2020 neighborhood (neighborhood
#' statistical area) boundaries, and current city planning districts.
#'
#' @format A data frame with 1024 rows and 8 variables:
#' \describe{
#' \item{`geography`}{Geography/area type}
#' \item{`GEOID`}{2020 Census GeoID}
#' \item{`TRACTCE20`}{2020 Census Tract ID}
#' \item{`name`}{Area name}
#' \item{`POP20`}{Population in area and tract}
#' \item{`perc_POP20`}{Percent of population in area and tract}
#' \item{`HOUSING20`}{Households/occupied housing units in area and tract}
#' \item{`perc_HOUSING20`}{Percent of households in area and tract}
#'}
#' @details Created using the [getACS::make_area_xwalk()] data.
"baltimore_census_xwalk"
74 changes: 74 additions & 0 deletions data-raw/baltimore_census_xwalk.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## code to prepare `area_xwalk` dataset goes here

library(getACS)
library(tidyverse)

block_xwalk <- make_block_xwalk(
"MD",
"Baltimore city"
)

area_xwalk_list_housing <- map(
list(
mapbaltimore::council_districts,
mapbaltimore::neighborhoods,
neighborhoods_2020,
mapbaltimore::planning_districts
),
\(x) {
make_area_xwalk(
x,
block_xwalk,
coverage = FALSE,
name_col = "name",
weight_col = "HOUSING20"
)
}
)

area_xwalk_housing <- purrr::list_rbind(
set_names(
area_xwalk_list_housing,
c("council district 2010",
"neighborhood 2010",
"neighborhood 2020",
"planning district")
),
names_to = "geography"
)

area_xwalk_list_pop <- map(
list(
mapbaltimore::council_districts,
mapbaltimore::neighborhoods,
neighborhoods_2020,
mapbaltimore::planning_districts
),
\(x) {
make_area_xwalk(
x,
block_xwalk,
coverage = FALSE,
name_col = "name",
weight_col = "POP20"
)
}
)

area_xwalk_pop <- purrr::list_rbind(
set_names(
area_xwalk_list_pop,
c("council district 2010",
"neighborhood 2010",
"neighborhood 2020",
"planning district")
),
names_to = "geography"
)

baltimore_census_xwalk <- dplyr::full_join(
area_xwalk_pop,
area_xwalk_housing
)

usethis::use_data(baltimore_census_xwalk, overwrite = TRUE)
77 changes: 77 additions & 0 deletions data-raw/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,83 @@ planning_districts <- planning_districts %>%

usethis::use_data(planning_districts, overwrite = TRUE)

neighborhoods_2020_path <- "https://services1.arcgis.com/43Lm3JYE3nM91DAF/arcgis/rest/services/NSA_March2023/FeatureServer/0"

neighborhoods_2020_source <- neighborhoods_2020_path |>
esri2sf::esri2sf(crs = selected_crs) %>%
sfext::rename_sf_col()

neighborhoods_2020 <- neighborhoods_2020_source |>
janitor::clean_names("snake") %>%
dplyr::mutate(
acres = as.numeric(units::set_units(sf::st_area(geometry), "acres")),
type = dplyr::case_when(
(stringr::str_detect(name, "Industrial") | name == "Jones Falls Area" | name == "Dundalk Marine Terminal") ~ "Industrial area",
stringr::str_detect(name, "Business Park") ~ "Business park",
name %in% c("University Of Maryland", "Morgan State University") ~ "Institutional area",
# NOTE: This classifies Montebello as a park but is more accurately described as a reservoir
name %in% c(
"Gwynns Falls/Leakin Park", "Druid Hill Park", "Patterson Park", "Clifton Park", "Carroll Park",
"Montebello", "Greenmount Cemetery", "Herring Run Park", "Lower Herring Run Park"
) ~ "Park/open space",
TRUE ~ "Residential"
)
) %>%
dplyr::select(
name,
type,
acres,
color_id = color_2,
geometry
) %>%
dplyr::mutate(
name_alt = case_match(
name,
"Perkins" ~ "Perkins Homes",
"Mount Clare" ~ "New Southwest/Mount Clare",
"Stadium/Entertainment Area" ~ "Stadium Area",
"Baltimore Peninsula" ~ "Port Covington",
"Fairmount" ~ "Fairmont",
"Butchers Hill" ~ "Butcher's Hill",
"Villages of Homeland" ~ "Villages Of Homeland",
"Auchentoroly-Parkwood" ~ "Parkview/Woodbrook",
"Parkway" ~ "Burleith-Leighton",
# "Chinquapin Park" ~ "Wrenlane",
"Concerned Citizens of Forest Park" ~ "Concerned Citizens Of Forest Park",
"Carroll - Camden Industrial Area" ~ name,
"University Of Maryland" ~ name,
"Four By Four" ~ name,
.default = NA_character_
),
name_join = coalesce(name_alt, name),
.after = name
) |>
dplyr::mutate(
name = case_match(name,
"University Of Maryland" ~ "University of Maryland",
"Four By Four" ~ "Four by Four",
"Carroll - Camden Industrial Area" ~ "Carroll-Camden Industrial Area",
.default = name)
) |>
dplyr::left_join(
mapbaltimore::neighborhoods |>
sf::st_drop_geometry() |>
dplyr::select(
osm_id,
wikidata,
name_join = name
),
by = "name_join"
) |>
dplyr::relocate(
color_id,
.after = "wikidata"
) |>
dplyr::select(!name_join) |>
dplyr::arrange(name)

usethis::use_data(neighborhoods_2020, overwrite = TRUE)

# Import neighborhood boundaries from iMAP (derived from a data set previously available on Open Baltimore)
# https://opendata.maryland.gov/Society/MD-iMAP-Maryland-Baltimore-City-Neighborhoods/dbbp-8u4u
neighborhoods_2010_path <- "https://opendata.arcgis.com/datasets/fc5d183b20a145009eae8f8b171eeb0d_0.geojson"
Expand Down
Binary file added data/baltimore_census_xwalk.rda
Binary file not shown.
Binary file added data/neighborhoods_2020.rda
Binary file not shown.
32 changes: 32 additions & 0 deletions man/baltimore_census_xwalk.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/neighborhoods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions man/neighborhoods_2020.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a82ef25

Please sign in to comment.