I am experimenting with cloud shadow masking approaches. My workflow so far looks like this:

var maskClouds = function (..) {
var mask = maskClouds (image);
var cloud_polygons = mask.reduceToVectors();
var cloudCoords = cloud_polygons.geometry().transform(crs).coordinates()

Now I want to iterate over each polygon's vertex and apply an equation to it to obtain cloud's shadow coordinates. The equation that I want to apply is different for X and Y so I can't just flatten and map over everything. The issue is that cloudCoords is a multiple nested list as seen on image below.

Output of cloudCoords

I have been banging my head against my keyboard for few days now and can't figure out how to do this. My approach at the moment is multiple nested ee.List.map() utilizing get and a reducer. I can convert it to a function that sort of does the job, but it's messy and not very clear. Especially line 46 is ridiculous, but I couldn't get it to work any other way. Is there a more elegant way to do this? Why does EE even require me to constantly cast the arguments into ee.List()??

enter image description here

enter image description here

1 Answer 1


Dictionaries (and features and lists) can hold any type of object, so any time you use get() you have to cast the result, because the client has no way to know what type its going to end up with (specifically because it is a type that will only be resolved in the future, once all your code gets sent to the EE server and evaluated).

There's no reason to use a reducer.first on line 46, you can simply use get(0) again.

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.