0

I am new to the EE python API and am struggling to get a for loop (could eventually also use a map function) over a feature collection. My idea is to have one image and a FeatureCollection as input, clip the image using my feature in the Collection, and store each clipped image in an image collection, which should thus be the return of my function.

After long readings and unsuccessfully trying to adapt GEE codes into python using map functions, I decided to go for a for loop like the one below:

def wrap (image, featCol):
   
    imgColBase = ee.ImageCollection([])
    iteration = featCol.size().getInfo()

    for i in range (iteration):
        subFeat = ee.FeatureCollection(featCol.toList(i))
        subImg = image.clip(subFeat)
        imgColBase = imgColBase.fromImages(subImg)

    return imgColBase

resultWrap = wrap(lossImage, bufferedPoints) 

Where my lossImage is the input image, and my bufferedPoints is my Feature Collection. I eventually get an Image Collection out of the function, but can't make much with (it does not give me its size() or I can't add an single image on a map using Map.addLayer).

Any idea?

1 Answer 1

0

Simply map over the features and return a clipped image. You'll need to specify (via a cast) that the result is an image collection.

ic = ee.ImageCollection(featColl.map(lambda f : image.clip(f.geometry())))

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.