Google Earth Engine – How to Add Cloud Cover as Band in Image Collection Using GEE Python API

geemapgoogle-earth-enginegoogle-earth-engine-javascript-apipython

I am looking for percentage of cloud cover in my study region from landsat images. Here is the code I have got so far:

    def cloudcover(image):
        value = image.get("CLOUD_COVER_LAND")
        return image.addBands(value)

    collection = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') \
    .map(cloudcover) \
    .select("CLOUD_COVER_LAND") \
    .filterBounds(polygon)
    
    listOfPoints = ee.FeatureCollection(points)
    col_med = collection.median()
    #extract values
    geemap.extract_values_to_points(listOfPoints, col_med, out_csv, scale= 30, crs = 'EPSG:4326')

But I keep getting this error:

EEException: reduce.median: Error in map(ID=LC08_166053_20180115):
Image.addBands: Parameter 'srcImg' is required.

Best Answer

When getting properties from an image of feature you typically have to cast it to the correct type before using it, or get it as the expected type directly:

value = image.getNumber("CLOUD_COVER_LAND")

or

value = ee.Number(image.get("CLOUD_COVER_LAND"))

Related Question