Line 19: LAI.setDefaultProjection(...).Float is not a function

这里我们需要注意的是这个设定默认投影的坐标,因为这里函数中有三个参数,所以如果我们不设定其中一个参数就一定要用null去替代,或者我们可以使用字典类型分别设定,这样就不用担心错误将第三个参数的值传入到第二个参数值。

前言 – 床长人工智能教程

函数:

setDefaultProjection(crs, crsTransform, scale)

Set a default projection to be applied to this image. The projection's resolution may be overridden by later operations.

设置要应用于此图像的默认投影。 投影的分辨率可能会被以后的操作覆盖。

Arguments:

this:image (Image):

The image to reproject.

crs (Projection):

The CRS to project the image to.

crsTransform (List, default: null):

The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with the scale option, and replaces any transform already on the projection.

scale (Float, default: null):

If scale is specified, then the projection is scaled by dividing the specified scale value by the nominal size of a meter in the specified projection. If scale is not specified, then the scale of the given projection will be used.

Returns: Image

代码:

var table = 
    /* color: #98ff00 */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[113.96499079450983, 26.612947981005476],
          [113.96499079450983, 25.1501177154906],
          [115.83266657575983, 25.1501177154906],
          [115.83266657575983, 26.612947981005476]]], null, false);


// Sentinel-3 OLCI/PROBA-V 数据
var dataset = ee.ImageCollection('COPERNICUS/S3/OLCI')
              .filterBounds(table)
              .filterDate('2020-01-01', '2020-12-31');

// 检查影像的可用波段,这里是第一景影像
var image = dataset.first();
print(image.bandNames());
Map.centerObject(table, 7)

// 定义一个函数,从Sentinel-3 OLCI/PROBA-V数据中计算LAI。
function calculateLAI(image) {
  // Convert LAI from dB to m^2/m^2
  var LAI = ee.Image(31.0).multiply(image.divide(315.0));
  // Set the CRS and scale of the LAI image
  var projection = image.select('Oa01_radiance').projection();
  var scale = projection.nominalScale();
  var crsTransform = projection.transform()

//原始错误代码
LAI = LAI.setDefaultProjection(projection, scale).Float();

//修改后的代码
LAI = LAI.setDefaultProjection(projection,null, scale).float();

//用以下这个代码也可以
    LAI = LAI.setDefaultProjection({
		crs:projection,
//	crsTransform:null,
	scale:scale
})
  return LAI;
}

// 对图像集应用LAI计算功能
var LAIcollection = dataset.map(calculateLAI);

// 获得2020年的LAI中位数
var medianLAI = LAIcollection.mean();

// 计算叶面积指数中位数
Map.addLayer(medianLAI, {}, 'Median LAI');

更多推荐