I am using a function I found here, r - Convert Lat/Lon to County Codes using FCC API - Stack Overflow , to convert lat / long points to census tracts.
I have a dataset of 43k rows. It works great for about 500 rows and then it crashes and assigns the remaining 42500 rows to the same tract, which is not correct. Here is the error message I get and the code below is what I am using:
Error in open.connection(con, "rb") :
cannot open the connection to 'https://geo.fcc.gov/api/census/area?lat=35.944191&lon=-81.175762&format=json'
geo2fips <- function(latitude, longitude) {
url <- "https://geo.fcc.gov/api/census/area?lat=%f&lon=%f&format=json"
res <- jsonlite::fromJSON(sprintf(url, latitude, longitude))[["results"]][["block_fips"]]
}
for (i in 1:nrow(tract_data)) {
tract_data$tracts[i] = geo2fips(tract_data1$Latitude[i], tract_data1$Longitude[i])
}
Any insight would be much appreciated. Thank you