2

I am trying to run this code with Google Earth Engine but I get an error on a Land sat 7 dataset.

expression is not a function

my code:

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T2_SR')
                  .filterDate('2018-01-01', '2018-12-31')
                  .filterBounds(ROI);
var albedo = dataset.expression(
  "((0.356*blue)+(0.130*red)+(0.373*nir)+(0.085*swir)+(0.072*swir2)- 0.018)/ 1.016",
  {
    red: dataset.select('B3'),
    blue:  dataset.select('B1'),
    nir:  dataset.select('B4'),
    swir:  dataset.select('B5'),
    swir2:  dataset.select('B7')
  });
0

1 Answer 1

2

expression appears to only work on images. So, you can instead use .map() to apply your expression as a function to the whole image collection. The code below will add albedo as an additional band to each image in the collection dataset (also note that I added a county from Maine as a stand-in ROI).

var maineCounties = ee.FeatureCollection('TIGER/2016/Counties')
  .filter(ee.Filter.eq('NAME', 'Waldo'));
print(maineCounties);
var ROI = maineCounties;

var albedo = function(image){
  var alb = image.expression(
  "((0.356*blue)+(0.130*red)+(0.373*nir)+(0.085*swir)+(0.072*swir2)- 0.018)/ 1.016",
  {
    'red': image.select('B3'),
    'blue':  image.select('B1'),
    'nir':  image.select('B4'),
    'swir':  image.select('B5'),
    'swir2':  image.select('B7')
  });
  return(image.addBands(alb.rename("albedo")));
};

var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T2_SR')
                  .filterDate('2018-01-01', '2018-12-31')
                  .filterBounds(ROI)
                  .map(albedo);

print("dataset",dataset);

var myAlbedo = dataset.select("albedo"); // To isolate just the albedo band
print("myAlbedo",myAlbedo); // Look at it
0

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.