【问题标题】:R: GEOCODE()- Returns short coordinatesR: GEOCODE() - 返回短坐标
【发布时间】:2020-10-21 12:42:23
【问题描述】:

我的任务是使用 GEOCODE() 函数从 R 返回坐标(经度、纬度)。 API 和安装包等一切顺利。

但是,在测试坐标时,我注意到 R 返回了 short (lon, lat) 例如,对于“LV-2114”,R 返回了短版本:

> geocode("LV-2114", output = "latlon", "latlona", source="google", 
       full_results = TRUE, return_type = 'geographies',method = 'census')

#> A tibble: 1 x 2 
#>    lon   lat  
#>    23.9  56.8

对于“LV-2114”,经纬度应为 (23.94453,56.79256)。我输入的其他地方也是如此。

我很确定这是我犯的一些错误。 如何返回长坐标?

【问题讨论】:

  • 我认为这只是 tibble 打印。你能试试df$lon 并检查输出吗
  • @AbdessabourMtk 感谢您的回复。你的意思是一行?geocode(“LV-2114”,df$lon)。如果是,则返回错误“df$lon 中的错误:'closure' 类型的对象不是可子集的”。还是你的意思是别的?
  • 我的意思是df <- goecode(.......) 然后是df$lon
  • 而且绝对是 tibble 舍入
  • 如果你想让它们变成一个向量,只需写as.data.frame(df)[1, , drop=T]

标签: r geocoding geocode


【解决方案1】:

您遇到的错误只是 print.tibble 对数值进行舍入的默认行为。

df <- geocode("LV-2114", output = "latlon", "latlona", source="google", 
       full_results = TRUE, return_type = 'geographies',method = 'census')

as.data.frame(df)[,, drop=T]
#> $lon
#> [1] 23.94453
#> 
#> $lat
#> [1] 56.79256
# or
as.matrix(df)

#>           lon      lat
#> [1,] 23.94453 56.79256
#> [2,] 23.94453  2.00000

当您要在计算中使用 tibble 中的值时,它将使用非舍入值,只有在打印时才会舍入值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多