GEE学习笔记001-ImageCollection(影像集合)的批量裁剪和批量导出

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

在GEE(Google Earth Engine)中,遥感影像可以是单张的Image,也可以是多张影像组成的影像集合(ImageCollection)。其中,Image的裁剪很简单,直接调用clip函数即可,但是针对ImageCollection,不能直接使用clip函数。
GEE提供的image导出函数(Export.image)包括Export.image() 、Export.image.toAsset() 、Export.image.toCloudStorage() 、Export.image.toDrive()。但这些函数都是针对Image类型的对象,并没有单独提出一个函数可以将ImageCollection类型的对象导出。以上提到的两个问题就是本文所要解决的两个问题:
(1)ImageCollection的裁剪;
(2)ImageCollection类型结果的的导出。


一、GEE中的裁剪函数image.clip(geometry)

(1)针对Image类型对象的裁剪

代码如下:
在这里插入图片描述

//使geometry居中显示
Map.centerObject(geometry,7);
//以geometry的范围裁剪image
var image_clip=image.clip(geometry);
//显示geometry
Map.addLayer(geometry,{},'geometry')
//显示裁剪前的图像
Map.addLayer(image,{max:1,min:-1,bands:['MNDWI']},'image')
//显示裁剪后的图像
Map.addLayer(image_clip,{max:1,min:-1,bands:['MNDWI']},'image_clip')

输出结果:
①geometry的范围:在这里插入图片描述

②image的范围
在这里插入图片描述
③image_clip的范围
在这里插入图片描述

(2)针对ImageCollection类型对象的裁剪

思路:使用map循环,对ImageCollection中的每一张Image执行相同的clip操作,代码如下:
在这里插入图片描述

//生成一个ImageCollection类型的实验数据
var list_imgs=ee.List([image1,image2,image3,image4]);
var img_Collection=ee.ImageCollection.fromImages(list_imgs);
print("img_Collection",img_Collection);//img_Collection就是生成的实验数据

//对ImageCollection类型对象进行裁剪
var clip_Collection=img_Collection.map(function(img){
  return img.clip(geometry)
})
//显示img_collection的第一张图像
Map.addLayer(clip_Collection.first(),{max:1,min:-1,bands:['MNDWI']},'imagecollection_clip')

输出结果:

在这里插入图片描述

二、Image对象和ImageCollection对象的导出(以导出至Asset为例)

(1)Image对象的导出

代码如下:

Export.image.toAsset({  
      image: image,
      description: 'MNDWI',
      region: geometry,
      scale: 30,
      maxPixels: 1e13,  //最大像元素
  });    

(2)ImageCollection对象的导出

代码如下:

//批量下载函数
function exportImage(image, roi, fileName) {  
    Export.image.toAsset({  
      image: image,
      description: 'MNDWI_'+fileName,
      region: aoi,
      scale: 30,
      maxPixels: 1e13,  //最大像元素
  });  
}

//生成列表,迭代下载
var indexList = clip_Collection.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 = clip_Collection.filter(ee.Filter.eq("system:index", indexs[i]))
              .first()
        var name=parseInt(indexs[i])
        
        exportImage(image, aoi, name);  //保存图像至Asset
  }
}); 

执行完上述代码之后,还需要在Task界面Run一下,才可以把结果保存!

总结

以上就是今天要讲的内容,本文仅仅简单介绍了GEE中Image和Image collection对象的裁剪和导出。

  • 14
    点赞
  • 59
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
批量导出GEEGoogle Earth Engine)中的ImageCollectionGoogle Drive,可以按照以下步骤进行操作。 首先,在GEE代码编辑器中导入所需的ImageCollection。可以使用类似以下代码的语句导入ImageCollection: ``` var collection = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA") .filterDate('2019-01-01', '2019-12-31') .filterBounds(geometry); ``` 其中,"LANDSAT/LC08/C01/T1_TOA"是您选择的ImageCollection的ID,.filterDate()和.filterBounds()函数可以根据需要筛选出特定的时间范围和地理范围。 接下来,使用GEE的Export功能导出ImageCollectionGoogle Drive。您可以使用类似以下代码的语句对ImageCollection进行导出: ``` Export.image.toDrive({ image: collection.toBands(), // 如果选择多个波段则使用toBands()函数 description: 'exported_images', //导出图像的描述 folder: 'export_folder', scale: 30, //导出图像的分辨率 region: geometry //导出图像的地理范围 }); ``` 在这个例子中,使用Export.image.toDrive()函数将ImageCollection导出为图像,并指定了导出的参数,如图像的描述、导出的文件夹、分辨率和地理范围。可以根据需要调整这些参数。 最后,运行这段代码并在弹出的对话框中确认您要授权GEE访问Google Drive,并等待图像导出完成。导出的图像将存储在指定的Google Drive文件夹中。 这样,您就可以通过以上步骤批量导出GEE中的ImageCollectionGoogle Drive。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小郭学地信

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值