Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【数据】卫星图像的效果出不来 #62

Closed
XiangyunHuang opened this issue Sep 12, 2019 · 3 comments
Closed

【数据】卫星图像的效果出不来 #62

XiangyunHuang opened this issue Sep 12, 2019 · 3 comments

Comments

@XiangyunHuang
Copy link
Owner

XiangyunHuang commented Sep 12, 2019

第6章 数据案例之背景地图

demo("eqMaps", package = "MSG")

其实是如下一段代码

library(RgoogleMaps)
data(eq2010, package = "MSG")
boundingbox = qbbox(lon = eq2010[, "long"], lat = eq2010[, "lat"])
EQMap = GetMap.bbox(boundingbox$lonR, boundingbox$latR, destfile = "EQ.png", maptype = "satellite", zoom = 6)

PlotOnStaticMap(EQMap,
   lon = eq2010$long, lat = eq2010$lat, pch = 20, col = "red",
   verbose = 0
 )
bgcol = rgb(255, 0, 0, alpha = 95, maxColorValue = 255)

PlotOnStaticMap(EQMap,
   lon = eq2010$lon, lat = eq2010$lat, pch = 21, bg = bgcol,
   col = "darkred", cex = 1.25 * eq2010$ms, verbose = 0
)

默认情形下,地图是基于 OSM 的,即 OpenStreetMap,Google Map 的卫星图像出不来 @pzhaonet @yihui 你们在国外 Google Map 应该用起来很方便,不妨抽空查找下原因

  1. 原因可能是 Google Map API,也可能是代码需要升级
  2. 第二个问题是目前卫星图像看起来精度很低的样子

下面是目前代码执行后输出的结果

bubble

osm

@XiangyunHuang
Copy link
Owner Author

凡是涉及谷歌地图的服务,都应该去掉,国内大部分人都无法使用的,应该用 leaflet/mapbox 代替

@yihui
Copy link
Collaborator

yihui commented Sep 19, 2019

可以。

@XiangyunHuang
Copy link
Owner Author

XiangyunHuang commented Sep 20, 2019

突然想到卫星地图可以用地形海拔数据替换,举个栗子

cameroon-elevation

library(sp)
library(raster)
# CMR  喀麦隆及其周边地区地图
cmr_map <- getData('GADM', country='CMR', level = 1) # 省界
# getData('ISO3') # 国家代码
cmr_alt <- getData('alt', country='CMR', mask=TRUE) 
# alt 是 altitude (海拔)的缩写 函数返回 raster 类型数据对象
png(filename = "cameroon-elevation.png", width = 1200, height = 1000, res = 200, type = "cairo")
par(mar = c(4, 4, 0.5, 2))
plot(cmr_alt, xlab = "LONGITUDE", ylab = "LATITUDE")
plot(cmr_map, add = TRUE, border = "gray")
dev.off()

最后填上数据点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants