GEE批量處理數(shù)據(jù)
var roi = ee.FeatureCollection("users/wang123123/mwsboundary").geometry(); //("users/....")更改shp文件路徑,shp文件需要是zip格式,然后上傳。
// 1、自己的研究區(qū)。2、分辨率。3、傳感器的名字(傳感器要和分辨率對應)。
//批量下載函數(shù)
function exportImage(image, roi, fileName) {
? ? Export.image.toDrive({
? ? ? ?image: image,
? ? ? ?description: "Drive-image-"+fileName,
? ? ? ?fileNamePrefix: fileName+'_NDVI',? //文件命名
? ? ? ?folder: "MODIS_NDVI",? //保存的文件夾
? ? ? ?scale: 250,? //分辨率
? ? ? ?region: roi,? //研究區(qū)
? ? ? ?maxPixels: 1e13,? //最大像元素,默認就好
? ? ? ?crs: "EPSG:4326"? //設(shè)置投影
? ?});
?}
?
//加載數(shù)據(jù)集
var data = ee.ImageCollection("MODIS/006/MOD13Q1");? //這里以MODIS NDVI 數(shù)據(jù)為例
Map.centerObject(roi, 4);? //圖層顯示
?
//篩選數(shù)據(jù)
var data_selected = data.filterBounds(roi)
? ? ? ? ? ? ? ?.filterDate("2021-1-1", "2021-12-31")
? ? ? ? ? ? ? ?.select('NDVI'); //選擇波段
print("data_selected", data_selected);
?
//生成列表,迭代下載
var indexList = data_selected.reduceColumns(ee.Reducer.toList(), ["system:index"]).get("list");
print("indexList", indexList);
indexList.evaluate(function(indexs) {
for (var i=0; i<indexs.length; i++) {
? ? ? ? var image = data_selected.filter(ee.Filter.eq("system:index", indexs[i]))
? ? ? ? ? ? ? .first()
? ? ? ? ? ? ? .select('NDVI')
? ? ? ? ? ? ? .toInt16()? //設(shè)置數(shù)據(jù)類型
? ? ? ? ? ? ? .clip (roi);? ?//裁剪數(shù)據(jù)
? ? ? ? exportImage(image, roi, indexs[i]);? //保存圖像至Google網(wǎng)盤
? ?}
?});
// 保存至云盤保存 F12
// 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 );