I am currently trying to create a line chart for each land-cover type across three bands I selected from MODIS.
Problem is most of the ui.Chart
functions require a feature or an image. Please help?
// Create clipping function
var clipper = function(image){
return image.clip(geometry);
};
// Load the MODIS data that is being processed
// Clip the image collection
var filtered = ee.ImageCollection('MODIS/006/MOD09A1').map(clipper)
// Sort dates in descending order
.sort('system:time_start',false);
print(filtered);
// Create a visualization color scheme
var medVis = {
min: 0,
max: 8000,
// You have to specify one band to use a palette
bands:['sur_refl_b04'],
palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
};
// Load the first image
Map.centerObject(geometry,8);
Map.addLayer(filtered.first(),medVis,"Loading the most recent Image");
Map.addLayer(geometry, {}, 'Shapefile Outline');
// Get the recent image alone
var singleImage = filtered.first();
print(singleImage);
// Merge the featureCollections that have been created
// Create your own polygons here to make the code reproducible.
// It can be polygons or points that refer to a particular land cover type
var training = forest.merge(water).merge(bare);
print(training);
var mean = singleImage.select(['sur_refl_b02','sur_refl_b03','sur_refl_b04'])
.reduceRegions({
collection: training,
reducer: ee.Reducer.mean(),
scale: 500
})
.reduceColumns({
selectors: ['sur_refl_b02','sur_refl_b03','sur_refl_b04','class'],
reducer: ee.Reducer.mean().repeat(3).group({
groupField: 3,
groupName: 'class'})
});
print(mean, 'Band Means');
Is there also any way in which I can retain the names of the selectors in the dictionary created as well?
I have added a link to code based on Rodrigo's comment: https://code.earthengine.google.com/a84485d5cba393122e2a1c4c5ae17690
Best Answer
I missed the bounty, but anyhow I got an answer. See if this is what you needed..
link: https://code.earthengine.google.com/1bcc1a12e1771da8dc428333064e6422