gee批量下载哨兵数据
时间: 2025-02-01 07:21:07 浏览: 40
使用 Google Earth Engine API 批量下载 Sentinel 卫星数据
准备工作
在开始之前,确保已经安装并配置好了 earthengine-api
和 geemap
库。这些库提供了访问 GEE 平台以及管理任务的功能。
对于 Python 用户来说,可以通过 pip 安装上述依赖项:
pip install earthengine-api geemap
初始化 Earth Engine:
import ee
ee.Initialize()
构建影像集合查询条件
定义感兴趣区域 (AOI),设置时间范围和其他筛选参数来构建特定的影像集合作为后续操作的基础[^1]。
# 设置研究区
aoi = ee.Geometry.Polygon(
[[[70.89, 26.54], [70.89, 27.30],
[72.27, 27.30], [72.27, 26.54]]])
# 创建Sentinel-1 影像集合
sentinel1_collection = (
ee.ImageCollection('COPERNICUS/S1_GRD')
.filterBounds(aoi)
.filterDate('2023-01-01', '2023-12-31') # 时间区间可以根据需求调整
)
print(f'Found {sentinel1_collection.size().getInfo()} images.')
下载单张图片作为测试
先尝试导出一张图片到 Google Drive 或本地文件系统验证流程是否正常工作[^2]。
from geemap import ee_export_image
image_to_download = sentinel1_collection.first()
task_config = {
'region': aoi.getInfo()['coordinates'],
'scale': 10,
'folder': 'gee_downloads',
}
ee_export_image(image=image_to_download, filename='test_sentinel.tif', **task_config)
实现批量下载功能
当确认单独图像可以成功下载之后,则可通过循环遍历整个影像集合完成批量化作业。这里展示了一个简单的例子,其中包含了基本错误处理逻辑以应对可能出现的问题。
def batch_download(collection, folder_name):
"""Batch download all images from an image collection."""
try:
size = collection.size().getInfo()
if not size:
print("No images found.")
return
for i in range(size):
img = ee.Image(collection.toList(100).get(i))
task_params = dict(
region=aoi.getInfo()["coordinates"],
scale=10,
maxPixels=1e13,
fileFormat="GeoTIFF",
description=f'sentinel_{i}',
folder=folder_name
)
export_task = ee.batch.Export.image.toDrive(**{
"image": img.select(['VV', 'VH']),
**task_params
})
export_task.start()
print(f'Started exporting image {i}')
except Exception as e:
print(e)
batch_download(sentinel1_collection, 'my_folder')
此脚本会将符合条件的所有 Sentinel-1 GRD 类型的数据逐个上传至指定目录下保存成 GeoTiff 文件格式。
相关推荐

















