gee下载Sentinel2卫星影像
时间: 2025-03-01 13:53:04 浏览: 78
### 使用 Google Earth Engine (GEE) 下载 Sentinel-2 卫星影像
为了通过 GEE 平台下载 Sentinel-2 影像,可以按照如下方法操作:
#### 准备工作
确保已安装 Python 版本的 `geemap` 库以及完成 GEE 的认证过程。这一步骤对于后续调用 API 接口至关重要。
```bash
pip install geemap
```
#### 初始化环境并设置区域范围
定义目标地理边界作为查询条件的一部分,在此例子中采用了一个特定地理位置的兴趣区(AOI)。该兴趣区可以通过 GeoJSON 文件导入或者直接指定坐标列表创建几何对象[^4]。
```python
import ee
import geemap
# Initialize the Earth Engine module.
ee.Initialize()
# Create a map centered at specific coordinates with zoom level set to 10.
Map = geemap.Map(center=[37.7749, -122.4194], zoom=10)
# Define Area of Interest as an example using predefined geometry or by loading from file.
aoi = ee.Geometry.Polygon(
[[[longitude_min, latitude_max],
[longitude_max, latitude_max],
[longitude_max, latitude_min],
[longitude_min, latitude_min]]])
```
#### 构建图像集合筛选器
构建时间区间过滤器用于限定所选数据的时间跨度;同时应用云覆盖度阈值减少不必要的干扰因素影响最终分析质量。此外还可以根据需求加入其他自定义属性约束条件进一步精确化检索结果。
```python
start_date = '2023-01-01'
end_date = '2023-12-31'
cloud_cover_threshold = 20
collection = (
ee.ImageCollection('COPERNICUS/S2')
.filterBounds(aoi)
.filterDate(start_date, end_date)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', cloud_cover_threshold))
)
```
#### 执行批量下载任务
最后一步就是发起导出请求至用户的谷歌云端存储桶内或是本地磁盘路径上保存处理后的栅格文件了。注意每次只能提交有限数量的任务队列等待执行完毕后再继续新增更多项以免超出配额限制引发错误提示信息返回给客户端程序端造成困扰。
```python
def export_image(image, filename):
task_config = {
'image': image,
'description': f'{filename}',
'scale': 10, # Spatial resolution in meters per pixel.
'region': aoi.getInfo()['coordinates'],
'maxPixels': 1e9,
'folder': 'gee_downloads' # Folder name within your Google Drive where files will be saved.
}
task = ee.batch.Export.image.toDrive(**task_config)
task.start()
print(f'Started exporting {filename}')
images_list = collection.toList(collection.size())
for i in range(0, min(collection.size().getInfo(), 5)): # Limiting exports to first five images for demonstration purposes.
img = ee.Image(images_list.get(i))
date_str = img.date().format('YYYYMMdd').getInfo()
export_image(img, f'sentinel2_{date_str}')
```
阅读全文
相关推荐
















