0

I am accessing the properties of an image collection in GEE. I have created an image collection and assigned it to the variable "collection". When accessing the date range I used the following syntax

//Create Image Collection
var collection = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
          .filter(ee.Filter.eq("WRS_PATH", 118))
          .filter(ee.Filter.eq("WRS_ROW", 56))
          .filterDate("2020-05-16", "2021-06-17");
Map.addLayer(collection)
Map.centerObject(collection, 9)
print("Collection: ", collection);

//Get date range
var dates = collection.get("date_range");
print ("dates: ", dates)
var daterange = ee.DateRange(dates.get(0), dates.get(1));
print("daterange: ", daterange)

This gives an error "dates.get is not a function. However if I create the "dates" variable with...

var dates = ee.List(collection.get("date_range"));

it all works fine. I don't really understand why this is as the "dates" variable appears to return the same list either way.

Hope someone can explain

1

Any time you use get() anywhere, the client-library has no way to know the result type (since it could be anything). In order to use the functions on the result (in this case, List.get), you need to specify the type of the output by either using getNumber, getString, etc. or by casting the result by wrapping it in the appropriate type.

https://developers.google.com/earth-engine/tutorials/tutorial_js_02#casting

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.