您要导出的内容 (dataset.mosaic()) 没有应用 visparams。
您需要调用 Visualize() 将其转换为可以在地图瓦片中显示的内容。
错误指出:错误:要渲染的图像必须有 1 或 3 个波段,但发现有 30 个。(错误代码:3)
visparams 中调用的一个频段似乎没有被识别,并且所有 30 个 CAMS 频段都在尝试加载。任何帮助/代码调试将不胜感激!
原始代码:
// Get data
var dataset = ee.ImageCollection('ECMWF/CAMS/NRT')
.filterDate('2023-07-22', '2023-07-31')
.filter('model_initialization_hour == 0');
// Select first and last forecast hours.
var hour00 = dataset.filter('model_forecast_hour == 0').first();
var hour21 = dataset.filter('model_forecast_hour == 21').first();
// Visualization parameters for specified aerosol band.
var visParams = {
bands: ['total_column_nitrogen_dioxide_surface'],
min: 0.0,
max: 3.6,
palette: [
'5e4fa2', '3288bd', '66c2a5', 'abe0a4', 'e6f598', 'ffffbf',
'fee08b', 'fdae61', 'f46d43', 'd53e4f', '9e0142'
]
};
var exportRegion = ee.Geometry.BBox(35.72711080753947, 31.761096539673837,
36.07730001652384, 32.088620980502085);
// Display forecasts on the map.
Map.addLayer(hour00, visParams, 'Total Column Nitrogen Dioxide Surface', true, 0.8);
Map.centerObject(exportRegion);
// --- Export Map Tiles for use with Map Preview ---
// Use image setup code from example at top of the page.
// Set up Export task.
Export.map.toCloudStorage({
image: dataset.mosaic(),
description: 'mapTilesForMapPreview',
bucket: 'test-no2', // replace with your GCS bucket name
fileFormat: 'auto',
maxZoom: 13,
region: exportRegion,
writePublicTiles: true,
mapsApiKey: 'XXX'
});
因为这里需要设定一个付费的项目,所以无法进行具体的错误导出展示:
我们首先看一下原始的数据集中的波段信息:
函数:
Export.map.toCloudStorage(image, description, bucket, fileFormat, path, writePublicTiles, maxZoom, scale, minZoom, region, skipEmptyTiles, mapsApiKey, bucketCorsUris)
创建一个批处理任务,将图像导出为矩形金字塔的地图图块,供网络地图查看器使用。地图图块将附带一个参考 index.html 文件,用于使用谷歌地图 API 显示这些a图块,以及一个 earth.html 文件,用于在谷歌地球上打开地图。
参数:
image (图像):
要导出为磁贴的图片。
description(字符串,可选):
任务的可读名称。默认为 "myExportMapTask"。
bucket(字符串,可选):
要写入的目标存储桶。
fileFormat(字符串,可选):
地图瓦片的文件格式,可以是
"auto"、"png "或 "jpg "中的一种。默认为 "auto",这意味着不透明的磁贴将编码为 "jpg",透明的磁贴将编码为 "png"。
path(字符串,可选):
用作输出路径的字符串。尾部的"/"为可选项。默认为任务描述。
writePublicTiles(布尔,可选):
是否写入公共磁贴,而不是使用水桶的默认对象 ACL。默认为 true,并要求调用者是水桶的所有者。
maxZoom(数值,可选):
要导出的地图磁贴的最大缩放级别。
scale(数值,可选):
最大图像分辨率(单位:米/像素),可替代 "maxZoom"。比例尺将转换为赤道上最合适的最大缩放级别。
minZoom(数值,可选):
要导出的地图图块的可选最小缩放级别。默认为零。
region(Geometry.LinearRing|Geometry.Polygon|String,可选项):
代表要导出区域的 LinearRing、Polygon 或坐标。可以指定为几何对象或序列化为字符串的坐标。将在包含此几何图形的矩形区域中生成地图方块。
skipEmptyTiles(布尔,可选):
如果为 "true",则跳过写入空(即全透明)的地图碎片。默认为 false。
mapsApiKey(字符串,可选):
在 index.html 中用于初始化 Google 地图 API。这将删除地图上的 "仅限开发目的 "信息。
bucketCorsUris(List,可选):
允许从 JavaScript 获取导出磁贴的域列表(如 https://code.earthengine.google.com)。将磁贴设置为 "公共 "还不足以让网页访问它们,因此必须明确授予域对数据桶的访问权限。这就是所谓的跨源资源共享(Cross-Origin-Resource-Sharing)或 CORS。您可以使用 "*"来允许所有域访问,但一般不鼓励这样做。更多详情,请参阅 https://cloud.google.com/storage/docs/cross-origin。
影像可视化函数
visualize(bands, gain, bias, min, max, gamma, opacity, palette, forceRgbOutput)
Produces an RGB or grayscale visualization of an image. Each of the gain, bias, min, max and gamma arguments can take either a single value, which will be applied to all bands, or a list of values the same length as bands.
Arguments:
this:image (Image):
The image to visualize.
bands (Object, default: null):
A list of the bands to visualize. If empty, the first 3 are used.
gain (Object, default: null):
The visualization gain(s) to use.
bias (Object, default: null):
The visualization bias(es) to use.
min (Object, default: null):
The value(s) to map to RGB8 value 0.
max (Object, default: null):
The value(s) to map to RGB8 value 255.
gamma (Object, default: null):
The gamma correction factor(s) to use.
opacity (Number, default: null):
The opacity scaling factor to use.
palette (Object, default: null):
The color palette to use. List of CSS color identifiers or hexadecimal color strings (e.g. ['red', '00FF00', 'bluevlolet']).
forceRgbOutput (Boolean, default: false):
Whether to produce RGB output even for single-band inputs.
Returns: Image
Export.map.toCloudStorage({
image: dataset.mosaic().visualize(),
description: 'mapTilesForMapPreview',
bucket: 'test-no2', // replace with your GCS bucket name
fileFormat: 'auto',
maxZoom: 13,
region: exportRegion,
writePublicTiles: true,
mapsApiKey: 'XXX'
});
大家可以自己开去开一个云存储账户,因为是计费项目,所以这里不展示,因为这需要mapsApiKey,所以如果你是付费用户可以去试试。