2021-04-12

var roi = pie.FeatureCollection('RESDC/WORLD_COUNTRY_BOUNDARY')
                            .filter(pie.Filter.eq("fcname","中国"));
visroi = {
     color: "ff0000ff", fillColor: "00000000", width: 1};
Map.addLayer(roi, visroi, "中国", false);
var chn = roi.getAt(0).geometry();
//定位地图中心
Map.centerObject(chn, 3);

//设置夜光数据预览参数及颜色组合
var visParams = {
     min: 0, max: 60,  
palette:['000000','4c3300','664401','7f5501','996601','b27702',  
'cc8802','e59902','ffad02','ffaf02','ffb102','ffb302','ffb502',  
'ffb702','ffb902','ffbb02','ffbd02','ffc002','ffc202','ffc402',  
'ffc602','ffc801','ffca01','ffcc01','ffce01','ffd001','ffd201',  
'ffd501','ffd701','ffd901','ffdb01','ffdd01','ffdf01','ffe101',  
'ffe300','ffe500','ffe700','ffea00','ffec00','ffee00','fff000',  
'fff200','fff400','fff600','fff800','fffa00','fffc00','ffff00']};  
//定义夜光指数计算函数
function calcNT(night, chn){
     
    var result = night.reduceRegion(pie.Reducer.mean(), chn, 1);
    return result;
}
//循环计算影像的夜光指数
var xSeries = [];
var chnNT = [];
for(var i = 2013; i < 2021; i++){
     
    var nightLight = pie.ImageCollection("VIIRS_VCMCFG/NIGHTTIME_LIGHTS")
                        .filterDate(i + "-01-01", i + "-12-31")
                        .map(function(image){
     
                            return image.select("avg_rad").divide(1000).rename("a_r");})
                        .mean();
print(String(i),nightLight);
Map.addLayer(nightLight, visParams, String(i), true);
var chnresult = calcNT(nightLight, chn);
xSeries.push(String(i));
chnNT.push(chnresult);
}
//动画演示 
Map.playLayersAnimation(xSeries, 2, 100); 

//添加图例
var data = {
     
    title: "夜光指数",
    colors: [ '#000000','#4c3300','#664401','#7f5501','#996601','#b27702', 
    '#cc8802','#e59902','#ffad02','#ffaf02','#ffb102','#ffb302','#ffb502',
    '#ffb702','#ffb902','#ffbb02','#ffbd02','#ffc002','#ffc202','#ffc402',
    '#ffc602','#ffc801','#ffca01','#ffcc01','#ffce01','#ffd001','#ffd201',
    '#ffd501','#ffd701','#ffd901','#ffdb01','#ffdd01','#ffdf01','#ffe101',
    '#ffe300','#ffe500','#ffe700','#ffea00','#ffec00','#ffee00','#fff000',
    '#fff200','#fff400','#fff600','#fff800','#fffa00','#fffc00','#ffff00'],
    step: 30
};
var style = {
     
    top: "80%",
    left: "40%",
    height: "70px",
    width: "350px"
};
var legend = ui.Legend(data. style);
Map.addUI(legend);

你可能感兴趣的:(笔记,RS,PIE,Engine)