如何使用google earth引擎的python API下载图片

2024-05-23 22:53:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Google的地球引擎API来访问LandSat图像。 程序如下所示

import ee
ee.Initialize()

加载陆地卫星图像并选择三个波段。

landsat = ee.Image('LANDSAT/LC8_L1T_TOA
/LC81230322014135LGN00').select(['B4', 'B3', 'B2']);

创建表示导出区域的几何图形。

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236]);

导出图像,指定比例和区域。

 export.image.toDrive({
    image: landsat,
    description: 'imageToDriveExample',
    scale: 30,  
    region: geometry
    });

它抛出以下错误。

Traceback (most recent call last):
File "e6.py", line 11, in <module>
export.image.toDrive({
NameError: name 'export' is not defined

请帮忙。我找不到下载图像的正确功能。


Tags: 图像image引擎import程序api区域地球
3条回答

要在Ben's answer上构建,还可以使用:

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])

从原始帖子中添加以下行,使坐标的格式与任务配置-->;区域字段的格式正确:

geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])
geometry = geometry['coordinates'][0]

它可防止到达以下位置时“任务配置”格式不匹配:

task = ee.batch.Export.image(landsat, 'exportExample', task_config)

这将允许您使用API中的给定函数,但它将提取坐标,这样您就可以在上面Ben建议的方法中使用它们。

如果使用的是python API,则必须使用“批处理”子模块。默认行为是保存到您的google驱动器。也可以将边界框指定为坐标列表:

llx = 116.2621
lly = 39.8412
urx = 116.4849
ury = 40.01236
geometry = [[llx,lly], [llx,ury], [urx,ury], [urx,lly]]

task_config = {
    'description': 'imageToDriveExample',
    'scale': 30,  
    'region': geometry
    }

task = ee.batch.Export.image(landsat, 'exportExample', task_config)

task.start()

这将在GoogleDrive的顶部文件夹中生成一个名为“exportExample.tif”的文件。

还要注意,在python中,每行末尾的分号不是必需的。

您的代码中有一个拼写错误,Export应该从大写字母开始。见documentation

相关问题 更多 >