【问题标题】:Exporting all images in a Google Earth Engine image collection (Google Earth Engine API)导出 Google 地球引擎图像集合中的所有图像(Google 地球引擎 API)
【发布时间】:2017-10-07 16:51:34
【问题描述】:

我需要为我的论文下载一堆 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',@987654327 @...)。

提前非常感谢!!!

【问题讨论】:

  • 如果您只是下载图像,我建议您使用更传统的来源,例如earthexplorer ...这将使您摆脱JavaScript 并可能更快、更方便.
  • 感谢您的回答。我尝试先从 earth explorer 订购,但订单需要很长时间才能完成(我假设有一个月的时间,因为有 20 万张图片积压......)

标签: javascript javascript-objects google-code google-earth-engine


【解决方案1】:

我创建了一个函数来执行类似的操作。它可以在我创建的一堆工具中使用: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 上发布。

【讨论】:

  • 我知道可能为时已晚,但谢谢!
  • 如果它对你有用,现在还不算晚 =) 看看这个:github.com/fitoprincipe/geetools-code-editor/wiki/Batch
  • 我当时很着急,完全忘记了我问过这个问题,不幸的是直到昨天(2年后:O)才看到答案。 2-3 所以我手动完成了。但我以后一定会用你的工具!
  • 嗨@RodrigoE.Principe,我尝试复制粘贴您在上面提供的测试代码,但它似乎无法在我的谷歌地球引擎代码编辑器上运行:(我尝试了您发布的其他一些代码在不同的问题上,但似乎没有一个有效。你有什么建议吗?
  • 我也有同样的问题。尝试使用该工具下载 ERA5 数据,但没有成功。在 GEE 编辑器中使用了类似的东西:“batch.Download.ImageCollection.toDrive(ERA5data, 'ERA5', {region: polygon});”并且还尝试了使用 batch.Export.imagecollection.toDrive 的 python 库,但也没有用。图书馆有什么文档吗?
【解决方案2】:

尝试了性能,但它不起作用...没有错误,没有任务。 提前致谢!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多