Recently I've been trying to print time series for different regions and show them in the same plot. Everything goes fine if I exclude the 4th region into the time series (1-3 time series are fine). But when I add the 4th region, time series points at other locations are gone. The output plot only shows the time series of the last region (only remains 2 points of other regions).
So the problem is: how to add the time series of the 4th region into the plot?
Excluding the 4th region in the feature collection would work properly, but I don't want to omit it.
var timeField = 'system:time_start';
// Define test regions.
var regions = ee.FeatureCollection([ // Test Regions are in Hunan, China.
ee.Feature( // Region 1
ee.Geometry.Rectangle(113.201806473291, 27.6867096858736, 113.251537728778, 27.7276180415286), {label: 'Region1'}),
ee.Feature( // Region 2
ee.Geometry.Rectangle(113.152404668942, 27.6389241071109, 113.177553060666, 27.6780758597365), {label: 'HengJiangCun'}),
ee.Feature( // Region3
ee.Geometry.Rectangle(113.196381164761, 27.7769042331009, 113.216382570871, 27.7999150021881), {label: 'ChenJiaBa'}),
ee.Feature( // Region4 Adding this region would omit most of the points
ee.Geometry.Rectangle(113.038857564920, 27.9581880215077, 113.042355165475, 27.9719283228899), {label: 'ZhaoShanXiang'}),
]);
// Add base maps.
Map.addLayer(regions, {}, 'Test Regions'); // Layer: Test Regions.
print(regions)
// Load Sentinel-2 TOA reflectance data.
var masked = S2
.filterDate('2017-01-01', '2017-12-31')
.filterBounds(regions);
print(masked);
// Function to calculate NDVI in S2 images.
function S2NDVI(image){
var bands = image.select('B4','B8');
var NDVI = bands.expression('(b(1)-b(0))/(b(0)+b(1))').select(['B8'],['NDVI']);
//return NDVI;
return image.addBands(NDVI);
}
// Calculate S2 NDVI.
var S2VI = masked.map(S2NDVI);
print(S2VI);
// Generating 25 percentile time series chart.
var reducer = ee.Reducer.percentile([25]);
// Time series chart settings.
var TSChart = ui.Chart.image.seriesByRegion(
S2VI.select('NDVI'), regions, reducer, 'NDVI', 20, 'system:time_start','label')
.setChartType('ScatterChart')
.setOptions({
title: 'CI-Red Edge time series at 4 regions',
vAxis: {title: 'CI Red Edge'},
lineWidth: 1,
pointSize: 4,
series: {
0: {color: '008744'}, // Region 1
1: {color: '0057e7'}, // Region 2
2: {color: 'd62d20'}, // Region 3
3: {color: 'ffa700'}, //Region 4
}});
print(TSChart);
Map.addLayer(S2VI.select('NDVI'),{},'Sentinel VI Collection');