导出Google Earth Engine图片集中的所有图片(Google Earth Engine API) [英] Exporting all images in a Google Earth Engine image collection (Google Earth Engine API)

查看:421
本文介绍了导出Google Earth Engine图片集中的所有图片(Google Earth Engine API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的论文下载一堆Landsat图像.我的问题似乎很简单,但是我对JavaScript毫无头绪,文档也没有足够的帮助. 我已将集合过滤到我所在的地区和时间段,并且希望将所有图像分别导出到云端硬盘. 集合示例:

I need to download a bunch of Landsat images for my thesis. My problem seems simple but I don't have a clue about JavaScript and the documentation didn't help enough. 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,
});

如何遍历集合以导出所有图像?答案是使用map()函数.

How can I iterate through the collection to export all images? The use of map() function seems to be the answer.

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

问题是如何将image参数设置为正确的图像(即第一个图像,然后是第二个图像,类似'thisImage()')和描述以匹配图像(即'L51984_1' ...).

The question is how to set the image parameter to the correct image (i.e first the 1st image, then the 2nd etc, something like 'thisImage()' ) and the description to match image (i.e. 'L51984_1','L51984_2'...).

非常感谢!

推荐答案

我创建了一个函数来执行类似的操作.我创建的许多gee工具中都可以使用它: https://github.com/fitoprincipe /geetools-code-editor

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

这是代码:

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

如果有任何问题,您可以在此处评论,也可以将其发布在github上.

If you have any issue you can comment here, but also you can post it on github.

这篇关于导出Google Earth Engine图片集中的所有图片(Google Earth Engine API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆