Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解析对查询的XML响应_Xml_R_Api_Census - Fatal编程技术网

解析对查询的XML响应

解析对查询的XML响应,xml,r,api,census,Xml,R,Api,Census,我试图提取大量经纬线的县fips编号。我可以从FCC API获取数据,但我很难将其读入R 例如,当我在R中运行以下代码时: library(httr) fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false")) result <- content(fips, as = "parsed") res

我试图提取大量经纬线的县fips编号。我可以从FCC API获取数据,但我很难将其读入R

例如,当我在R中运行以下代码时:

library(httr)
fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false"))

result <- content(fips, as = "parsed")

result
库(httr)

fips您必须解析从该API返回的
XML

library("httr")
library("XML")
fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false"))
result <- content(fips, as = "parsed")
> xmlToList(xmlParse(result))$County["FIPS"]
   FIPS 
"53073" 
库(“httr”)
库(“XML”)

fips另一个选项是使用以下链接中的代码:

#FCC的普查区块转换API
# http://www.fcc.gov/developers/census-block-conversions-api
安装程序包(“RCurl”)
安装软件包(“RJSONIO”)
拉特朗基普
library("httr")
library("XML")
fips <- GET("http://data.fcc.gov/api/block/find", query = list(latitude = 48.9905, longitude = -122.2733, showall="false"))
result <- content(fips, as = "parsed")
> xmlToList(xmlParse(result))$County["FIPS"]
   FIPS 
"53073" 
# FCC's Census Block Conversions API
# http://www.fcc.gov/developers/census-block-conversions-api

install.packages("RCurl")
install.packages("RJSONIO")

latlong2fips <- function(latitude, longitude) {
  url <- "http://data.fcc.gov/api/block/find?format=json&latitude=%f&longitude=%f"
  url <- sprintf(url, latitude, longitude)
  json <- RCurl::getURL(url)
  json <- RJSONIO::fromJSON(json)
  as.character(json$County['FIPS'])
}

# Orange County
latlong2fips(latitude=28.35975, longitude=-81.421988)