使用高程数据来计算山体阴影
主要功能
使用高程数据来计算不同角度的山体阴影,并且在map中添加为多个图层展示。
代码
// Hillshade example. This is a demonstration of computing
// a hillshade from terrain data and displaying multiple
// layers based on multiple view geometries. Hillshade
// creation is also provided by ee.Terrain.hillshade().
// Define a function to convert from degrees to radians.
function radians(img) {
return img.toFloat().multiply(Math.PI).divide(180);
}
// Define a function to compute a hillshade from terrain data
// for the given sun azimuth and elevation.
function hillshade(az, ze, slope, aspect) {
// Convert angles to radians.
var azimuth = radians(ee.Image(az));
var zenith = radians(ee.Image(ze));
// Note that methods on images are needed to do the computation.
// i.e. JavaScript operators (e.g. +, -, /, *) do not work on images.
// The following implements:
// Hillshade = cos(Azimuth - Aspect) * sin(Slope) * sin(Zenith) +
// cos(Zenith) * cos(Slope)
return azimuth.subtract(aspect).cos()
.multiply(slope.sin())
.multiply(zenith.sin())
.add(
zenith.cos().multiply(slope.cos()));
}
// Compute terrain meaasures from the SRTM DEM.
var terrain = ee.Algorithms.Terrain(ee.Image('CGIAR/SRTM90_V4'));
var slope = radians(terrain.select('slope'));
var aspect = radians(terrain.select('aspect'));
// For loops are needed for control-flow operations on client-side
// operations. Here Map.addLayer() is a client operation that needs
// to be performed in a for loop. In general, avoid for loops
// for any server-side operation.
Map.setCenter(-121.767, 46.852, 11);
for (var i = 0; i < 360; i += 60) {
Map.addLayer(hillshade(i, 60, slope, aspect), {}, i + ' deg');
}
步骤分析
- 定义函数radians(img)实现角度弧度转换
- 定义函数hillshade(az, ze, slope, aspect)来计算山体阴影
- 创建ee对象,通过ee.Alogrithms.Terrain来计算坡度坡向等地形度量指标
- ee对象特定图层提取
- 地图对象设置显示中心,缩放等级
- 按照角度循环计算山体阴影,添加计算的山体阴影图层,设置显示参数
主要方法
- img.toFloat()
Casts the input value to a 32-bit float.
Arguments:
this:value (Image):
The image to which the operation is applied.
Returns: Image
将输入影像投影为32bit浮点型。
本例中,转换为浮点型之后,使用了Math.PI和除法divide()实现角度弧度转换函数radians()
- 山体阴影计算
hillshade(az, ze, slope, aspect)
-
方位角计算az
将输入的方位角由角度转化为弧度值 -
高度角计算ze
将输入的高度角由角度转化为弧度值 -
山体阴影计算
Hillshade = cos(Azimuth - Aspect) * sin(Slope) * sin(Zenith) + cos(Zenith) * cos(Slope)
- 按照60°为步长,计算从0到360度的不同方位角的山体阴影
- for 循环实现对i的计算山体阴影时输入方位角的控制
- addLayer添加图层,使用i+'deg'来对图层进行命名
网友评论