目录
1、问题与目标
如何利用GEE进行随机样点的采样?通过本分析,实现以下目标:
- 在分析区域生成1000个甚至更多的随机采样点位
- 以区域气温为例,利用随机生成采样点进行气温的采样
- 将随机采集的气温数据导出为shp文件
分析区域如下:
2、python代码
(1)加载分析区域
huanghe_bj = '../boudary/huangtu_plateau.shp'
huanghe = geemap.shp_to_ee(huanghe_bj)
roi = huanghe.geometry()
Map = geemap.Map()
Map.addLayer(ee.Image().paint(roi, 0, 2), {'palette':'darkblue'}, 'plateau')
Map.centerObject(roi)
Map
(2)生成随机采样点位
# 研究区域月均气温的随机采样点
randomPoints = ee.FeatureCollection.randomPoints(roi)
Map.addLayer(randomPoints, {'color':'red'}, 'sample Points')
结果如下:
(3)月均气温数据计算
# 计算2020年7月日平均温度,进行相应时间段、区域范围筛选
era5_mt = ee.ImageCollection('ECMWF/ERA5/DAILY') \
.select('mean_2m_air_temperature') \
.filterDate('2020-07-01', '2020-07-31') \
.filterBounds(roi) \
.mean() \
.subtract(273.15)
(4)利用随机样点进行空间采样
# 随机点位气温采样
airTmp_randomPoints = era5_mt.sampleRegions(**{
'collection':randomPoints,
'scale':5000,
'geometries':True
})
# 查询随机提取点的信息,以第一个点位信息为例
airTmp_randomPoints.first().getInfo()
""" {'type': 'Feature',
'geometry': {'geodesic': False,
'type': 'Point',
'coordinates': [110.2008274793623, 36.449142653149586]},
'id': '0_0',
'properties': {'mean_2m_air_temperature': 23.755029296875023}} """
(5)将采样点结果导出shp文件
geemap.ee_to_shp(airTmp_randomPoints, '../Temp/test.shp')
在ArcGIS中加载,好熟悉的界面哈
3、小结
- 生成随机采样点的函数 randomPoints()
- 区域内随机采样的函数 sampleRegions()
- 快速导出为shp文件的函数 ee_to_shp()
参考:
-
https://developers.google.com/earth-engine/apidocs/ee-featurecollection-randompoints?hl=en
-
https://developers.google.com/earth-engine/guides/feature_collection_info
-
GEE系列:第9单元 在GEE中生成采样数据【随机采样】_GEE水生态空间-CSDN博客
-
GEE学习:利用sampleRegions构建分类训练样本_GEE水生态空间-CSDN博客