GEOID extraction from geocoding call
lepromatous opened this issue · 8 comments
Is there a way to pull the GEOID (up to at least block group FIPS codes) from the cry_geocode() function? The API may not allow this, but you can get it if you geocode manually on the website. Thanks!
Thanks @lepromatous! @bransonf - lets talk about this today.
Hey @lepromatous, I threw together a function that uses the census website as you mentioned. I'll put it on my long term agenda to integrate all of the website's endpoints, but for now this should help you out.
# Get the Census Geometry from a Single Line Address
cxy_geoid <- function(address){
# Insert Address to the URL
url <- utils::URLencode(
glue::glue('https://geocoding.geo.census.gov/geocoder/geographies/onelineaddress?address={address}&benchmark=4&vintage=4')
)
# GET the Request
response <- httr::GET(url)
content <- httr::content(response)
# Check for Matches
if(length(content$result$addressMatches) == 0){
stop("No matches found for this address")
}
# Get the Census Block GEOID for the First Result
GEOID <- content$result$addressMatches[[1]]$geographies$`2010 Census Blocks`[[1]]$GEOID
return(GEOID)
}
> cxy_geoid("4643 Lindell Blvd St Louis MO")
[1] "295101124002011"
I'm leaving this open for now as a reminder to implement all of the census bureau API endpoints.
@bransonf - would the idea be that we'll have to iterate over each address to return the block ID?
@chris-prener - in its current state, yes. But I do believe there is an equivalent batch endpoint with this sort of data.
Hi all -- have you found a way to pull block group GEOID in a batch request as a part of the cxy_geocode function? While the code @bransonf provided above is helpful, I'm having trouble iterating it over a large dataset. Thanks a bunch!
Thanks for checking in with us @abyrum - we should be able to offer something on this front next spring I hope!
Great, thanks @chris-prener!