Google Earth Engine – Union Polygons

dissolvegoogle-earth-enginepolygon

I am trying to compare the NDVI-values of different land cover classes over a certain time period and display it in a chart.
So in a first step, I'd like to extract the crop land cover and use its geometry to calculate just the NDVI of the croplands
This is my code so far.

var area = ee.FeatureCollection('users/jonathanreith/KK')
Map.centerObject(area,9);
var lc  = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3").select('landcover');

var crop = lc.eq(30)

// Convert the crop landcover to vectors.
var crop = crop.reduceToVectors({
  geometry: area,
  geometryType: 'polygon',
  eightConnected: false,
  labelProperty: 'landcover',
  scale: 300
});

print(crop)
var cropu = crop.union(1)
print(cropu)

//chart
var NDVITimeSeries = ui.Chart.image.seriesByRegion({
    imageCollection: l8,
    regions: cropu,
    reducer: ee.Reducer.mean()
});

Unfortunately, crop consists of thousands of features, while union somehow erases all the information and just leaves the outer bounding box.

So how do I create an union feature with its geometries intact?
My Code
I already checked these Q&As:

Best Answer

If I understand correct, you need a MultiPoint Feature for the TimeSeries. I think you just need to filter the 'crop' FeatureCollection from reduceToVectors for the features containing the crop landcover by:

crop = crop.filter(ee.Filter.equals('landcover',1))

then you can extract the feauteres as one MultiPolygon with:

var cropu = crop.geometry()