0

I am trying to do something similar, I have a feature collection which i want to map over an function, which access image in an asset. The image asset id is a combination of variable inside the function. which i am not able to concatenate because they are in computed object formats not strings. Also i get this error 'Actual value for parameter 'id' must be a constant.' My image lies in subset folders in earth engine assets

year=2019

def getarea(feature):
    
dist_bounds=ee.FeatureCollection('projects/remotesensing/assets/District_Boundaries')
    dist=dist_bounds.filterBounds(feature.geometry()).aggregate_array('District').get(0)
    state=dist_bounds.filterBounds(feature.geometry()).aggregate_array('STATE').get(0)
    
    result_image=ee.Image('projects/remotesensing/assets/CropImages/'+'/'+(dist)+(str((year))))
    clipped_image = result_image.clip(feature.geometry())
    area=clipped_image.reduceRegion(
          reducer= ee.Reducer.sum().group(
          groupField= 1,
          groupName= 'class',
      ),
      geometry= feature.geometry(),
      scale= 10,
      maxPixels= 1e10
      ).get('groups');

    props = {
        'crop': feature.get('crop_name'),
        'area': area
        }
    
    return ee.Feature(feature.geometry(), props)

1 Answer 1

0

As the error says, Image IDs must be constants, you can't compute one on the fly (for security reasons). You can filter an image collection down to a specific ID though.

collection.filter(ee.Filter.eq("system:index", computedID))

If your images are in a folder instead of a collection, move them over.

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.