我想从我数据中的地址中获得一个城市的人口普查代码。问题是我找不到适用于佛罗里达州盖恩斯维尔的shapefile。所以我试着使用接受调查的人的地址来获取人口普查代码,一旦我有了人口普查代码,我就会substr到前11位,以匹配tidycensus包的地理I,它给出了最低层次的县人口普查和shapefiles。
因为我只有城市居民的大地水准面,所以我会得到那些shapefiles,而不是整个县。因此,我执行以下操作只是为了获得人口普查代码:
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)指向the data is here的链接。我有大约9200个地址要解析,这是在大约1800年发生的。看了看这个错误,我发现需要一些超时设置,不幸的是,我不知道该怎么做。
我需要shapefiles来做我个人项目的关键部分。
发布于 2020-03-08 05:38:22
所有的标点符号都必须从gainsville_df2$Address向量中删除。call_geolocator函数没有或者如果有,则会在由标点符号组成的字符串上不规则地工作,并且经常会在带有标点符号的地址上抛出HTTP500错误,如#或{}等等。因此,更好的做法是使用as.character(stringr::str_replace_all(gainsville_df2$Address, "[[:punct:]]", " "))函数删除所有标点符号。别担心,即使没有标点符号,地理定位器功能仍然会给出正确的人口普查代码。它只查找街道名称、号码、街区、城市和州。
https://stackoverflow.com/questions/60555964
复制相似问题