GEE案例

GEE计算山体阴影

2019-01-03  本文已影响0人  赤豆冰棍

使用高程数据来计算山体阴影

主要功能

使用高程数据来计算不同角度的山体阴影,并且在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');
}

步骤分析

  1. 定义函数radians(img)实现角度弧度转换
  2. 定义函数hillshade(az, ze, slope, aspect)来计算山体阴影
  3. 创建ee对象,通过ee.Alogrithms.Terrain来计算坡度坡向等地形度量指标
  4. ee对象特定图层提取
  5. 地图对象设置显示中心,缩放等级
  6. 按照角度循环计算山体阴影,添加计算的山体阴影图层,设置显示参数

主要方法

  1. 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()

  1. 山体阴影计算
    hillshade(az, ze, slope, aspect)
  1. 按照60°为步长,计算从0到360度的不同方位角的山体阴影
上一篇 下一篇

猜你喜欢

热点阅读