简体   繁体   English

导出 Google Earth Engine 图像集合中的所有图像(Google Earth Engine API)

[英]Exporting all images in a Google Earth Engine image collection (Google Earth Engine API)

I need to download a bunch of Landsat images for my thesis.我需要为我的论文下载一堆 Landsat 图像。 My problem seems simple but I don't have a clue about JavaScript and the documentation didn't help enough.我的问题似乎很简单,但我对 JavaScript 一无所知,而且文档也没有提供足够的帮助。 I have filtered the collection to my region and time period and i want to export all images to Drive, seperately.我已将集合过滤到我所在的地区和时间段,并且我想将所有图像单独导出到云端硬盘。 Collection example:收藏示例:

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)); 

The code for exporting a single image is:导出单个图像的代码是:

Export.image.toDrive({
  image: image1 //example, var image1='Landsat/....'
  description: 'L51984_1',
  scale: 30,
});

How can I iterate through the collection to export all images?如何遍历集合以导出所有图像? The use of map() function seems to be the answer.使用 map() 函数似乎是答案。

prSR5.map(Export.image.toDrive({
  image: image,
  description: 'L51984',
  scale: 30,
}));

The question is how to set the image parameter to the correct image (ie first the 1st image, then the 2nd etc, something like ' thisImage() ' ) and the description to match image (ie 'L51984_1' , 'L51984_2' ...).问题是如何将图像参数设置为正确的图像(即首先是第一个图像,然后是第二个图像,例如“ thisImage() ”)和匹配图像的描述(即'L51984_1''L51984_2' .. .)

Many thanks in advance!!!提前谢谢了!!!

I have created a function to perform a similar action.我创建了一个函数来执行类似的操作。 It is available in a bunch of gee tools I've created: https://github.com/fitoprincipe/geetools-code-editor它在我创建的一堆 Gee 工具中可用: https : //github.com/fitoprincipe/geetools-code-editor

Here is the code:这是代码:

/* 
 * 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})
    }
  }

I haven't tried it a lot, but worked in a couple of test I made, example:我没有尝试过很多,但在我做的几个测试中工作,例如:

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});

If you have any issue you can comment here, but also you can post it on github.如果您有任何问题,可以在这里发表评论,也可以在 github 上发布。

performance tried but it does not work...no errors, no tasks.性能尝试但它不起作用...没有错误,没有任务。 Thanks in advance!提前致谢!

// 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})
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM