加载影像出现错误:
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.
错误代码:
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, visParams, name, shown, opacity)
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
修改后的代码:
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');