Reduce a Landsat Collection by Region in Earth Engine

by Trynaplot   Last Updated November 09, 2018 01:22 AM

ui.reduceRegions() seems to get tripped up by Landsat data. I've encountered the same error using Landsat 5, 7, and 8 and with several shapefiles so I'm confident it isn't a problem with the regions I'm providing. The scale I use (anywhere between 30m and 6km) doesn't make a difference either. The weird thing is this doesn't happen with MODIS data. See here and here for more on reducing MODIS data.

The NDVI chart leads me to believe that the image collection is stacked up right, but both series1 and series2 plots fail with the following error:

Error generating chart: Collection.first: Error in map(ID=1): Collection.geometry: Unable to perform this geometry operation. Please specify a non-zero error margin.

Series1 and 2 should show (for series1) individual band values over the course of the year, and (for series2) NDVI values for individual counties over the course of the year.

Anyone have ideas on how to get past the error? Reproducible code below.

var cali = ee.FeatureCollection('ft:1S4EB6319wWW2sWQDPhDvmSBIVrD3iEmCLYB7nMM')
  .filter(ee.Filter.eq('StateName', 'California'));
print("cali shape",cali);

// This function gets NDVI from a Landsat 5 image.
var addNDVI = function(image) {
  return image.addBands(image.normalizedDifference(['B4', 'B3']).rename('NDVI'));
print("addNDVI function",addNDVI);

// This function clips images to the ROI feature collection
var clipToCol = function(image){
  return image.clipToCollection(cali);
print("clipToCol function",clipToCol);

// Load a Landsat collection, map the NDVI function over it.
var collection = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')
  .filterDate('2001-01-01', '2001-12-31')
print("TOA Col Preview",collection.first());

// Chart the data
var NDVIchart = ui.Chart.image.series({
  region: cali,
  reducer: ee.Reducer.mean(),
  scale: 6000
}).setOptions({title: 'NDVI in ROI'});
// Display the chart in the console.
print("NDVI chart",NDVIchart);

// Define a chart with one series in the region, averaged by DOY.
// Guide here:
var series1 = ui.Chart.image.doySeries(
print("DOY series",series1);

var series2 = ui.Chart.image.doySeriesByRegion(
print("County series", series2);

Related Questions

Mapping a function over a Collection

Updated November 05, 2018 15:22 PM