1

I have a imported a KML as fusion table to GEE. This fusion table is type of FeatureCollection and contains 6 elements. I would like to create a time series of a raster (in this example MODIS LST), based on the feature. Meaning, my final goal is to get a chart (which I can export as csv), where the x-axis is the date and the y-axis is LST (or other raster value), per each feature in the feature collection, or one that contains all, which I can differentiate between them. I saw the GEE example script - Image Time Series By Region, but when I changed the feature collection there to my fusion table, I got one chart for all of my features, I assume this is the average of all of them.

What I got so far is this:

// Get  temperature data for 1 year.
var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(fc2)
                    .filterDate('2003-12-25', '2008-02-25')
                    .select('LST_Day_1km');

// Convert temperature to Celsius.
modisLST = modisLST.map(function(img){
  var date = img.get('system:time_start');
  return img.multiply(0.02).subtract(273.15).set('system_time_start', date);
});

// Create a function that takes an image, calculates the mean over a
// geometry and returns the value and the corresponding date as a 
// feature.
var createTS = function(img){
  var date = img.get('system_time_start');
  var value = img.reduceRegion(ee.Reducer.mean(), fc2).get('LST_Day_1km');
  var ft = ee.Feature(null, {'system:time_start': date, 
                            'date': ee.Date(date).format('Y/M/d'), 
                            'value': value});
  return ft;
};

// Apply the function to each image in modisLST.
var TS = modisLST.map(createTS);

// Create a graph of the time-series.
var graph = ui.Chart.feature.byFeature(TS, 'system:time_start', 'value');

print(graph.setChartType("ColumnChart")
          .setOptions({vAxis: {title: 'LST [deg. C]'},
                        hAxis: {title: 'Date'}}));

where fc2 is my fusion table that contains 6 features. How can I accomplished my goal?

  • 1
    You should give access to your feature collection fc2 to solve the problem perfectly, but I assume you're mistake is calling reduceRegion(), which returns the mean value over all the 6 geometries. Instead, you should call reduceRegions() on each image, which returns the featurecollection with the mean values augmented as properties to each feature. – Kuik Nov 20 '18 at 8:11
  • ee.FeatureCollection('ft:1NYL6hUez42eXOGs9iWx0g6NWbY6orkzXyJGamDM8') and it didn't work.. I get: Error generating chart: Image.reduceRegions, argument 'collection': Invalid type. Expected: FeatureCollection. Actual: Reducer and Image.reduceRegions, argument 'collection': Invalid type. Expected: FeatureCollection. Actual: Reducer – user88484 Nov 20 '18 at 17:01
2

As this is a common operation, there's a function to do it in one go, so you don't have to do your own multi-temporal aggregation: ui.Chart.image.seriesByRegion.

var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(fc2)
                    .filterDate('2003-12-25', '2004-02-25')
                    .select('LST_Day_1km');

// Convert temperature to Celsius.
modisLST = modisLST.map(function(img){
  return img.multiply(0.02).subtract(273.15).copyProperties(img, ['system:time_start'])
});

// Create a graph of the time-series.
var graph = ui.Chart.image.seriesByRegion({
  imageCollection: modisLST, 
  regions: fc2, 
  reducer: ee.Reducer.mean()
})
print(graph)

If you click on the box in the upper right corner of the chart, you can download the CSV used to generate the chart.

If, for some reason, you still want to do your own aggregation, you should use reduceRegions to reduce each region separately. The way you're doing it with reduceRegion, you are indeed getting the mean of all the regions. The downside of doing it yourself is that you then have to rearrange the results into something the charting API can understand.

  • Great, this is what I was looking for. – user88484 Nov 22 '18 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.