I am trying to make a yearly image collection using Landsat images, then trying to make a classification using Random forest for the image of the years 1990, 1995, 2000, 2005, 2010, 2015 and 2020.

I would like to know if it is possible to compute the area class (forest class) of each of them considering the forest definition >10% of tree cover and 0.5Ha. I have tried to write the script but I got 0 km2 for all of them as a result (see script below).

I am still a beginner in GEE.

Here is the code: https://code.earthengine.google.com/?scriptPath=users%2Frorohambi%2FRo20%3AManakara_sorona

  • Welcome to GIS SE. Please edit your question to include the pertinent code in the body of your text. This way if your link ever goes 404, your question remains valid for other users.
    – Aaron
    Apr 16, 2021 at 3:14

1 Answer 1


It is impossible because yearly images in Image Collections that you made did not preserve original scale of Landsat images (they have 111,319.49 m, 1.0 arc degree, instead of 30 m as you expected). So, expected 0.5 ha is not about 6 pixels. In these images, as Forest0, one pixel is corresponding to 1,239,202.88 ha; not 0.09 ha.

On the other hand, all images that you use for determining area (in ha because you divide by 10,000; not by 1,000,000 for obtaining km2) are empty because your conditions in these binary images do not work (they have not sense).

Following code snippet corroborates the obtaining of a scale different of 30 for Forest0 image (.gte(cc) condition in this image has not sense because unmasked value is 1 and cc is equal 10 so, obvious result is false and an empty image). However, in Forest0 image it can be obtained an area value; it is exemplified as follows.

var Forest0 = classified_1990
  .selfMask().rename('Forest0'); //forest id: 0 /Nonforest id: 1

print('scale Forest0', Forest0.projection().nominalScale());
Map.addLayer(Forest0, imageVisParam2, 'Forest0');

var Forest0_area = Forest0
      reducer: ee.Reducer.sum(),
      geometry: aoi,  // a geometry
      scale: 30,   // scale = 30 for landsat 8; this is not true scale
      maxPixels: 1e9  

print("Forest0_area in ha", Forest0_area.get('Forest0'));

As your aoi area was not adequately retrieved in your script, I assumed one rounded your points. Complete code is here. Following image has some relevant results of running the script in GEE console editor. However, you have to find an approach where scale is preserved.

enter image description here

  • Thank you so much xunilk. As I understand it, I have to manage to preserve the image scale to 30m (classified_1990 #30m if I want to get the right results. If I managed to preserve the scale, is the computation of forest imposing the forest definition impossible? The first sentence in the third paragraph is not really clear for me. So, fix the scale first and apply the code you have been suggested. I know that this change in scale starts after I have done the yearly collection (yearCompCol#30m) but I don’t understand the reason and so don’t know how to correct it.
    – HAMBI
    Apr 16, 2021 at 6:30
  • If you managed to preserve the scale the computation of forest imposing the forest definition is completely possible because you can use 'connectedPixelCount' adequately. My suggestion is to copy/paste the script with another name, comment all unnecessary lines for speeding up the execution of script and work momentarily with one image for founding out where scale was lost and fix it. For understanding how scale works in GEE you can start here: developers.google.com/earth-engine/guides/scale .
    – xunilk
    Apr 16, 2021 at 13:22
  • By the way, "all unnecessary lines for speeding up the execution of script" it should be read as all lines with 'print' and 'Map.addLayer' statements not important for debugging the script.
    – xunilk
    Apr 16, 2021 at 13:32

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.