clip image results to a ROI in Google Earth Engine

mikejwilliamson picture mikejwilliamson · Jul 24, 2018 · Viewed 8.4k times · Source

I have developed a time series of sea surface temperatures for a specific region of interest in Google Earth Engine. Running the code below displays the sea surface temperatures from the entire data set

Map.addLayer(BIOT)

// Load an image.
var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst')
  .filterDate('2013-01-01', '2018-01-01')
  .filterBounds(BIOT);

print('sst', sst)

var TS1 = Chart.image.series(sst, BIOT,  ee.Reducer.mean(),
1000, 'system:time_start').setOptions({title: 'BIOT SST',vAxis: {title: 'SST 
Celsius'},
});
print(TS1);

Map.setCenter(72.25, -6.8, 7); //lat, long, zoom
Map.addLayer (sst, {'min': 23, 'max': 34, 'palette':"0000ff,32cd32,ffff00,ff8c00,ff0000"});

I tried to add the code:

Map.addLayer(sst.clip(BIOT))

To clip the data to a region I have already defined (BIOT) but the image still displays all the data for all regions, rather than the one I have specified. Any ideas? Any help appreciated!

Answer

Val picture Val · Jul 25, 2018

sst is an ImageCollection, which can't be clipped this way. This also means, when you execute Map.addLayer(sst), you're mapping all images within the collection, if they are spatially overlapping, they will cover each other up.

If you still want to do that, and you only need the data from your AOI BIOT anyways, you can add .map(function(image){return image.clip(BIOT)}) when you create your ImageCollection.

// Load an image **collection**.
var sst = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst')
  .filterDate('2013-01-01', '2018-01-01')
  .filterBounds(BIOT)
  .map(function(image){return image.clip(BIOT)}) ;

This will iterate over each image in the collection and clip it to BIOT.