0
print(table);
var ElementList = table.toList(3);
print(ElementList);
var i = 0;
for(i=0;i<3;i++){
  var element = ElementList.get(i);
  print(element);
  var dataset = ee.ImageCollection("COPERNICUS/S2_SR")
                .filterMetadata("CLOUD_COVERAGE_ASSESSMENT","less_than",20)
                .filterDate('2020-1-1','2021-1-1').filterBounds(element.geometry())
                .map(maskS2clouds).map(add_MNDWI).map(add_NDVI).map(add_EVI).map(add_USI).map(add_UWI);
print(dataset);

How to get the geometry of a feature? I searched the functions of Feature and found .geometry() as I wrote in the code, but I was told that this function is DEPRECATED and need to use Element.geometry() which I didn't know how to use it in my code.

table is a FeatureCollection and I turned it to a List, then get every Feature of it which is called element.

enter image description here

1 Answer 1

0

Can you provide a working example so that we can replicate the error? Also using for loops like this is not recommended, so consider using .map() (https://developers.google.com/earth-engine/tutorials/tutorial_js_03).

Finally most likely because you loop client side you have to cast your element as a feature like this

print(table);
var ElementList = table.toList(3);

print(ElementList);
var i = 0;
for(i=0;i<3;i++){
  var element = ee.Feature(ElementList.get(i));
  print(element);
  var dataset = ee.ImageCollection("COPERNICUS/S2_SR")
                .filterMetadata("CLOUD_COVERAGE_ASSESSMENT","less_than",20)
                .filterDate('2020-1-1','2021-1-1').filterBounds(element.geometry())
                .map(maskS2clouds).map(add_MNDWI).map(add_NDVI).map(add_EVI).map(add_USI).map(add_UWI);
print(dataset)};

But hard to tell exactly without a working example!

2
  • Thank you very much! I changed my code as you teached me and it worked now. I will update this question for you to repeat my error. Thank you.
    – Xingan
    Commented Jan 24, 2022 at 17:10
  • Glad it worked, if you then could accept the answer for future reference
    – Jobbo90
    Commented Jan 24, 2022 at 18:56

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.