Package 'codec'

Title: Community Data Explorer for Cincinnati
Description: This repository serves as the definition of the CoDEC data specifications and provides helpers to create, validate, release, and read CoDEC data.
Authors: Cole Brokamp [aut, cre], Erika Manning [aut], Andrew Vancil [aut]
Maintainer: Cole Brokamp <[email protected]>
License: GPL (>= 3)
Version: 2.3.0.9001
Built: 2025-01-24 21:25:57 UTC
Source: https://github.com/geomarker-io/codec

Help Index


Convert a tibble to a CoDEC data package

Description

CoDEC Specifications:

  1. The data must include a census tract identifier column (i.e., census_tract_id_2010, or census_tract_id_2020). The column must contain 11-digit GEOID identifiers for every census tract in Hamilton County, OH.

  2. The data includes a year column (year), an integer year representing the vintage of the data (e.g. 2021). The data can optionally include a month column (month), an integer month of the year.

  3. Data must be structured in a tidy format such that each row is an observation for a specific census tract at a specific year (and month).

Usage

as_codec_dpkg(
  x,
  name,
  version,
  title = character(),
  description = character(),
  homepage = character()
)

is_codec_dpkg(x)

Arguments

x

data.frame or tibble meeting CoDEC data specifications above

name

see dpkg::as_dpkg()

version

see dpkg::as_dpkg()

title

see dpkg::as_dpkg()

description

see dpkg::as_dpkg()

homepage

see dpkg::as_dpkg()

Value

for as_codec_dpkg, a dpkg object

for is_codec_dpkg, a logical

Examples

is_codec_dpkg(mtcars)

Cincy census tracts and block groups

Description

Read tract and block group ("bg") geographies from the online Census TIGER/Line files into R

Usage

cincy_census_geo(
  geography = c("tract", "bg"),
  vintage = as.character(2024:2013)
)

cincy_county_geo(vintage = as.character(2024:2013))

Arguments

geography

which type of cincy census geography to return

vintage

a character vector of a year corresponding to the vintage of TIGER/Line data

Details

Compressed shapefiles are downloaded from TIGER into an R user data directory and will be cached for use across other R sessions (see ?dpkg::stow for more details).

Value

a simple features object with a geographic identifier column (geoid) and a geometry column (s2_geography)

Examples

cincy_census_geo("tract", "2024")
cincy_census_geo("tract", "2020")
cincy_census_geo("tract", "2019")
cincy_census_geo("bg", "2020")
cincy_census_geo("bg", "2019")
cincy_county_geo("2024")

cincy_city_geo()

Description

cincy_city_geo()

Usage

cincy_city_geo()

Examples

cincy_city_geo()

Cincy neighborhood geographies

Description

CAGIS data (see install_cagis_data()) provides community council boundaries, but these boundaries can overlap and do not align with census geographies or ZIP codes. By default, the statistical neighborhood approximations are instead returned, which are calculated by aggregating census tracts into 50 matching neighborhoods.

Usage

cincy_neighborhood_geo(
  geography = c("statistical_neighborhood_approximations", "community_council")
)

Arguments

geography

which type of cincy neighborhood geography to return

Value

a simple features object with a geographic identifier column (geoid) and a geometry column (s2_geography)

Examples

cincy_neighborhood_geo("statistical_neighborhood_approximations")
cincy_neighborhood_geo("community_council")

Cincy ZIP Code Tabulation Areas

Description

Read ZIP Code Tabulation Areas (ZCTAs) geographies from the online Census TIGER/Line files into R

Usage

cincy_zcta_geo(vintage = as.character(2024:2013))

Arguments

vintage

a character vector of a year corresponding to the vintage of TIGER/Line data

Value

a simple features object with a geographic identifier column (geoid) and a geometry column (s2_geography)

Examples

cincy_zcta_geo()
cincy_zcta_geo("2018")

Coerce CoDEC data package into a simple features object

Description

The name of the census tract column in the CoDEC data package is used to add the appropriate cincy geography.

Usage

codec_as_sf(x)

Arguments

x

a CoDEC data package

Details

Tract identifers do not change across decennial censuses, but the digital representation of their boundaries may be improved over time. Here, data packages using 2010 tract identifers use the TIGER/Line 2019 tract shapefiles and data packages using 2020 tract identifiers use the TIGER/Line 2020 tract shapefiles

Value

a simple features object with a geographic identifier column (geoid) and a geometry column (s2_geography) in addition to the columns in x

Examples

codec_as_sf(get_codec_dpkg("property_code_enforcements-v0.2.0"))

CoDEC colors

Description

CoDEC colors

Usage

codec_colors(n = NULL)

Arguments

n

a numeric vector of color numbers or character vector of color names; if NULL returns named vector of available colors

Examples

plot(1:8, rep(1, 8), col = codec_colors(1:8),
  pch = 19, cex = 10, axes = FALSE, xlab = "", ylab = "")
text(1:8, rep(1.1, 8), labels = names(codec_colors()))

Spatially interpolate community-level data

Description

Census block-level weights are used to spatially interpolate CoDEC data packages from the census tract-level to other Cincy geographies.

Usage

codec_interpolate(from, to, weights = c("pop", "homes", "area"))

Arguments

from

a CoDEC data package

to

A simple features object returned by one of the ⁠cincy_*_geo()⁠ functions (i.e., cincy_census_geo(), cincy_neighborhood_geo(), or cincy_zcta_geo()')

weights

which census block-level weights to use; see details

Details

Block-level total population (pop), total number of homes (homes), or total land area (area) from the 2020 Census can be chosen to use for the weights. Geospatial intersection happens after transforming geographies to epsg:5072. See codec_as_sf() for adding geography to a CoDEC data package. Variables beginning with "n_" are interpolated using a weighted sum; all other variables are interpolated using a weighted mean.

Value

a tibble with a new geographic identifier column for the to target geography (geoid) in addition to the (interpolated) columns in from

Examples

codec_interpolate(get_codec_dpkg("acs_measures-v0.1.0"),
                  cincy_neighborhood_geo())
codec_interpolate(get_codec_dpkg("property_code_enforcements-v0.2.0"),
                  cincy_census_geo("tract", "2020"))

Read a dpkg from CoDEC into R

Description

Public data packages are downloaded from ⁠gh://geomarker-io/codec/⁠ using dpkg::stow() to cache a local copy in the user's data directory.

Usage

get_codec_dpkg(codec_dpkg, overwrite = FALSE)

Arguments

codec_dpkg

name of CoDEC dpkg

overwrite

logical; re-download the remote file even though a local file with the same name exists?

Value

a CoDEC data package (see dpkg::as_dpkg())

Examples

get_codec_dpkg("drivetime-v0.2.2")

Install CAGIS GIS database

Description

This installs the CAGIS Open Data GIS database (.gdb) into the data directory for the codec package. Once downloaded, it will be reused across R sessions on the same computer. The geodatabase contains many layers that are updated quarterly. (Historical geodatabases are not available here.)

Usage

install_cagis_data(
  cagis_data_url =
    "https://www.cagis.org/Opendata/Quarterly_GIS_Data/CAGISOpenDataQ4_2024.gdb.zip"
)

Arguments

cagis_data_url

the url to the CAGIS Open Data .gdb.zip file; this changes quarterly, so check for something more recent if the file cannot be found

See Also

This function is called by cincy_neighborhood_geo(), cincy_city_geo() and others that import individual layers.

Examples

options(timeout = max(2500, getOption("timeout")), download.file.method = "libcurl")
install_cagis_data()
sf::st_layers(install_cagis_data())$name