在 Google Earth Engine 中,不能直接更改 Image
的名称字段(因为每个影像本质上没有一个可直接修改的“名字”字段),但可以通过将日期用于标识导出的影像.
思路:把imagecollection的所有影像的date按照顺序存成list,然后导出的时候按照顺序调用,作为description
代码如下:
//collection是自己要导出的imagecollection
// 将影像集合转换为列表
var imageList = collection.toList(collection.size());
// 提取所有影像的日期,并按顺序存储为一个列表
var dateList = imageList.map(function(image) {
return ee.Image(image).date().format('YYYY-MM-dd');
});
print(dateList,'dateList')
// 获取影像列表的大小
var collectionSize = collection.size().getInfo(); // 获取影像集合的大小
var dateListInfo = dateList.getInfo(); // 将日期列表转换为本地的 JS 列表
// 定义一个函数来导出每个影像,使用日期列表中的日期作为文件名
var exportImage = function(image, i) {
// 选择要导出的波段
var selectedBands = image.select(['band1', 'band2']);
// 获取当前影像对应的日期
var date = dateListInfo[i]; // 使用日期列表中的日期
// 导出影像到 Google Drive,使用日期作为文件名的一部分
Export.image.toDrive({
image: selectedBands, // 导出的影像只包含选择的两个波段
description: '371425000000' + date, // 使用影像的日期作为文件名
scale: 10, // 设置导出分辨率为10米
region: image.geometry(), // 设置导出区域
fileNamePrefix: '371425000000' + date, // 设置文件名前缀
maxPixels: 1e13 // 设置最大像素值限制
});
};
// 遍历影像列表并导出每个影像
for (var i = 0; i < collectionSize; i++) {
var image = ee.Image(imageList.get(i)); // 获取索引为 i 的影像
exportImage(image, i); // 导出影像,使用日期作为文件名的一部分
}
结果展示: