提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
前言
在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对象的裁剪和导出。