下载数据先准备工作(具体细节都能查到):科学上网 谷歌邮箱,谷歌邮箱注册GEE账号。
一:导入需要下载边界shp文件。
找到自己的shp文件,导入除了sbx文件的所有文件。
导入成功
命名assetid 如111,点击uoload。
上床成功后,点刷新,看到111,导入成功。
二,程序编写
导入数据:点击箭头
粘贴下面程序程序:这里的程序只能一年一年的下载。需要改的就是年份(比如说:如果要下载2002年的数据需要把程序里的数据2000改成2002)。
var roi=table
// 调用MODIS的NDVI数据集250m
var dataset = ee.ImageCollection('MODIS/061/MOD13Q1')
// 筛选研究时间和覆盖研究区域的影像
.filter(ee.Filter.date('2000-01-01', '2001-01-01'))
.select('NDVI')
// 对NDVI波段进行0.0001比例缩放
.map(function(image){
return image.multiply(0.0001).set('system:time_start',image.get('system:time_start'))
.clip(table)
});
var ndviVis = {
min: -1,
max: 1,
palette: ['red', 'blue', 'yellow', 'green'],
};
Map.centerObject(table, 8);
Map.addLayer(dataset, ndviVis, 'NDVI');
// 计算2020年NDVI月最大值
var years = ee.List.sequence(2000, 2000);
var months = ee.List.sequence(2, 12);
var monthly_max = ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function(m) {
return dataset.filter(ee.Filter.calendarRange(y,y, 'year')).filter(ee.Filter.calendarRange(m, m, 'month')).max().set('year', y).set('month', m).set('system:time_start', ee.Date.fromYMD(y, m, 1));
});
}).flatten()
);
Map.addLayer(monthly_max.mean().clip(table), ndviVis, 'yearly_mean');
print('全年月最大值时间序列',ui.Chart.image.series(monthly_max, table, ee.Reducer.mean(), 250));
// 输出每月合成的NDVI最大值
monthly_max
.aggregate_array('month')
.evaluate(function (months) {
months.forEach(function (month) {
var image = monthly_max
.filterMetadata('month', 'equals', month)
.first()
var description = 'NDVI_max-'+ '2000_' + month
Export.image.toDrive({
image: image,
description: description,
folder:"monthly_max",
scale: 250,
crs: "EPSG:4326",
maxPixels: 3784216672400,
region: table,
});
})
})
var NDVImean = ee.Number(monthly_max.mean().reduceRegion({
reducer: ee.Reducer.mean(),
geometry: table,
scale: 250,
maxPixels: 4e9
}).values().get(0));
print('NDVImean',NDVImean);
//将全年月最大值的平均值结果导出
Export.image.toDrive({
image: monthly_max.mean(),
description: '2000_yearly_mean',
folder: 'AVHRR_NDVI',
crs: 'EPSG:4326',
fileFormat:'GeoTIFF',
region: table,
scale: 250,
maxPixels: 1e13,
})
三、按年下载后批量点击RUN代码(这里是借鉴的:生态笔记博主的程序Google Earth Engine(GEE)批量下载代码(以MODIS NDVI数据为例)_生态笔记的博客-CSDN博客_gee批量下载)
在所有任务窗口弹出后(即run窗口全部弹出),按F12进入控制台,然后将这些脚本粘贴到控制台,然后按ENTER键即可。
function runTaskList() {
var runButtons = document.querySelector('#task-pane').shadowRoot.querySelectorAll(".run-button")
runButtons.forEach(function(e) {e.click()})
}
runTaskList()
setTimeout(
function(){
var taskDialog = document.querySelectorAll("ee-image-config-dialog") //table的话-image-改成-table-
taskDialog.forEach(function(e) {e.shadowRoot.querySelector("ee-dialog").shadowRoot.querySelector("paper-dialog").querySelector(".ok-button").click()})
},5 * 1000 );