I am importing 2 different shapefiles from assets to plot the time series chart of MODIS
but I am unable to make the feature collection out of these shapefiles
how to do that?
// 1st Shapefile
var Haryana_state = ee.FeatureCollection('users/abhilashaanu92/HaryanaBoundary');
Map.addLayer(Haryana_state);
// 2nd Shapefile
var Punjab_state = ee.FeatureCollection('users/abhilashaanu92/punjab_state_boundary');
Map.addLayer(Punjab_state);
// Combine both shapefile features into a single feature collection.
var both_states = ee.FeatureCollection([Haryana_state, Punjab_state]);
Map.addLayer(both_states);
// Load MODIS vegetation indices data and subset annual images.
var vegIndices = ee.ImageCollection('MODIS/006/MOD13A1')
.filter(ee.Filter.date('2019-01-01', '2020-01-01'))
.select(['NDVI', 'EVI']);
// Define the chart and print it to the console.
var chart =
ui.Chart.image
.seriesByRegion({
imageCollection: vegIndices,
band: 'NDVI',
regions: both_states,
reducer: ee.Reducer.mean(),
scale: 500,
seriesProperty: 'label',
xProperty: 'system:time_start'
})
.setOptions({
title: 'Average NDVI Value by Date',
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {
title: 'NDVI (x1e4)',
titleTextStyle: {italic: false, bold: true}
},
lineWidth: 5,
colors: ['f0af07', '0f8755', '76b349'],
});
print(chart);
if I put the name of a single shapefile variable in the regions then it is working but when I combine the 2 shapefiles into a feature collection then it is showing the error.
Error generating chart: Collection.geometry: Unable to use a collection in an algorithm that requires a feature or image. This may happen when trying to use a collection of collections where a collection of features is expected; use flatten, or map a function to convert inner collections to features. Use clipToCollection (instead of clip) to clip an image to a collection.
How to rectify this?
After adding .flatten() as in here
var both_states = ee.FeatureCollection([Haryana_state, Punjab_state]).flatten();
both the polygons merged into a single layer and the chart drawn was of the Punjab region only, as the values I cross-checked after exporting the CSV of Chart.
but I want a chart something like this, where the time-series is of both Haryana and Punjab on the same chart.