1

I want to find cloud cover of an image This is my code:

var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
    .filterBounds(district)
    .filterDate('2015-03-01','2015-05-01')
    .sort('CLOUD_COVER')
    .map(maskClouds)
    .median();

I tried this code:

var getCloudScores = function(image)
{
    //Get the cloud cover
    var value = ee.Image(image).get('CLOUD_COVER');
    return ee.Feature(null, {'score': value})
};

var results = landsat.map(getCloudScores);

print(Chart.feature.byFeature(results));

It is giving me error:

landsat is not defined in this scope.

How do I calculate cloud cover and which variable I should use in place of landsat?

  • landsat is not defined in this scope because you don't have an imageCollection called landsat. Use the cloud scores function on your image and you should get an answer. – JepsonNomad Jul 12 at 6:59
1

I don't think it would make sense to get a cloud score from an imageCollection that has been reduced to a single median image. Instead, by removing the cloud mask, median reducer, and sorting step when you assign your imageCollection, you can map the getCloudScores function to all images in the collection. Note that I include a different district because yours isn't declared in the code you provide. Additionally, I made the date filter a little longer to demonstrate what the cloud cover time series looks like with more than just 3 observations.

var maineCounties = ee.FeatureCollection('TIGER/2016/Counties')
  .filter(ee.Filter.eq('NAME', 'Waldo'));
print(maineCounties);
var district = maineCounties;

var imageColl = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
    .filterBounds(district)
    .filterDate('2015-03-01','2015-08-01');
print("image",imageColl);


var getCloudScores = function(image)
{
    //Get the cloud cover
    var value = image.get('CLOUD_COVER');
    return ee.Feature(null, {'score': value});
};

var results = imageColl.map(getCloudScores);

print(Chart.feature.byFeature(results));

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.