Skip to contents

geocode_tiger() geocodes addr vectors using TIGER address range geometries downloaded from census.gov for a specific county.

The geocoding precision is the level of matching achieved for each address:

  • range: is the most precise; the address matched on street name and ZIP code, and the number was within one of the ranges; point locations are interpolated from the geometry of the best match using the street number

  • street: is less precise; the address matched on street name and ZIP code, but the number was not within one of the ranges; point locations are interpolated as the centroid of all matching range geometries

  • unmatched: no precision; the address did not match any street name and ZIP code combinations; point locations are <null feature> (which is equivalent to NA)

Usage

geocode_tiger(x, county, year, offset = 0)

Arguments

x

an addr vector

county

character string of county identifier

year

character year of tigris product

offset

number of meters to offset geocode from street line

Value

a s2_geography vector of geocoded point locations; an attribute ("geocode_precision") is added as a factor with levels range, street, or unmatched.

Details

If a street number-name has multiple in range and parity matches, then the best match is chosen based on the smallest width of ranges and then on the range with the closest midpoint.

Examples

gcd <-
  geocode_tiger(as_addr(voter_addresses()[1:100]),
                county = "39061", year = "2024", offset = 20)
#> matching 100 addresses to 55922 address ranges in county 39061 (TIGER vintage 2024) ...
#> Warning: 11 addr in x could not be matched to any street-zipcodes
#> finding best matched ranges using street number...
#> Warning: 1 addr in x were matched to a street, but could not be matched to a range
#> imputing point along matched range...

head(gcd)
#> <geodesic s2_geography[6] with CRS=OGC:CRS84>
#> [1] POINT (-84.6109993 39.1404602) POINT (-84.5891071 39.1116154)
#> [3] POINT (-84.5279112 39.2497598) POINT (-84.5256961 39.1270156)
#> [5] POINT (-84.3172464 39.0776455) POINT (-84.3824045 39.088258) 

table(attr(gcd, "geocode_precision"))
#> 
#>     range unmatched    street 
#>        88        11         1 

# consider addresses matched to street but out of range missing
gcd[attr(gcd, "geocode_precision") == "street"] <- NA_character_

# convert to s2_cell
s2::as_s2_cell(gcd)
#> <s2_cell[100]>
#>   [1] 8841ca76b5efbe77 8841b60a0d5e19f5 88404b8c046f8bdd 8841b40ba44f9447
#>   [5] 8841a90b58dbe54d 8841ae9112bbb0cd 884053f3f6fee25f 8841ad8d8f978ce1
#>   [9] 88404d08e849910b 88404d1b33e32715 88404b1f222d5069 88404b05997174e7
#>  [13] 8841b303e0996f01 8841b259c73b173d 88404d59413d123f 88404bdd1899d5f9
#>  [17] 8841b4cee66afceb 8841b5908d386da1 8841acf822dad861 8841b59a829ebd39
#>  [21] 8841b672db4c6a39 NA               8841b26737052c6d 88404b1264b22fdf
#>  [25] 884054a63a68942b 88404de2651a3ca3 8841ca9d5d9af5cd 8841c9db1972956d
#>  [29] 88404ae535c4e161 8841b248d848c017 88404e8dfad37c71 8841b3fe80d160ef
#>  [33] 8841b1541d2a216d 8841b3be6c6e8145 88402c527ce786fd 8841b5e337f57d15
#>  [37] 88404b1311c91a23 NA               8841cd0fd27f4841 8841ad7f5941f239
#>  [41] 8841aee7ee93b15d 8841ad98d5e440e7 8841adbeffcbcc41 8841ca1539fc6c1b
#>  [45] 884056418a7fd145 8841a97af382893f 884052d867347865 8841b3d8a5f4624d
#>  [49] 8841ace88bc1b725 8841b623135a2889 8841b4783ab86801 88405356c064f025
#>  [53] 8841c9f7d4b6fee5 88404eae1d096a39 8840517490bf206f 88404ad2a7b1b09d
#>  [57] 88404a363c5fbdef 8841ad7c827f7c67 8841acab01ccb0e3 88404b551494672b
#>  [61] 8841b5ecdf41b8af NA               8841b62395ba62b9 8841ae910c566cf7
#>  [65] 8841ca767b596cc3 NA               NA               8841b1597a5ec3eb
#>  [69] 884053129b312faf 88404c7f269aeb6f 8841c9dab2d3757b 8840355c4a70f931
#>  [73] 8841ca034277ac9b 8841aec6e225ae1b NA               NA              
#>  [77] NA               8841ac23d29086ed 8841c97272f18573 88404a90bef927e9
#>  [81] NA               88403512a1f13121 88402c53baf37d75 88404b2ea8e97e71
#>  [85] 8841b2f0289231d7 8841ad6b91ca4fe5 NA               88404b39f409668d
#>  [89] NA               8841ad5bdd7381cd NA               8841b3ede13148d5
#>  [93] 88404c211ecd713d 8841cb7f088440df 8841ac2abea965c5 8841b393e3bff263
#>  [97] 8841b5ea771e3919 8841ad8c111bea6f 8841acf3ed338a5b 8841a94cb3910809

# create leaflet map
leaflet::leaflet(wk::wk_coords(gcd)) |>
  leaflet::addTiles() |>
  leaflet::addCircleMarkers( lng = ~x, lat = ~y, label = ~ feature_id)