2

我想从我数据中的地址中获取一个城市的人口普查代码。问题是我找不到佛罗里达州盖恩斯维尔的可用 shapefile。所以我试图使用参加调查的人的地址来获取人口普查代码,一旦我有了人口普查代码,我会substr使用前 11 位数字来匹配tidycensus包裹的 GEOID,这使县人口普查和 shapefile 降到最低的层次结构。

因为我只有城市居民的 GEOID,所以我会得到那些 shapefile,而不是整个县。所以我做了以下只是为了获得人口普查代码:

library(tigris)
library(readr)

gainsville_df2 <- readr::read_csv("311_Service_Requests__myGNV_.csv")

#gainsville_df2 is the dataframe of the csv file
jio<- apply(gainsville_df2["Address"], 1, function(row) tigris::call_geolocator(row, "Gainesville", "FL", zip = NA))

#It ran for ~1.5 hours, parsing through 1892 addresses, then I got this error out of nowhere:

#Error in tigris::call_geolocator(row, "Gainesville", "FL", zip = NA) : 
#  Internal Server Error (HTTP 500).
#Called from: httr::stop_for_status(r)

数据链接在这里。我有 ~9200 个地址要解析,这发生在 ~1800 年。环顾四周,我发现需要一些超时设置,不幸的是,我不知道该怎么做。

我需要 shapefile 来完成我个人项目的关键部分。

4

1 回答 1

2

必须从gainsville_df2$Address向量中删除所有标点符号。call_geolocator函数没有或如果有,则在标点符号的刺上不规则地工作,并且通常会在带有标点符号的地址上引发 HTTP 500 错误,如 # 或 { } 等等。因此,使用该as.character(stringr::str_replace_all(gainsville_df2$Address, "[[:punct:]]", " "))功能删除所有标点符号是一个更好的做法。不用担心,即使没有标点符号,地理定位器功能仍然会提供正确的人口普查代码。它只查找街道名称、编号、街区、城市和州。

于 2020-03-07T21:38:22.233 回答