I would like to create an ImageCollection, in specific months for the L5 with a filter that returns only one image per year, which can be the image with less cloud coverage, then apply a spectral linear mixing model and export all processed images to the google drive. The problem occurs when I apply the function of the spectral linear mixture model to the distinct year collection I created. I believe the problem lies in this collection. I have no experience with GEE, could someone help me?

This is what I have so far:


var bacia = ee.FeatureCollection("users/geodenilson/Bacia_Carlos");
var roi = bacia.geometry();

// define custom function for exporting images to drive
var ExportCol = function(col, folder, scale, type,
                     nimg, maxPixels, region) {
type = type || "float";
nimg = nimg || 500;
scale = 30 || 1000;
maxPixels = maxPixels || 1e10;

var colList = col.toList(nimg);
var n = colList.size().getInfo();

for (var i = 0; i < n; i++) {
  var img = ee.Image(colList.get(i));
  var id = img.id().getInfo();
  region = roi || img.geometry().bounds().getInfo()["coordinates"];

  var imgtype = {"float":img.toFloat(),

    description: 'LANDSAT_5_'+id,
    folder: folder,
    //fileNamePrefix: id,
    region: region,
    scale: scale,
    maxPixels: maxPixels})

var getFractionssn = function(ModeloMistura){
    // Define Endmembers
    var endmemberssn =[
            [150.0, 430.0, 270.0, 4300.0, 1500.0, 550.0], /*gv*/
            [1200.0, 2400.0, 3250.0, 4600.0, 5500.0, 3600.0], /*soil*/
            [160.0, 300.0, 170.0, 150.0, 50.0, 30.0] /*water*/
    // Uminxing Data
    var unmixedsn = (ModeloMistura)
                  .select('B1','B2','B3','B4','B5', 'B7')

  var detexsn = unmixedsn.expression(
    '120*(Soil/GV)+20', {
      'Soil': unmixedsn.select (1),
      'GV': unmixedsn.select (0)});

    return detexsn;

var lsCol = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
  .filter(ee.Filter.dayOfYear(182, 243))
  // Add the observation year as a property to each image.
  .map(function(img) {
    return img.set('year', ee.Image(img).date().get('year'));

// Make a distinct year collection; one image representative per year.
var distinctYears = lsCol.distinct('year').sort('year');

var result = distinctYears.map(getFractionssn)

ExportCol(result, 'GEE_output', 30)

1 Answer 1


There is not so much wrong with the code. Just sometimes you will need to specifically cast an ee.Feature to an ee.Image. Not sure where and why this occasionally happens, maybe one of the GEE team can answer that question.

// Uminxing Data
var unmixedsn = ee.Image(ModeloMistura) // cast to an ee.Image
              .select('B1','B2','B3','B4','B5', 'B7')

link full code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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