0

I have written a code in GEE retrieves images from sentinel 1 and suppose to display those images. I have created a for loop that suppose to display those images but for some reason I am getting the error message:

Required argument (index) missing to function: List.get(list, index)

Returns the element at the specified position in list. A negative index counts backwards from the end of the list.

Args:

list (List): Undocumented. index (Integer): Undocumented.

Returns the element at the specified position in list. A negative index counts backwards from the end of the list.

I saw that this problem is common but I don't find the problem in my code that led to this error.

this is my code:

//var geometry=geometry2;


// Load the Sentinel-1 ImageCollection.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD');

// Filter by metadata properties.
var vh = sentinel1
  // Filter to get images VH dual polarization.
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  // Filter to get images collected in interferometric wide swath mode.
  .filter(ee.Filter.eq('instrumentMode', 'IW'))
    // reduce to VH polarization
  .select('VH')
   // filter 10m resolution
  .filter(ee.Filter.eq('resolution_meters', 10))
  .filterBounds(geometry);

  // Filter to get images from different look angles.
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
//var vhAscending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'));


//fiter date
var vhDesc = vhDescending.filterDate(ee.Date('2015-08-01'), ee.Date('2019-10-08'));
//var vhAsce = vhAscending.filterDate(ee.Date('2019-06-01'), ee.Date('2019-10-08'));

//clip the dataset according to the geometry
var clippedCol=vhDesc.map(function(im){ 
  return im.clip(geometry);
});

//count how many images we have in the collection-
var count=clippedCol.size();
print('Number of Images',count);



//create list of images
var ListDesc =(clippedCol.toList(clippedCol.size()));

var ListofNumbers=[0,1,2,3,5,17,20,28];


//display the images using loop
for (var i in ListofNumbers) {
  var image = ee.Image(ListDesc.get(ListDesc[i]));
  Map.addLayer(image,{}, i);

}

code update:

//var geometry=geometry2;


// Load the Sentinel-1 ImageCollection.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD');

// Filter by metadata properties.
var vh = sentinel1
  // Filter to get images VH dual polarization.
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  // Filter to get images collected in interferometric wide swath mode.
  .filter(ee.Filter.eq('instrumentMode', 'IW'))
    // reduce to VH polarization
  .select('VH')
   // filter 10m resolution
  .filter(ee.Filter.eq('resolution_meters', 10))
  .filterBounds(geometry);

  // Filter to get images from different look angles.
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
//var vhAscending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'ASCENDING'));


//fiter date
var vhDesc = vhDescending.filterDate(ee.Date('2015-08-01'), ee.Date('2019-10-08'));
//var vhAsce = vhAscending.filterDate(ee.Date('2019-06-01'), ee.Date('2019-10-08'));

//clip the dataset according to the geometry
var clippedCol=vhDesc.map(function(im){ 
  return im.clip(geometry);
});

//count how many images we have in the collection-
var count=clippedCol.size();
print('Number of Images',count);



//create list of images
var ListDesc =(clippedCol.toList(clippedCol.size()));

var ListofNumbers=[0,1,2,3,5,17,20,28];


//display the images using loop
for (var i in ListofNumbers) {
  var image = ee.Image(ListDesc.get(ListofNumbers,i));
  Map.addLayer(image,{}, i);}

  • You are calling ListDesc.map(...) before defining var ListDesc – Léo M Oct 10 at 8:54
  • sorry I have put the wrong code, I edited it. and Now I get another error message- Required argument (index) missing to function: List.get(list, index) Returns the element at the specified position in list. A negative index counts backwards from the end of the list. Args: list (List): Undocumented. index (Integer): Undocumented. – Reut Oct 10 at 9:02
  • At the end of your code, you wrote ListDesc.get(ListDesc[i]) but this function requires two arguments, first the list and then the index. I would suggest to try something like ListDesc.get(ListDesc,i) instead. – Léo M Oct 10 at 9:06
  • that didn't work – Reut Oct 10 at 9:07
  • 1
    Ok, according to the documentation ( developers.google.com/earth-engine/api_docs#ee.list.get ), I would replace the whole line var image = ee.Image(ListDesc.get(ListofNumbers,i)) by var image = ee.Image(ee.List.get(ListDesc,ListofNumbers[i])) or var image = ee.Image(ListDesc.get(ListofNumbers[i])) – Léo M Oct 10 at 9:20
0

There are 2 issues here:

  1. The documentation for List.get says:

ee.List.get

Returns the element at the specified position in list. A negative index counts backwards from the end of the list.

Usage Returns List.get(index) Object Argument Type Details this: list List index Integer

  1. when using the expression for (var i in ListofNumbers), i is the index of the list, and not the element. So, you have to get the element using that index.
var ListDesc = ee.List([
  ee.Image.constant(1), 
  ee.Image.constant(2),
  ee.Image.constant(3)])

var ListofNumbers = [0, 2];


//display the images using loop
for (var i in ListofNumbers) {
  var index = ListofNumbers[i]
  var image = ee.Image(ListDesc.get(index))
  Map.addLayer(image, {}, index.toString())
}

https://code.earthengine.google.com/df59d380138a4e4b5a390376d6633d81

  • thank you for your answer, I didn't understand what is the first part (ListDec) that you have created, why is it composed of 3 images? – Reut Oct 10 at 12:11
  • it's just an example of a list of images.. shouldn't be relevant to your question. If it is relevant, then the issue may come from there – Rodrigo E. Principe Oct 10 at 12:51
  • yes I know it's an example, but if you could elaborate a little about it it will make it more clear for me – Reut Oct 10 at 12:52
  • 1
    var ListDesc = ee.List([ee.Image.constant(1), ee.Image.constant(2), ee.Image.constant(3)]) should be a list of image just like your var ListDesc =(clippedCol.toList(clippedCol.size()));. Copy and paste my for loop to replace yours ans see how it goes – Rodrigo E. Principe Oct 10 at 13:36

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.