【问题标题】:How do I convert County FIPS to Lat-Long coordinates in R or Python?如何在 R 或 Python 中将县 FIPS 转换为经纬度坐标?
【发布时间】:2019-10-31 12:27:48
【问题描述】:

由于被世界卫生组织的 IARC 列为可能的致癌物,草甘膦最近备受关注。我对美国的农药使用模式感到好奇,并在 R-Shiny 中使用交互式地图绘制了这些数据,例如使用传单。

可在此处找到县级农药使用估算:https://water.usgs.gov/nawqa/pnsp/usage/maps/county-level/

使用州/县 FIPS 代码报告数据。我需要经纬度坐标来显示数据。

似乎可以很容易地从经纬度转换为 FIPS,如下面的 API 所示:https://geo.fcc.gov/api/census/

反方向怎么走?

【问题讨论】:

标签: r shiny leaflet geo


【解决方案1】:

我发现需要使用 here.com 的 REST API 的五个选项(如下)的解决方案。我首先使用来自library(tigris) 的表fips_codes 交叉引用USGS 表中的FIPS 代码与县和州名称。这让我可以将名字放在地址行中,例如Boulder County, CO。接下来,我写了一个小函数here_now,示例用法为:

here_now("Boulder+County,+CO") # $lat: 40.08791; $lon: -105.3447

实现是使用来自library(jsonlite)fromJSON 调用REST API

here_now <- function(searchtext) {

    AppCode <- getOption("hereAppCode")
    AppID <- getOption("hereAppID")       

    rootURL <- "https://geocoder.api.here.com/6.2/geocode.json?"
    app_id = paste("app_id", AppID, sep="=")
    app_code = paste("app_code", AppCode, sep="=")
    searchtext = paste("searchtext", searchtext, sep="=")

    request <- paste(paste(rootURL, app_id, sep=''), app_code, searchtext, sep="&")
    response = fromJSON(request)

    res <- list()
    res$lat <- response$Response$View$Result[[1]]$Location$NavigationPosition[[1]]$Latitude
    res$lon <- response$Response$View$Result[[1]]$Location$NavigationPosition[[1]]$Longitude

    res
}

此外,我使用了 FCC 的反向地理编码 API 来验证:https://geo.fcc.gov/api/census/

我尝试过的地理编码选项包括: - 通过 ggmap 的谷歌 API(需要 API 密钥,需要信用卡) - mapquest API(需要 API 密钥,不需要信用卡) - 数据科学工具包的 RDSK 实施 - 通过同名的 R 包提供 Geonames 服务 - Here APIs(需要 AppID 和 AppCode,免费增值模式)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 2021-07-18
    • 2015-07-13
    • 2019-11-18
    • 2010-10-11
    • 2017-07-02
    • 2020-02-23
    相关资源
    最近更新 更多