Google earth engine制作时间序列动画GIF
情景分析
- 适用于时间序列动态变化分析中
- 制作时间序列Sentinel-1影像动态图
- 基于Sentinel-1提取水体范围及制作动态图
Sentinel-1影像动态图
利用Google earth engine云平台制作2015年—2022年时间序列的Sentinel-1 VV极化动态变化图GIF。
代码如下:
///Sentinel-1影像动态图
var Sl = ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(miyunshuiku).select(['VV']);
var distyearhb = [];
for (var year=2015;year<2023;year++)
{
print(year);
var startDate = ee.Date.fromYMD(year, 07,01);
var endDate = ee.Date.fromYMD(year, 10,01);
var distyear="S1"+year
print(distyear)
var distyear = Sl.filterDate(startDate, endDate).mean();
print(distyear)
distyearhb.push(distyear)
}
print(distyearhb)
var collection=ee.ImageCollection.fromImages(distyearhb)
print(collection)
var palettes = require('users/gena/packages:palettes');
var visParams = {
min:-25,
max: 5,
palette: palettes.colorbrewer.Blues[9].reverse(),
};
var rgbVis = collection.map(function(img) {
return img.visualize(visParams).clip(miyunshuiku);
});
print(rgbVis)
// Define GIF visualization parameters.
var gifParams = {
'region': miyunshuiku,
'dimensions': 600,
'crs': 'EPSG:3857',
'framesPerSecond': 5
};
// Print the GIF URL to the console.
print(rgbVis.getVideoThumbURL(gifParams));
// Render the GIF animation in the console.
print(ui.Thumbnail(rgbVis, gifParams));
结果图如下:
基于Sentinel-1提取水体范围及制作动态图
代码如下:
//定义Sentinel-1水体指数SDWI计算公式
function SDWI_V1(Sen1) {
var VH = Sen1.select("VH");
var VV = Sen1.select("VV");
var x = VV.multiply(VH).multiply(10);
var y=(x).log();
var sdwi=y.subtract(8);
return sdwi;
}
//根据边界筛选数据集
var Sl = ee.ImageCollection('COPERNICUS/S1_GRD').filterBounds(miyunshuiku);
//建立一个空列表
var classifiyearhb = [];
//循环提取2015-2022年水体面积
for (var year=2015;year<2022;year++)
{
print(year);
var startDate = ee.Date.fromYMD(year, 07,01);
var endDate = ee.Date.fromYMD(year, 10,01);
var distyear="S1"+year
print(distyear)
var distyear = Sl.filterDate(startDate, endDate).mean().clip(miyunshuiku);
var SDWIyear="SDWI"+year
var SDWIyear=SDWI_V1(distyear).select("VV").rename("sdwi");
print(SDWIyear)
// Make a FeatureCollection from the hand-made geometries.
var polygons = ee.FeatureCollection([
ee.Feature(water, {'class': 1}),
ee.Feature(nowater, {'class': 0})
]);
// Get the values for all pixels in each polygon in the training.
var training = SDWIyear.sampleRegions({
// Get the sample from the polygons FeatureCollection.
collection: polygons,
// Keep this list of properties from the polygons.
properties: ['class'],
// Set the scale to get Landsat pixels in the polygons.
scale: 10
});
// Create an SVM classifier with custom parameters.
var classifier = ee.Classifier.libsvm({
kernelType: 'RBF',
gamma: 0.5,
cost: 10
});
// Train the classifier.
var trained = classifier.train(training, 'class');
var classifiyear="classifi"+year
// Classify the image.
var classifiyear = SDWIyear.classify(trained);
classifiyearhb.push(classifiyear)
}
//建立时间序列水体提取的影像数据集并制作动态图GIF
var classificollect=ee.ImageCollection.fromImages(classifiyearhb)
var visParams = {
min:0,
max: 1,
palette: ['white', 'blue']
};
var classifirgbVis = classificollect.map(function(img) {
return img.visualize(visParams).clip(miyunshuiku);
});
print(classifirgbVis)
// Define GIF visualization parameters.
var gifParams = {
'region': miyunshuiku,
'dimensions': 600,
'crs': 'EPSG:3857',
'framesPerSecond': 5
};
// Print the GIF URL to the console.
print(classifirgbVis.getVideoThumbURL(gifParams));
// Render the GIF animation in the console.
print(ui.Thumbnail(classifirgbVis, gifParams));
结果图如下:
参考资料
[1] https://blog.csdn.net/qq_35794085/article/details/124394997
[2] https://developers.google.cn/earth-engine/tutorials/community/modis-ndvi-time-series-animation
[3] https://blog.csdn.net/qq_31988139/article/details/119949649
[4] https://blog.csdn.net/puzige/article/details/117319908
[5] https://developers.google.com/earth-engine/guides/classification