我正在为一些地形图绘制改进的山体阴影.记录的基本山体阴影工作流程image()是:
require(raster)
alt = getData('alt', country='CHE')
slope = terrain(alt, opt='slope')
aspect = terrain(alt, opt='aspect')
hill = hillShade(slope, aspect, 40, 270)
plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
plot(alt, col=rainbow(25, alpha=0.35), add=TRUE)
Run Code Online (Sandbox Code Playgroud)
此图像显示plot(hill..)之前plot(alt..)应用:

该方法创建一个实心的灰色底层山体阴影,其上半透明地绘制其他数据层(例如高程阴影).这种方法的问题是(a)平坦地形的中性色(RBG(202,202,202),'#CAPACA')严重遮蔽整个模型,这(b)防止多个阴影层,例如'瑞士山体阴影使用'方法.
我可以想象一个将光栅转换为矩阵并将山体阴影作为数值乘数应用于其他层的亮度的解决方法,但这看起来并不优雅(尽管我可能错了).我想知道是否有人在这方面有任何想法或(最好)经验?提前致谢.
没有经验,但为什么不给灰色底图一个取决于斜率的alpha值?这是我的尝试:
# before
require(raster)
alt = getData('alt', country='CHE')
slope = terrain(alt, opt='slope')
aspect = terrain(alt, opt='aspect')
hill = hillShade(slope, aspect, 40, 270)
plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
plot(alt, col=rainbow(25, alpha=0.35), add=TRUE)
Run Code Online (Sandbox Code Playgroud)

如你所说,非常黑暗.
# after
grayalphas <- seq(-1,1,by=.01)^2*100
grayalphas[grayalphas==100] <- 99
plot(hill, col=paste0(grey(0:100/100),sprintf("%.2d",grayalphas)), legend=FALSE, main='Switzerland')
plot(alt, col=rainbow(25, alpha=0.35), add=TRUE)
Run Code Online (Sandbox Code Playgroud)

我将灰色alphas设置为抛物线形状,灰度值为.5时最小值,灰度值为0或1时最大值为99.如果你选择这样的东西,你会想要修改等级,但它很容易实现.另外,你会想要比我在alphas中付出更多努力,因为我的是严格的数字而不是十六进制.
[编辑]我发现了一个漂亮的函数添加阿尔法,addTrans() 这里在萨沙Epskamp的答案.这保留了抛物线,但它的范围从中间的0到极端的255.
grayalphas <- seq(-1,1,length=101)^2*255
plot(hill, col=addTrans(grey(0:100/100),grayalphas), legend=FALSE, main='Switzerland')
plot(alt, col=rainbow(25, alpha=0.35), add=TRUE)
Run Code Online (Sandbox Code Playgroud)
