Census Batch Geocoding API with source addresses in data frame (not CSV) in R

假装没事ソ 提交于 2019-12-04 18:10:51

if you're willing to write the data to a temp file...

library("httr")
a = c(1, 2, 3) 
b = c("125 Worth Street", "258 Broadway", "8 Centre Street") 
c = rep("New York", 3) 
d = rep("NY", 3)
e = c("10013","10007","10007")
addresses = data.frame(a,b,c,d,e)
colnames(addresses) <- c("Unique_ID","Street address","City","State","ZIP")
apiurl <- "http://geocoding.geo.census.gov/geocoder/geographies/addressbatch"
file <- tempfile(fileext = ".csv")
write.csv(addresses, file, row.names = FALSE)
req <- POST(apiurl, body=list(
    addressFile = upload_file(file), 
    benchmark = "Public_AR_Census2010",
    vintage = "Census2010_Census2010"
  ), 
  encode="multipart"
)
content(req, "text", encoding = "UTF-8")


#> [1] "\"3\",\"8 Centre Street, New York, NY, 10007\",\"Match\",\"Non_Exact\",\"8 Centre St, NEW YORK, NY, 10013\",\"-74.00442,40.712765\",\"59660429\",\"R\",\"36\",\"061\",\"002900\",\"4019\"\n\"2\",\"258 Broadway, New York, NY, 10007\",\"No_Match\"\n\"1\",\"125 Worth Street, New York, NY, 10013\",\"Match\",\"Exact\",\"125 Worth St, NEW YORK, NY, 10013\",\"-74.0027,40.715446\",\"59660405\",\"L\",\"36\",\"061\",\"003100\",\"1012\"\n\"Unique_ID\",\"Street address, City, State, ZIP\",\"No_Match\"\n"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!