专栏名称: EasyCharts
EasyCharts,易图表,我们将定期推送各种数据可视化与分析教程,包括Excel(Power BI)、Origin、Sigmaplot、GraphPad、R、Python、Matlab、Tableau、D3.js等。
目录
相关文章推荐
前端早读课  ·  【第3532期】错误页面演变史:如何让失误变 ... ·  15 小时前  
前端大全  ·  Cursor 内部工作原理 ·  昨天  
龙视新闻联播  ·  清凉在龙江丨四季皆可游 昼夜都精彩 ·  昨天  
龙视新闻联播  ·  清凉在龙江丨四季皆可游 昼夜都精彩 ·  昨天  
前端早读课  ·  【第3531期】了解声明式 Web推送 ·  昨天  
前端大全  ·  前端行情变了,差别真的挺大。。。 ·  2 天前  
51好读  ›  专栏  ›  EasyCharts

ggmap: 使用 ggplot2 进行空间可视化绘图(下篇)

EasyCharts  · 公众号  · 前端  · 2017-07-11 12:02

正文

请到「今天看啥」查看全文


这些实际上是 Mercator 对 1984 年世界大地测量系统(WGS84)的普遍预测,这是 Google Maps 使用球形地球模型的来源。当 output=“more” 时,会返回一个较大的数据集,该数据集提供了更多的 Google 地理编码信息:

> geocode("baylor university", output = "more")

lon lat type loctype address north south east

1 -97.11441 31.54872 university approximate [long address] 31.55823 31.53921 -97.0984

west postal_code country administrative_area_level_2

1 -97.13042 76706 united states mclennan

administrative_area_level_1 locality street streetNo point_of_interest

1 texas waco s 5th st 1311

#在个人电脑上运行后情况

> library(ggmap)

#谷歌地图API服务条款。Google Maps API Terms of Service: http://developers.google.com/maps/terms.


> geocode("baylor university", output = "more")

Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=baylor%20university&sensor=false

lon      lat          type     loctype

1 -97.11431 31.54984 establishment approximate

address    north    south      east      west

1 1301 s university parks dr, waco, tx 76798, usa 31.55119 31.54849 -97.11297 -97.11566

street_number                        route locality administrative_area_level_2

1          1301 South University Parks Drive     Waco             McLennan County

administrative_area_level_1       country postal_code

1                       Texas United States       76798

特别是,各级政府机构的报告。若设定 output=“all" 时,则返回整个 JSON 对象,该对象由谷歌地理编码 API 解析。参考下面的代码。

## output = "all"的时,返回详细信息情况(节选一部分)。

> library(ggmap)

> geocode("baylor university", output = "all")

Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=baylor%20university&sensor=false

$results

$results[[1]]

$results[[1]]$address_components

$results[[1]]$address_components[[1]]

$results[[1]]$address_components[[1]]$long_name

[1] "1301"

$results[[1]]$address_components[[1]]$short_name

[1] "1301"

$results[[1]]$address_components[[1]]$types

[1] "street_number"

地理编码 API 有一些防止滥用的要求限制。

一个未指明的短期 rate(见图文) 以及 24 小时 2500 个请求的限制,通过隐藏的全局变量可以在一定程度上进行检测。

GooglegGocodeQueryCount 和输出函数 geocodequerycheck,geocode 使用它们监控自己的进度,要么(1)根据使用情况调整运行速度或(2)如果查询超出限制则弹出一个错误提示,值得注意是,revgeocode 共享相同的请求响应,同时是由相同的变量和函数监测。

要了解更多关于谷歌地理编码、距离矩阵,和 API 方向的使用规则,请参考文献中列出的网站。

002.
revgeocode 函数

在某些情况下,将经度 / 纬度坐标转换为物理地址是很有用的,使用 revgeocode 函数这样做是可能的,不过这将依赖于 Google 地理编码 API。

> gc

> (gc

[1] -97.11441 31.54872

> revgeocode(gc)

[1] "S 1st St, Baylor University, Waco, TX 76706, USA"

Like geocode , more output can be provided as well –

> revgeocode(gc, output = "more")

address route establishment neighborhood locality

1 [long address] S 1st St Baylor University Baylor Waco

administrative_area_level_2 administrative_area_level_1 country postal_code

1 McLennan Texas United States 76706

因此,除了反向地理编码的物理位置 (即: 地址),revgeocode 可以报告在不同尺寸级别上的情况。最后,output="all" 选项可以返回 Google 报告的整个 JSON 对象。







请到「今天看啥」查看全文