如何从 Google Earth Engine python api 迭代和下载图像集合中的每个图像

kri*_*nab 4 python python-3.x google-earth-engine landsat

我是谷歌地球引擎的新手,并试图了解如何使用谷歌地球引擎 python api。我可以创建一个图像集合,但显然该getdownloadurl()方法仅适用于单个图像。所以我试图了解如何迭代和下载集合中的所有图像。

这是我的基本代码。对于我正在做的其他一些工作,我非常详细地分解了它。

import ee
ee.Initialize()
col = ee.ImageCollection('LANDSAT/LC08/C01/T1')
col.filterDate('1/1/2015', '4/30/2015')
pt = ee.Geometry.Point([-2.40986111110000012, 26.76033333330000019])
buff = pt.buffer(300)
region = ee.Feature.bounds(buff)
col.filterBounds(region)
Run Code Online (Sandbox Code Playgroud)

所以我拉了 Landsat 集合,按日期和缓冲区几何过滤。所以我应该在集合中有 7-8 张图片(所有乐队)。

但是,我似乎无法通过迭代来处理集合。

例如:

for i in col:
    print(i)
Run Code Online (Sandbox Code Playgroud)

错误表明 TypeError: 'ImageCollection' object is not iterable

因此,如果集合不可迭代,我如何访问单个图像?

一旦我有了图像,我应该可以使用通常的

path = col[i].getDownloadUrl({
    'scale': 30,
    'crs': 'EPSG:4326',
    'region': region
})
Run Code Online (Sandbox Code Playgroud)

Nic*_*ton 7

为此使用它是个好主意ee.batch.Export。此外,避免混合客户端和服务器功能是一种很好的做法(参考)。出于这个原因,可以使用 for 循环,因为它Export是一个客户端函数。这是一个让您入门的简单示例:

import ee
ee.Initialize()

rectangle = ee.Geometry.Rectangle([-1, -1, 1, 1])
sillyCollection = ee.ImageCollection([ee.Image(1), ee.Image(2), ee.Image(3)])

# This is OK for small collections
collectionList = sillyCollection.toList(sillyCollection.size())
collectionSize = collectionList.size().getInfo()
for i in xrange(collectionSize):
    ee.batch.Export.image.toDrive(
        image = ee.Image(collectionList.get(i)).clip(rectangle), 
        fileNamePrefix = 'foo' + str(i + 1), 
        dimensions = '128x128').start()
Run Code Online (Sandbox Code Playgroud)

请注意,以这种方式将集合转换为列表对于大型集合(参考)也是危险的。但是,如果您确实需要下载,这可能是最具扩展性的方法。