首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R call_geolocator_latlon函数返回NA

R call_geolocator_latlon函数返回NA
EN

Stack Overflow用户
提问于 2021-01-20 00:25:45
回答 2查看 325关注 0票数 0

我正在尝试使用R tigris包获取人口普查区域信息,并遵循这里详细介绍的过程:Retrieve Census tract from Coordinates我的代码一直工作到上个月,它突然停止工作,并返回NA,用于任何lat,lon组合。我查阅了tigris包上的文档,没有发现我做错了什么。我也更新了我的tigris包,但是下面的命令总是返回NA。

代码语言:javascript
复制
 library(tigris)
 call_geolocator_latlon(40.61847, -74.02123)

有人知道这个包是否已经被弃用了吗?

EN

回答 2

Stack Overflow用户

发布于 2021-03-13 04:29:08

尝尝这个

代码语言:javascript
复制
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()函数的方式相同

代码语言:javascript
复制
replacement_function(40.61847, -74.02123)
票数 2
EN

Stack Overflow用户

发布于 2021-01-20 01:21:34

根据official page的说法,2021年1月和2月是形状更新的月份。这些将从三月份开始提供。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65795510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档