You can install the development version of tract from GitHub with:
# install.packages("devtools")
devtools::install_github("geomarker-io/tract")
In R, get census tract identifiers for exact locations and years using
the get_census_tract_id()
function:
library(tract)
get_census_tract_id(
s2::as_s2_cell(c("8841b399ced97c47", "8841b38578834123")),
year = "2020")
#> ℹ Found 2 unique locations in 1 state
#> 8841b399ced97c47 8841b38578834123
#> "39061003200" "39061003000"
The s2 geohash is a hierarchical geospatial index that uses spherical geometry. In R, s2 cells can be created using their character string representation, or by specifying latitude and longitude coordinates; e.g.:
s2::s2_lnglat(c(-84.4126, -84.5036), c(39.1582, 39.2875)) |> s2::as_s2_cell()
#> <s2_cell[2]>
#> [1] 8841ad122d9774a7 88404ebdac3ea7d1