当前位置:   article > 正文

GEE基础学习——Hillshade山阴的计算和显示

hillshade

很多时候我们需要计算山阴主要通过ee.Terrain.hillshade()来实现,具体代码如下:

  1. // Hillshade example. This is a demonstration of computing
  2. // a hillshade from terrain data and displaying multiple
  3. // layers based on multiple view geometries. Hillshade
  4. // creation is also provided by ee.Terrain.hillshade().
  5. // Define a function to convert from degrees to radians.
  6. function radians(img) {
  7. return img.toFloat().multiply(Math.PI).divide(180);
  8. }
  9. // Define a function to compute a hillshade from terrain data
  10. // for the given sun azimuth and elevation.
  11. function hillshade(az, ze, slope, aspect) {
  12. // Convert angles to radians.
  13. var azimuth = radians(ee.Image(az));
  14. var zenith = radians(ee.Image(ze));
  15. // Note that methods on images are needed to do the computation.
  16. // i.e. JavaScript operators (e.g. +, -, /, *) do not work on images.
  17. // The following implements:
  18. // Hillshade = cos(Azimuth - Aspect) * sin(Slope) * sin(Zenith) +
  19. // cos(Zenith) * cos(Slope)
  20. return azimuth.subtract(aspect).cos()
  21. .multiply(slope.sin())
  22. .multiply(zenith.sin())
  23. .add(
  24. zenith.cos().multiply(slope.cos()));
  25. }
  26. // Compute terrain meaasures from the SRTM DEM.
  27. var terrain = ee.Algorithms.Terrain(ee.Image('CGIAR/SRTM90_V4'));
  28. var slope = radians(terrain.select('slope'));
  29. var aspect = radians(terrain.select('aspect'));
  30. // For loops are needed for control-flow operations on client-side
  31. // operations. Here Map.addLayer() is a client operation that needs
  32. // to be performed in a for loop. In general, avoid for loops
  33. // for any server-side operation.
  34. Map.setCenter(-121.767, 46.852, 11);
  35. for (var i = 0; i < 360; i += 60) {
  36. Map.addLayer(hillshade(i, 60, slope, aspect), {}, i + ' deg');
  37. }

这个代码的具体思路是首先,及建立一个函数,完成有角度向弧度的转换!

其次就是定义一个新的函数,来计算太阳方位角和高程并通过返回值计算 Hillshade = cos(Azimuth - Aspect) * sin(Slope) * sin(Zenith) +cos(Zenith) * cos(Slope),另外需要注意,我们算数的(+, -, /, *)是不能执行的,因为这里没有用到image.expression进行,也没有合适的波段去进行选择,所以要用英文字母的加减乘除。

剩余的地方基本上就是通过影像分别计算slope和aspect然后进行函数的hillshade的函数计算。

最后进行图像的中心位置显示。

此外本程序还设置了一个循环,也就是每隔60度进行一个方向的展示:

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/768939
推荐阅读
相关标签
  

闽ICP备14008679号