前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Google Earth Engine(GEE)——argument ‘input‘: Invalid type. Expected type: Image<unknown bands>错误

Google Earth Engine(GEE)——argument ‘input‘: Invalid type. Expected type: Image<unknown bands>错误

作者头像
此星光明
发布2024-02-02 14:35:05
1650
发布2024-02-02 14:35:05
举报

 加载影像出现错误:

lope: Layer error: Terrain.slope, argument 'input': Invalid type. Expected type: Image<unknown bands>. Actual type: ImageCollection.

Aspect: Layer error: Terrain.aspect, argument 'input': Invalid type. Expected type: Image<unknown bands>. Actual type: ImageCollection.

错误代码:

代码语言:javascript
复制
var poi = 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      },
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.MultiPolygon(
        [[[[175.15998918717003, -82.43120366717352],
           [175.15998918717003, -82.45432179439132],
           [175.15998918717003, -82.45432179439132],
           [175.15998918717003, -82.43120366717352]]],
         [[[-171.83219831282995, -78.7073936066519],
           [-171.83219831282995, -82.83675780045455],
           [-122.08610456282995, -82.83675780045455],
           [-122.08610456282995, -78.7073936066519]]]], null, false);
Map.centerObject(poi, 6)

var esa = ee.ImageCollection("COPERNICUS/DEM/GLO30")
var elevation = esa.select('DEM');

var elevationVis = {
  min: 0,
  max: 2500,
  palette: ['000096','0064ff', '00b4ff', '33db80', '9beb4a',
  'ffeb00', 'ffb300', 'ff6400', 'eb1e00', 'af0000']
};
Map.addLayer(elevation, elevationVis, 'Elevation Copernicus');

//without converting to a single image
// ERROR

// Calculate slope. Units are degrees, range is [0,90).
var slope = ee.Terrain.slope(elevation);
// Calculate aspect. Units are degrees where 0=N, 90=E, 180=S, 270=W.
var aspect = ee.Terrain.aspect(elevation);
// Display slope and aspect layers on the map.
Map.addLayer(slope, {min: 0, max: 89.99}, 'Slope');
Map.addLayer(aspect, {min: 0, max: 359.99}, 'Aspect');

 这里需要选择输入的对象是一个波段,而不是影像集合,所以我们加载影像不能进行多波段加载,只能进行单景影像的加载,这里我们的错误就是从这个方面下手。这里的问题是我们需要裁剪影像,否则无法获取单波段的slope和aspect,因为我们无法对影像集合进行坡度和坡向操作。看下面函数就知道了

所需要的函数:

ee.Terrain.slope(input)

Calculates slope in degrees from a terrain DEM.

The local gradient is computed using the 4-connected neighbors of each pixel, so missing values will occur around the edges of an image.

Arguments:

input (Image):

An elevation image, in meters.

Returns: Image

ee.Terrain.aspect(input)

Calculates aspect in degrees from a terrain DEM.

The local gradient is computed using the 4-connected neighbors of each pixel, so missing values will occur around the edges of an image.

Arguments:

input (Image):

An elevation image, in meters.

Returns: Image

Map.addLayer(eeObject, visParamsnameshownopacity)

Adds a given EE object to the map as a layer.

Returns the new map layer.

Arguments:

eeObject (Collection|Feature|Image|RawMapId):

The object to add to the map.

visParams (FeatureVisualizationParameters|ImageVisualizationParameters, optional):

The visualization parameters. For Images and ImageCollection, see ee.data.getMapId for valid parameters. For Features and FeatureCollections, the only supported key is "color", as a CSS 3.0 color string or a hex string in "RRGGBB" format. Ignored when eeObject is a map ID.

name (String, optional):

The name of the layer. Defaults to "Layer N".

shown (Boolean, optional):

A flag indicating whether the layer should be on by default.

opacity (Number, optional):

The layer's opacity represented as a number between 0 and 1. Defaults to 1.

Returns: ui.Map.Layer

修改后的代码:

代码语言:javascript
复制
var poi = 
    /* color: #d63000 */
    /* displayProperties: [
      {
        "type": "rectangle"
      },
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.MultiPolygon(
        [[[[175.15998918717003, -82.43120366717352],
           [175.15998918717003, -82.45432179439132],
           [175.15998918717003, -82.45432179439132],
           [175.15998918717003, -82.43120366717352]]],
         [[[-171.83219831282995, -78.7073936066519],
           [-171.83219831282995, -82.83675780045455],
           [-122.08610456282995, -82.83675780045455],
           [-122.08610456282995, -78.7073936066519]]]], null, false);
Map.centerObject(poi, 6)

var esa = ee.ImageCollection("COPERNICUS/DEM/GLO30").filterBounds(poi).mosaic().clip(poi)
var elevation = esa.select('DEM');
print("elevation ",elevation )
var elevationVis = {
  min: 0,
  max: 2500,
  palette: ['000096','0064ff', '00b4ff', '33db80', '9beb4a',
  'ffeb00', 'ffb300', 'ff6400', 'eb1e00', 'af0000']
};
Map.addLayer(elevation, elevationVis, 'Elevation Copernicus');

//without converting to a single image
// ERROR

// Calculate slope. Units are degrees, range is [0,90).
var slope = ee.Terrain.slope(elevation);
print(slope)
// Calculate aspect. Units are degrees where 0=N, 90=E, 180=S, 270=W.
var aspect = ee.Terrain.aspect(elevation);
// Display slope and aspect layers on the map.
Map.addLayer(slope, {min: 0, max: 89.99}, 'Slope');
Map.addLayer(aspect, {min: 0, max: 359.99}, 'Aspect');
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-04-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Arguments:
  • Returns: Image
  • Arguments:
  • Returns: Image
  • Arguments:
  • Returns: ui.Map.Layer
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档