问题描述
我有一个任务,要使用GEOCODE()函数从R返回坐标(lon,lat)。 使用API和安装软件包等一切都可以顺利进行。
但是,在测试坐标时,我注意到R返回短(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)。我输入的其他地方也是如此。
我很确定这是我犯的一些错误。 如何返回长坐标?
解决方法
您遇到的错误只是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
当要在计算中使用小节内的值时,它将仅使用未舍入的值进行舍入。