R中的地图地块更好的山体阴影 [英] Better hillshading for map plots in R

查看:84
本文介绍了R中的地图地块更好的山体阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为某些地形图绘制改进的山体阴影. image()中记录的基本的hillshade工作流程是:

I'm working on improved hillshading for some topographical map plots. The basic hillshade workflow documented in image() is:

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)

此图显示在应用plot(alt..)之前的plot(hill..):

This image shows plot(hill..) before plot(alt..) is applied:

该方法会创建一个山形阴影的纯灰色底层,在该图层上半透明地绘制其他数据层(例如高程阴影).这种方法的问题是(a)平坦地形的中性色(RBG(202,202,202),'#CACACA')严重遮盖了整个模型,这(b)防止了多个阴影分层,例如瑞士山体阴影" 方法.

The method creates a solid grey under-layer of hillshades on which other data layers (e.g. elevation shading) are plotted semi-transparently. The problem with this approach is (a) that the neutral colour for flat terrain (RBG (202,202,202), '#CACACA') severely shades the whole model, which (b) prevents multiple shade layering, such as used by the 'Swiss hillshade' approach.

我可以想象出一种解决方法,该方法可以将栅格转换为矩阵,并将山影作为数值乘数应用于其他图层的亮度,但这似乎并不十分优雅(尽管我可能是错的).我想知道是否有人在这方面有任何想法或(最好是)经验?预先感谢.

I can imagine an workaround that converts rasters to matrices and applies hillshading as a numerical multiplier to the brightness of other layers, but this doesn't seem very elegant (although I may be wrong). I wonder if anyone has any ideas or (preferably) experience in this area? Thanks in advance.

推荐答案

对此没有经验,但是为什么不给灰色底图一个依赖于坡度的alpha值呢?这是我的尝试:

No experience with this, but why not give the gray undermap an alpha value that depends on slopes? Here's my try:

# 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)

正如您所说,非常黑暗.

As you say, very dark.

# 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)

我将灰度alpha设置为抛物线形状,灰度值为0.5时最小值为0,灰度值为0或1时最大值为99.等等,但是很容易实现.另外,您将要比我在alpha上付出更多的努力,因为我的代码严格是数字而不是十六进制.

I set the gray alphas to have a parabolic shape, with minimum where the gray value is .5 and max of 99 at gray values of 0 or 1. If you choose something like this, you'll want to tinker with levels, etc, but it is easy to implement. Plus you'll want to put more effort than I did into the alphas, as mine are strictly numeric and not hex.

我发现了一个添加alpha的漂亮函数,addTrans()

I found a nifty function for adding alphas, addTrans() here in Sacha Epskamp's answer. This keeps the parabola, but it ranges from 0 in the middle to 255 on the extremes.

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)

这篇关于R中的地图地块更好的山体阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆