0
点赞
收藏
分享

微信扫一扫

AI Earth ——开发者模式案例1:按区域进行Sentinel2L2A检索与下载


按区域检索与下载影像

用户可使用平台内置或自主上传的矢量文件,进行数据的检索(以 Sentine-2 L2A 为例),再进行数据筛选、拼接、裁剪等操作后,将数据导出至 我的数据 中。

初始化环境​​¶​​

定义矢量区域​​¶​​

使用 ​​FeatureCollection​​​ 引用平台内置或自主上传的矢量边界,定义检索数据的区域。利用 ​​aie.Map​​ 构造一个地图组件 Map 对象,通过 ​​aie.Map.addLayer​​

region = aie.FeatureCollection('China_Province') \
.filter(aie.Filter.eq('province', '浙江省')) \
.geometry()

map = aie.Map(
center=region.getCenter(),
height=800,
zoom=6
)

vis_params = {
'color': '#00FF00'
}

map.addLayer(
region,
vis_params,
'region',
bounds=region.getBounds()
)
map

Sentinel-2 数据检索​​¶​​

定义函数 s2_collection ,实现按区域、时间、云量等条件的 Sentinel-2 数据检索,返回哨兵单景 s2 image 和进行镶嵌、裁剪后的 s2 mosaic image 。

def s2_collection(start_date, end_date):
s2 = aie.ImageCollection('SENTINEL_MSIL2A') \
.filterBounds(region) \
.filterDate(start_date, end_date) \
.filter('eo:cloud_cover<20')
mosaic_image = s2.median().clip(region)
return s2, mosaic_image

s2, s2_mosaic = s2_collection('2021-04-01', '2022-08-30')

数据可视化​​¶​​

对 S2 数据进行波段组合可视化,常用波段:真彩色 ['B4', 'B3', 'B2'] 、假彩色 ['B8', 'B4', 'B3'] 、假彩色 ['B12', 'B11', 'B4'] 等。

vis_params = {
'bands': ['B4', 'B3', 'B2'],
'min': 0,
'max': 3500
}

map.addLayer(
s2_mosaic,
vis_params,
'Ture color',
bounds=region.getBounds()
)
map

影像导出​​¶​​

使用 ​​Export.image.toAsset​​ 将数据导出至我的数据中,可以通过 scale 参数指定导出的分辨率( 单位:米 )。

# 导出镶嵌影像
task = aie.Export.image.toAsset(s2_mosaic, 's2_mosaic', 200)
task.start()

# 导出单景影像,可自行调整需要导出的影像景数
size = s2.size().getInfo() # 检索得到的影像景数
print(size)

size = 5
for i in range(size):
id = s2.toList(count=size).getInfo()[i]['id']
print(id)
task = aie.Export.image.toAsset(aie.Image(id), id, 50)
task.start()

加载后的影像结果: 

AI Earth ——开发者模式案例1:按区域进行Sentinel2L2A检索与下载_ai

 

举报

相关推荐

2.开发者git 操作

0 条评论