在我的项目中,我想收集 VIIRS 数据并获得总和值。收集完后我下载了Excel格式。在此代码中,我为美国收集了。我想自动收集土耳其 81 个州的信息。我有 81 个不同的形状文件,它们的名称是 01,02,03...80,81。我如何组织我的代码以针对 81 个州自动运行此代码?
// import USA
var usaBoundary = ee.FeatureCollection("projects/ee-tabakogluayca99/assets/ABD");
// Simplify geomtri
var geometry = usaBoundary.geometry().simplify(10000); // Toleransı uygun bir şekilde ayarlayın
Map.centerObject(geometry);
var ntlCollection = ee.ImageCollection("NOAA/VIIRS/DNB/ANNUAL_V21");
var startYear = 2014;
var endYear = 2024;
var startDate = ee.Date.fromYMD(startYear, 1, 1);
var endDate = ee.Date.fromYMD(endYear + 1, 1, 1);
var band = 'average';
var ntlFiltered = ntlCollection
.filter(ee.Filter.date(startDate, endDate))
.filter(ee.Filter.bounds(geometry))
.select(band);
print('Filtered NTL collection', ntlFiltered);
//Map.addLayer(ntlFiltered);
var projection = ntlFiltered.first().projection();
var resolution = projection.nominalScale();
print('NTL Image Resolution', resolution);
// Function to calculate average night light for each image
var calculateAverageLight = function(image) {
var stats = image.reduceRegion({
reducer: ee.Reducer.mean(), // Use mean reducer for average
geometry: geometry,
scale: resolution,
maxPixels: 1e10
});
var avgLight = stats.getNumber(band);
var feature = ee.Feature(null, {
'avg_light': avgLight,
'system:time_start': image.get('system:time_start')
});
return feature;
};
// Apply the function to the filtered ImageCollection
var ntlTimeSeriesAvg = ntlFiltered.map(calculateAverageLight);
print('Average Nighttime Lights Time Series', ntlTimeSeriesAvg);
// Create a chart for average nighttime lights
var chartAvg = ui.Chart.feature.byFeature({
features: ntlTimeSeriesAvg,
xProperty: 'system:time_start',
yProperties: ['avg_light']
})
.setChartType('ColumnChart')
.setOptions({
title: 'Average Nighttime Lights Time Series for ' + 'USA',
vAxis: {
title: 'Average Lights',
viewWindow: {
min: 0
},
gridlines: { color: '#c7beb5' }
},
hAxis: {
title: '',
format: 'YYYY-MM',
gridlines: { color: '#c7beb5' }
},
legend: { position: 'none' }
});
print(chartAvg);
// Export the first image of the clipped ImageCollection (average lights) to Google Drive
/*
var imageToExportAvg = map_ic.first();
Export.image.toDrive({
image: imageToExportAvg,
description: 'VIIRS_Wyoming_Annual_Average_Lights',
folder: 'GEE_exports',
region: geometry,
scale: resolution.toInt(),
maxPixels: 1e10
});
*/
各州的形状文件有 81 个不同的文件吗?您可以将它们组合成一个功能集合,然后将当前的解决方案映射到该集合上吗?