【问题标题】:R - Building a dataframe using Country,continent, latitude and longitudeR - 使用国家、大陆、纬度和经度构建数据框
【发布时间】:2018-01-11 17:37:05
【问题描述】:

我有一个数据框,其中有一列包含国家/地区列表,我希望获取该国家/地区的大陆名称、纬度和经度。

例如,

df <- data.frame(CountryName = c("Austria", "Czech Republic", "Finland"))

我正在寻找一个包含大陆、纬度和经度的数据框。

library(countrycode)
library(geocode)

df$continent <- as.factor(countrycode(sourcevar = df[, "CountryName"], origin = "country.name", destination = "continent"))

所以,我的数据框中现在有了大陆。

geocode("Austria") 在 R 中返回 lat 和 long。 你能指导我在 Dataframe 中获取它吗?

谢谢。

【问题讨论】:

    标签: r geocoding


    【解决方案1】:

    原则上,您可以一次从ggmap(我知道没有包geocode)向所有国家/地区拨打geocode(),然后像这样使用cbind

    cbind(df, ggmap::geocode(as.character(df[, "CountryName"]), force = FALSE))
    # Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Austria&sensor=false
    # Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Czech%20Republic&sensor=false
    # Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Finland&sensor=false
    #      CountryName continent      lon      lat
    # 1        Austria    Europe 14.55007 47.51623
    # 2 Czech Republic    Europe 15.47296 49.81749
    # 3        Finland    Europe 25.74815 61.92411
    

    但是,人们经常会收到有关 OVER_QUERY_LIMIT 的警告消息。为了解决这个问题,可能需要一个 API 密钥,c.f. Getting OVER QUERY LIMIT after one request with geocode.

    【讨论】:

    • 是的,我们如何解决这个问题 (OVER_QUERY_LIMIT)。
    【解决方案2】:

    通过注册您自己的 Google API 密钥来解决“OVER QUERY LIMIT”问题:Google API sign-up

    查看相关的堆栈溢出问题:stackoverflow.com/questions/36175529

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-10
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多