我需要为我的论文下载一堆Landsat图像。我的问题似乎很简单,但我对JavaScript没有任何线索,文档也没有足够的帮助。 我已将该集合过滤到我的区域和时间段,我想将所有图像单独导出到云端硬盘。 收集示例:
var surfaceReflectanceL5 = ee.ImageCollection('LANDSAT/LT5_SR');
var dateSR5=surfaceReflectanceL5.filterDate('1984-01-01', '1985-01-01');
var prSR5=dateSR5.filter(ee.Filter.eq('wrs_path', 182))
.filter(ee.Filter.eq('wrs_row', 35));
导出单个图像的代码是:
Export.image.toDrive({
image: image1 //example, var image1='Landsat/....'
description: 'L51984_1',
scale: 30,
});
如何遍历集合以导出所有图像? map()函数的使用似乎就是答案。
prSR5.map(Export.image.toDrive({
image: image,
description: 'L51984',
scale: 30,
}));
问题是如何将图像参数设置为正确的图像(即首先是第一个图像,然后是第二个图像,类似于' thisImage()
')以及匹配图像的描述(即'L51984_1'
,'L51984_2'
...)。
非常感谢提前!!!
答案 0 :(得分:7)
我创建了一个执行类似操作的函数。它可以在我创建的一堆gee工具中使用:https://github.com/fitoprincipe/geetools-code-editor
以下是代码:
/*
* Author: Rodrigo E. Principe
* License: Apache 2.0
PURPOSE:
This function Exports all images from one Collection
PARAMETERS:
col = collection that contains the images (ImageCollection) (not optional)
folder = the folder where images will go (str) (not optional)
scale = the pixel's scale (int) (optional) (defaults to 1000) (for Landsat use 30)
type = data type of the exported image (str) (option: "float", "byte", "int", "double") (optional) (defaults to "float")
nimg = number of images of the collection (can be greater than the actual number) (int) (optional) (defaults to 500)
maxPixels = max number of pixels to include in the image (int) (optional) (defults to 1e10)
region = the region where images are on (Geometry.LinearRing or Geometry.Polygon) (optional) (defaults to the image footprint)
Be careful with the region parameter. If the collection has images
in different regions I suggest not to set that parameter
EXAMPLE:
ExportCol(myLandsatCol, "Landsat_imgs", 30)
*/
var ExportCol = function(col, folder, scale, type,
nimg, maxPixels, region) {
type = type || "float";
nimg = nimg || 500;
scale = scale || 1000;
maxPixels = maxPixels || 1e10;
var colList = col.toList(nimg);
var n = colList.size().getInfo();
for (var i = 0; i < n; i++) {
var img = ee.Image(colList.get(i));
var id = img.id().getInfo();
region = region || img.geometry().bounds().getInfo()["coordinates"];
var imgtype = {"float":img.toFloat(),
"byte":img.toByte(),
"int":img.toInt(),
"double":img.toDouble()
}
Export.image.toDrive({
image:imgtype[type],
description: id,
folder: folder,
fileNamePrefix: id,
region: region,
scale: scale,
maxPixels: maxPixels})
}
}
我没有尝试过很多,但是我做了几个测试,例如:
var batch = require('users/fitoprincipe/geetools:batch')
var col = ee.ImageCollection("LEDAPS/LE7_L1T_SR").filterDate("2002-01-01","2002-01-03");
batch.Download.ImageCollection.toDrive(col, "Folder", {scale:30});
如果您有任何问题,可以在这里发表评论,也可以在github上发布。
答案 1 :(得分:0)
性能尝试但不起作用...没有错误,没有任务。 提前致谢!
// Digitalize your AOI: geometry
// Load the Sentinel-1 ImageCollection.
// Band selection: VV, VH & Incidende Angle (default), Mode: IW, Spatial Resolution : 10m
var imgVVVH = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('resolution_meters', 10))
.filter(ee.Filter.eq('instrumentMode', 'IW'));
// 3. Definición de las órbitas y rango de fechas
//
// Tipo de orbita
var asc = imgVVVH.filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'));
var desc = imgVVVH.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
//Rango de fechas
var date = ee.Filter.date('2015-03-01', '2015-04-01');
// Filter by date and geometry, create multiband image and transform to Float.
var ascArea = asc.filter(date).filterBounds(geometry).toBands().toFloat();
var descArea = desc.filter(date).filterBounds(geometry).toBands().toFloat();
/*
//6. Recortar y guardar
//
// Clip & Save
// Modificar para las diferentes trayectorias; Ascendente default
function clipySave (ascArea){// (ascArea), (descArea)
var imagenclip = ascArea.clip(geometry)
//var imagenclip = descArea .clip(geometry)
Export.image.toDrive(ascArea)
//Export.image.toDrive(descArea)
return imagenclip
}
*/
//Performing your code.............No errors, No tasks
var col= ascArea.clip(geometry);
var folder = 'Download_S1';
var ExportCol = function(col, folder, scale, type,
nimg, region) {
type = 'float';
nimg = nimg || 500;
scale = scale || 10;
//maxPixels = maxPixels || 1e10;
var colList = col.toList(nimg);
var n = colList.size().getInfo();
for (var i = 0; i < n; i++) {
var img = ee.Image(colList.get(i));
var id = img.id().getInfo();
region = region || img.geometry().bounds().getInfo()["coordinates"];
var imgtype = {"float":img.toFloat(),
"byte":img.toByte(),
"int":img.toInt(),
"double":img.toDouble()
}
Export.image.toDrive({
image:imgtype[type],
description: id,
folder: folder,
fileNamePrefix: id,
region: region,
scale: scale})
//maxPixels: maxPixels})
}
}