我正在尝试计算每个水域的水域和每个波段的统计数据,看看是否有季节性变化。
导出的 .csv 文件在加入之前只有列 ("GNIS_ID","AreaSqKm","waterArea")。我打印了变量 Join,它确实包含我需要的所有列。为什么它们没有显示在导出的 CSV 文件中?我错过了什么?
var CollectMonth = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(HI_poly)
.sort('CLOUD_COVER')
.filterDate('2014-01-01', '2014-01-30')
.map(function(image){return image.clip(USGS_WBD)}) // clip the images by the;
print(CollectMonth);
// Calculate Water Area
var waterThreshold = 324;
var WaterAreaFunction = function(image){
//add the water band to the image
var water = image.select(['pixel_qa']).rename('water');
//get pixels equal the threshold
var water01 = water.eq(waterThreshold);
//mask those pixels from the image
image = image.updateMask(water01).addBands(water);
var area = ee.Image.pixelArea();
var waterArea = water01.multiply(area).rename('waterArea');
image = image.addBands(waterArea);
var stats = waterArea.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: USGS_WBD,
scale: 30,
});
return image.set(stats);
};
var l8Mosaic = CollectMonth.map(WaterAreaFunction).mosaic().multiply(0.0001);
var l8Mosaic_area = l8Mosaic.divide(1000000)
//statistics
var WBD_area = l8Mosaic_area.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.sum(),
scale: 30 // resolution
}).select(["GNIS_ID","AreaSqKm","waterArea"]);
print("area:",WBD_area);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_mean","B2_mean","B3_mean","B4_mean","B5_mean","B6_mean","B7_mean"])
var WBD_mean = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.mean(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_mean","B2_mean","B3_mean","B4_mean","B5_mean","B6_mean","B7_mean"])
print("mean:",WBD_mean);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_median","B2_median","B3_median","B4_median","B5_median","B6_median","B7_median"])
var WBD_median = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.median(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_median","B2_median","B3_median","B4_median","B5_median","B6_median","B7_median"])
print("median:",WBD_median);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_min","B2_min","B3_min","B4_min","B5_min","B6_min","B7_min"])
var WBD_min = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.min(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_min","B2_min","B3_min","B4_min","B5_min","B6_min","B7_min"])
print("min:",WBD_min);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_max","B2_max","B3_max","B4_max","B5_max","B6_max","B7_max"])
var WBD_max = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.max(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_max","B2_max","B3_max","B4_max","B5_max","B6_max","B7_max"])
print("max:",WBD_max);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_WBD10","B2_WBD10","B3_WBD10","B4_WBD10","B5_WBD10","B6_WBD10","B7_WBD10"])
var WBD10 = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.percentile([10]),
scale: 30 // resolution
}).select(["GNIS_ID","B1_WBD10","B2_WBD10","B3_WBD10","B4_WBD10","B5_WBD10","B6_WBD10","B7_WBD10"])
print("WBD10:",WBD10);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_WBD90","B2_WBD90","B3_WBD90","B4_WBD90","B5_WBD90","B6_WBD90","B7_WBD90"])
var WBD90 = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.percentile([90]),
scale: 30 // resolution
}).select(["GNIS_ID","B1_WBD90","B2_WBD90","B3_WBD90","B4_WBD90","B5_WBD90","B6_WBD90","B7_WBD90"])
print("WBD90:",WBD90);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_std","B2_std","B3_std","B4_std","B5_std","B6_std","B7_std"])
var WBD_std = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.stdDev(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_std","B2_std","B3_std","B4_std","B5_std","B6_std","B7_std"])
print("std:",WBD_std);
var WBD_value = l8Mosaic.select(["B1","B2","B3","B4","B5","B6","B7"])
.rename(["B1_variance","B2_variance","B3_variance","B4_variance","B5_variance","B6_variance","B7_variance"])
var WBD_variance = WBD_value.reduceRegions({
collection: USGS_WBD,
reducer: ee.Reducer.variance(),
scale: 30 // resolution
}).select(["GNIS_ID","B1_variance","B2_variance","B3_variance","B4_variance","B5_variance","B6_variance","B7_variance"])
print("variance:",WBD_variance);
// =============== Join ============================
// Join two collection
// Use an equals filter to define how the collections match.
var filter = ee.Filter.equals({
leftField: 'GNIS_ID',
rightField: 'GNIS_ID'
});
// Define the join.
var innerJoin = ee.Join.inner();
// Apply the join.
var Join = innerJoin.apply(WBD_area, WBD_mean, filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// Apply the join.
var Join = innerJoin.apply(Join, WBD_median,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD_min,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD_max,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD10,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD90,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD_std,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
// // Apply the join.
var Join = innerJoin.apply(Join, WBD_variance,filter);
Join = Join.map(function(pair) {
var f1 = ee.Feature(pair.get('primary'));
var f2 = ee.Feature(pair.get('secondary'));
return f1.set(f2.toDictionary());
});
print(Join)
// Export the FeatureCollection.
Export.table.toDrive({
collection: Join,
description: 'Monthly_Lansat8_SR',
fileFormat: 'CSV'
});