1

Following the indication on Calculating number of pixels in polygon using Google Earthy Engine? I wrote this script:

var gfc =ee.Image('UMD/hansen/global_forest_change_2018_v1_6'); 
var lossyear = gfc.select(['lossyear']);
//For loop for each years
for (var py=0; py <19; py++){ 
 var year = py+2000;
 var y = py;
 var table_comp = path for feature collection;
// current and next year
var lossYear= lossyear.eq(y);
var lossYear = lossyear.updateMask(lossYear);
var yp1 =ee.Number(y).add(1);
var lossYear_pl =lossyear.eq(yp1)
var lossYear_pl =lossyear.updateMask(lossYear_pl)
var gfc_count= lossYear.reduceRegions({
   collection: table_comp,
   reducer: ee.Reducer.count(),
   scale: 30});
}

For each geometry of feature collection I would like to have the number of Hansen loss for the reference year and the next. I'm writing this script to ask information about function of reducer.count() function. I have noticed that the surface that I calculate starting from the pixels extracted from Hansen is often larger than the area of the polygons I previously calculated. Besides the inevitable mistake,I would ask major information about the function reduce.count().

In particular pixels that are on the border of the polygon how are they counted?

0

For your particular question, pixels with some area outside the border aren't considered in the results. Also, there is no option to set a weighted count as some GIS software offers in their algorithms:


enter image description here


enter image description here

Using your code as example: https://code.earthengine.google.com/d6646b24dcc3cb22279aef19ba4e6895


  • thanks for your answer, in your opinion, then what can be the reason for this difference that I often observe between the two areas? what you get from the shapefile is often much lower. I am attaching a script that I prepared with a small sample of the data I'm working on. Could you help me identify if there is any error? – matte85 Jun 7 at 8:23
  • Hi, I can reproduce your example. There is a problem with your Table object – aldo_tapia Jun 7 at 12:21
  • what is the problem? I think to share with you my example asset – matte85 Jun 7 at 14:13
  • Hi! I believe I have identified the error you reported to me. I think it's just a display problem. – matte85 Jun 7 at 19:23

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.