两个数据集,一个点文件FeatureCollection,另一个Landsat8影像数据ImageCollection,现在遍历点文件中的每一个点,提取这个点位上所有影像的栅格值(波段值),并导出为csv,适用。
代码:
var firstlyr = ee.FeatureCollection("users/points");
var fqshp = ee.FeatureCollection("users/boundary");
function maskL8sr(image) {
// Bit 0 - Fill
// Bit 1 - Dilated Cloud
// Bit 2 - Cirrus
// Bit 3 - Cloud
// Bit 4 - Cloud Shadow
var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0);
var saturationMask = image.select('QA_RADSAT').eq(0);
// Apply the scaling factors to the appropriate bands.
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
// Replace the original bands with the scaled ones and apply the masks.
return image.addBands(opticalBands, null, true)
.addBands(thermalBands, null, true)
.updateMask(qaMask)
.updateMask(saturationMask);
}
// Map the function over one year of data.
var dataset = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterDate('2021-01-01', '2021-02-01')
.filterBounds(fqshp)
.map(maskL8sr);
print('images number:',dataset.size());
print(dataset);
var mapfunc = function(feat) {
var geom = feat.geometry();
var addProp = function(img, f) {
var newf = ee.Feature(f);
var values = img.reduceRegion({
reducer:ee.Reducer.first(),
geometry:geom,
scale:30,
maxPixels:1e11});
var values_array = ee.Algorithms.If(
values.get('SR_B1'),
values.toArray(['SR_B1','SR_B2','SR_B3','SR_B4','SR_B5','SR_B6','SR_B7']),
9999);
var fields_name = ee.String(img.get('system:index'));
return ee.Feature(newf.setMulti(ee.Dictionary.fromLists(ee.List([fields_name]),ee.List([values_array]))));
};
var newfeat = ee.Feature(dataset.iterate(addProp, feat));
return newfeat;
};
var newft = firstlyr.map(mapfunc);
Export.table.toDrive({
collection: newft,
description: 'newft',
fileFormat:'CSV',
folder:'newft',
fileNamePrefix:'newft'});
print('done!');
转自:“科研萌新”微信公众号
如有侵权,请联系本站删除!