0

I am trying to obtain the Census tract information using the R tigris package and following the process as detailed here: Retrieve Census tract from Coordinates My code was working till last month when it suddenly stopped working and returns NA for any lat, lon combination. I looked up the documentation on tigris package and do not see what I am doing wrong. I also updated my tigris package but the following command keeps returning NA.

 library(tigris)
 call_geolocator_latlon(40.61847, -74.02123)

Does anyone know if the package has been deprecated?

4

2 回答 2

2

尝试这个

replacement_function <- function (lat, lon, benchmark, vintage) 
{
  if (missing(benchmark)) {
    benchmark <- "Public_AR_Census2020"
  }
  else {
    benchmark <- benchmark
  }
  if (missing(vintage)) {
    vintage <- "Census2020_Census2020"
  }
  else {
    vintage <- vintage
  }
  call_start <- "https://geocoding.geo.census.gov/geocoder/geographies/coordinates?"
  url <- paste0("x=", lon, "&y=", lat)
  benchmark0 <- paste0("&benchmark=", benchmark)
  vintage0 <- paste0("&vintage=", vintage, "&format=json")
  url_full <- paste0(call_start, url, benchmark0, vintage0)
  r <- httr::GET(url_full)
  httr::stop_for_status(r)
  response <- httr::content(r)
  return(response$result$geographies$`Census Blocks`[[1]]$GEOID)
  if (length(response$result$geographies$`2020 Census Blocks`[[1]]$GEOID) ==
      0) {
    message(paste0("Lat/lon (", lat, ", ", lon, ") returned no geocodes. An NA was returned."))
    return(NA_character_)
  }
  else {
    if (length(response$result$geographies$`2020 Census Blocks`[[1]]$GEOID) >
        1) {
      message(paste0("Lat/lon (", lat, ", ", lon, ") returned more than geocode. The first match was returned."))
    }
    return(response$result$geographies$`2020 Census Blocks`[[1]]$GEOID)
  }
}

您可以像调用 call_geolocator_latlon() 函数一样调用此函数

replacement_function(40.61847, -74.02123)
于 2021-03-12T20:29:08.160 回答
1

根据官方页面,2021 年 1 月和 2 月是形状更新的月份。这些将从 3 月开始提供。

于 2021-01-19T17:21:34.000 回答