我正在尝试使用R tigris包获取人口普查区域信息,并遵循这里详细介绍的过程:Retrieve Census tract from Coordinates我的代码一直工作到上个月,它突然停止工作,并返回NA,用于任何lat,lon组合。我查阅了tigris包上的文档,没有发现我做错了什么。我也更新了我的tigris包,但是下面的命令总是返回NA。
library(tigris)
call_geolocator_latlon(40.61847, -74.02123)有人知道这个包是否已经被弃用了吗?
发布于 2021-03-13 04:29:08
尝尝这个
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-01-20 01:21:34
根据official page的说法,2021年1月和2月是形状更新的月份。这些将从三月份开始提供。
https://stackoverflow.com/questions/65795510
复制相似问题