I'm trying to extract a historical series of ndvi by land cover class (in particular Trees, Shrubland and Grassland), using the ESA collection (ESA/WORLDCOVER/200V) and clipping on my study area (geometry: Palo) I followed several suggestions already given among the available questions, but I'll stop at this point (I attach script). it shows the following error:
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.'
if I try to run on a single class (ex. Trees) it runs but the chart shows as many lines as the polygons referred to the class. I therefore need to find a command (the equivalent of "dissolve" on QGIS) that merges all polygons of a given class together. I've already tried the various .dissolve commands but they don't work.
(this is a temporary script)
var ESA = ee.ImageCollection("ESA/WorldCover/v100").first();
var cover = ESA.select('Map').clip(Palo);
var class10 = cover.eq(10);
var class20 = cover.eq(20);
var class30 = cover.eq(20);
var Trees = cover.updateMask(class10)
.reduceToVectors({ geometry: Palo,
scale: 10,
geometryType:'polygon',
labelProperty: 'Trees',
});
var Shrub = cover.updateMask(class20)
.reduceToVectors({ geometry: Palo,
scale: 10,
geometryType:'polygon',
labelProperty: 'Shrubland'
});
var Grass = cover.updateMask(class30)
.reduceToVectors({ geometry: Palo,
scale: 10,
geometryType:'polygon',
labelProperty: 'Shrubland'
});
var regions = ee.FeatureCollection([
ee.Feature(Trees,{label : 'Trees'}),
ee.Feature(Shrub,{label : 'Shrubland'}),
ee.Feature(Grass,{label : 'Grassland'})]
);
var S2 = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(Palo)
.filterDate('2020-01-01','2020-01-31');
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']));
};
var S2 = S2.map(addNDVI);
var NDVI = S2.select(['nd']);
var NDVImed = NDVI.median();
//print('S2',S2);
var visParams = {
min: -0.1,
max: 1.0,
palette: [
'FFBB22', 'FFFF4C', '648C00',
],
};
var plotNDVI = ui.Chart.image.seriesByRegion(
S2,
regions,
ee.Reducer.mean(),
'nd',10)
.setChartType('LineChart')
.setSeriesNames(['Trees', 'Shrubland','Grassland'])
.setOptions({
interpolateNulls: true,
lineWidth: 1,
pointSize: 3,
title: 'NDVI annual evolution',
hAxis: {title: 'Date'},
vAxis: {title: 'NDVI'},
series: {0:{color: 'red'}
}
});
print(plotNDVI);