这段代码在Google Earth Engine (GEE) 平台上实现了从MODIS卫星影像数据集中提取特定时间范围内的影像,对其进行裁剪,并批量导出到Google Drive。
总体功能
实现了从MODIS卫星影像数据集中提取特定时间范围内的影像,进行裁剪,并批量导出到Google Drive的功能。通过对影像进行裁剪和导出,可以获得研究区内指定时间范围内的高分辨率影像数据,用于进一步的分析和研究
数据集
- 数据集:使用的是MODIS卫星影像数据集,具体为
MODIS/061/MOD09A1
(Terra Surface Reflectance 8-Day Global 500m)。
代码流程和功能
-
代码解释
-
设置研究区和时间范围:
- 定义了研究区
ROI
和时间范围startDate
到endDate
。
- 定义了研究区
-
裁剪影像:
- 筛选出时间范围内的MODIS影像,并使用
clip
函数裁剪到研究区ROI
。
- 筛选出时间范围内的MODIS影像,并使用
-
可视化参数:
- 定义可视化参数
visParams
,包括波段选择、最小和最大值以及伽玛校正。
- 定义可视化参数
-
在地图上可视化:
- 使用
Map.centerObject
将地图中心移动到研究区,并使用Map.addLayer
添加影像到地图进行显示。
- 使用
-
批量导出影像:
- 使用
geetools
的output.Download.ImageCollection.toDrive
方法将影像集合批量导出到Google Drive,设置导出参数如分辨率、区域、最大像素数、数据类型和投影系统。
- 使用
-
结果
- 批量导出:将指定时间范围内的裁剪后的MODIS影像批量导出到Google Drive,文件夹名称为
GEE_Exported_Images
。 - 导出设置:
- 分辨率:500米。
- 区域:研究区
ROI
。 - 最大像素数:1e13。
- 数据类型:int16。
- 投影系统:EPSG:4326。
注意
时间跨度不要太大,不然会运行崩溃。
完整代码:
// MOD09A1 (Terra Surface Reflectance 8-Day Global 500m)
// 设置研究区
var ROI = table;
// 定义裁剪函数
function clip(image) {
return image.clip(ROI);
}
// 设置时间范围
var startDate = "2012-12-25";
var endDate = "2013-01-01";
// 筛选 MOD09A1 数据集并裁剪影像
var Terra_SR_8d = ee.ImageCollection('MODIS/061/MOD09A1')
.filterDate(startDate, endDate)
.map(clip);
// 可视化参数
var visParams = {
bands: ['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03'], // 使用近红外、红光和蓝光波段
min: 0,
max: 3000,
gamma: 1.4
};
// 添加影像到地图进行可视化
Map.centerObject(ROI, 9); // 将地图中心移动到研究区
Map.addLayer(Terra_SR_8d.mean(), visParams, 'MODIS Composite');
// 批量导出影像
var output = require('users/fitoprincipe/geetools:batch');
// https://github.com/fitoprincipe/geetools-code-editor
output.Download.ImageCollection.toDrive(Terra_SR_8d, "GEE_Exported_Images", {
scale: 500, // 分辨率 (m)
region: ROI, // 感兴趣区
maxPixels: 1e13, // 默认为 1e8
type: "int16", // 导出影像到 Drive 时,影像波段的数据类型必须一致;Asset 则不需要
crs: "EPSG:4326" // 不设置,默认导出 MODIS_Sinusoidal 投影系统
});
/*
output.Download.ImageCollection.toDrive()
output.Download.ImageCollection.toDrive(ImageCollection, Folder name in your Drive, options of Export.image.toDrive())
Export.image.toDrive 中的参数都可以在 option 中更改
Export.image.toDrive(image, description, folder, fileNamePrefix, dimensions, region, scale, crs, crsTransform, maxPixels, shardSize, fileDimensions, skipEmptyTiles, fileFormat, formatOptions)
*/
最后注释的内容提供了有关 output.Download.ImageCollection.toDrive()
方法的使用说明。以下是对注释的详细解释:
解释
-
方法概述:
output.Download.ImageCollection.toDrive()
是一个用于将 ImageCollection 批量导出到 Google Drive 的方法。
-
方法签名:
output.Download.ImageCollection.toDrive(ImageCollection, Folder name in your Drive, options of Export.image.toDrive())
- ImageCollection:要导出的影像集合。
- Folder name in your Drive:存储在 Google Drive 中的文件夹名称。
- options of Export.image.toDrive():导出时的参数选项,与
Export.image.toDrive()
方法的参数相同。
-
导出选项:
Export.image.toDrive
方法中的参数都可以在option
中更改。这些参数包括:- image:要导出的影像。
- description:导出任务的描述。
- folder:存储在 Google Drive 中的文件夹名称。
- fileNamePrefix:文件名前缀。
- dimensions:导出影像的像素尺寸。
- region:要导出的区域。
- scale:导出的分辨率。
- crs:投影坐标系统。
- crsTransform:自定义的坐标变换。
- maxPixels:最大像素数。
- shardSize:分片大小。
- fileDimensions:每个文件的尺寸。
- skipEmptyTiles:是否跳过空的瓦片。
- fileFormat:文件格式。
- formatOptions:格式选项。