2.2 像元值提取
需求: 需要提取一些某些地面点的像元值,如PML_V2序列在某坐标点的值
数据: 张永强PML_V2数据【https://developers.google.com/earth-engine/datasets/catalog/CAS_IGSNRR_PML_V2_v017#bands】
map常用的语法:
- 用法一:不预先定义函数,直接
map(function(feature){....})
,这是最常见的实现循环的表达。map可以直接使用一开始引入的全局变量。- 用法二:首先定义函数
var xxx = function(feature){....}
,然后map(xxx)
注意:
- map中不能使用
- map中不能使用Map等组件;
- map使用的函数必须有返回值;
方法一: 使用reduceRegion()
var Yeheshan = ee.Feature(ee.Geometry.Point([107.9148,34.5587]),{'name':'Yeheshan'})
var PML = ee.ImageCollection("CAS/IGSNRR/PML/V2_v017")
.filterDate('2000-02-26','2020-12-26')
//编写针对点[feature]提取栅格值的函数
var extracPixels = function(feature,imageCollection){
//构建点矢量形状
var point = feature.geometry()
//提取点附近的栅格值,存放于空feature中
var imageValues = imageCollection.map(function(image){
//点附近的栅格值,Values为一个字典
var Values = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: 30
})
//image的system:index属性中存放着日期,获得该信息,并和Values一起赋予空feature
//由于feature可以合成为featureCollection,因此feature是map方法中很好的一个信息存储格式
var em_feature = ee.Feature(null, Values).set('system:index', image.get('system:index'))
return em_feature //每个image返回一个feature,整个imageCollection返回一个featureCollection
})
return imageValues
}
var PML_YHS = extracPixels(Yeheshan,PML)
Export.table.toDrive({
collection: PML_YHS,
description: 'PML in Yeheshan',
fileFormat: 'CSV'
});