I am trying to calculate the area of six landcover classes within a polygon. However the proportions I get back do not add up to one. For example:

var CL = ee.ImageCollection('USDA/NASS/CDL').select('cropland') //crop data layer for USA
                  .filter(ee.Filter.date('2009-01-01', '2009-12-31')); //example year

var area = ee.Image.pixelArea(); 

// I am reclassifying all images to six basic categories
// 1 - corn
// 2 - cotton
// 3 - soybeans
// 4 - other crop
// 5 - native vegetation (loosely defined)
// 6 - non habitat

var propNames = ee.List(['from', 'to']);
var fromToList = ee.List(
    reducer: ee.Reducer.toList().repeat(propNames.size()),
    selectors: propNames

var from = fromToList.get(0);
var to = fromToList.get(1);

var remapping = function(image) {
  return image.remap(from, to, null, 'cropland');

var CL2 = CL.map(remapping);


var buffed = geometry.buffer(2500);

var geom_area = buffed.area();
var fcomp = CL2.filterBounds(buffed);

var fcomp_corn = fcomp.first()

var fcomp_cotton = fcomp.first()
var fcomp_soy = fcomp.first()
var fcomp_other = fcomp.first()
var fcomp_native = fcomp.first()
var fcomp_nonhabit = fcomp.first()


var area_image = fcomp_corn.addBands(fcomp_cotton)

var areas = area_image.reduceRegion({
geometry: buffed,
scale: 30,

print("geometry area",geom_area);


gives me the following proportions

Landcover proportion
corn 0.0278
cotton 0.0000
native 0.6739
nonhabitat 5.1639
other 0.0039
soy 0.0025

Obviously, 'nonhabitat' is wrong here. Does anyone know what is going wrong in my code?

here is the GEE link: https://code.earthengine.google.com/9380d97e4489f43f20787bc79bdc53c2

1 Answer 1


I used a simpler approach for calculating areas based in your fcomp image. Code snippet looks as follows and complete code is here.

var fcomp2 = fcomp.first();

var area_image2 = fcomp2

//print("area_image2", area_image2);

var mergedAllFunction = function(image) {

 var thres1 = area_image2.eq(1).rename('corn');
 var thres2 = area_image2.eq(2).rename('cotton');
 var thres3 = area_image2.eq(3).rename('soy');
 var thres4 = area_image2.eq(4).rename('other');
 var thres5 = area_image2.eq(5).rename('native');
 var thres6 = area_image2.eq(6).rename('nonhabit');

 return image.addBands(area_image2).addBands([thres1, thres2, thres3, thres4, thres5, thres6]);

var median = CL.median();

var merged = mergedAllFunction(median);

//print("merged", merged);

var areas_c = merged
    .select(['corn', 'cotton', 'soy', 'other', 'native', 'nonhabit'])
      reducer: ee.Reducer.sum(),
      geometry: buffed,  // a geometry
      scale: 30,   
      maxPixels: 1e9  

print("complete areas in square meters", areas_c); //complete areas in square meters

print("areas sum", ee.List(areas_c.values()).reduce(ee.Reducer.sum()));

var areas_p = merged
    .select(['corn', 'cotton', 'soy', 'other', 'native', 'nonhabit'])
      reducer: ee.Reducer.sum(),
      geometry: buffed,  // a geometry
      scale: 30,   
      maxPixels: 1e9  

print("areas as proportion", areas_p); //areas as proportion

print("proportion areas sum", ee.List(areas_p.values()).reduce(ee.Reducer.sum()));

After running above code in GEE code editor, I got results of following image. It can be observed that sum areas is comparable with geometry area and the sum of obtained area proportions is 1; as expected (relative errors are very low in both cases).

enter image description here


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.