https://code.earthengine.google.com/4804f3a84fd1e186ba8a1d29bdc19d4a
Here's the code. I try to get the area where NDVI>8. I just wonder why I get two different area calculate results between area1 and area2. I just move the updateMask. Why it caused the change?
And the second question is, pixelArea gets the area of each pixel, and the Reducer.sum gets the sum of all the pixel in the interested area, so the area calculated should be the multiple of 30*30 cause I used Landsat here, shouldn't it? Why I get decimals?
var img=S2.map(NDVI).first().select("ndvi")
var test=img.updateMask(img.select("ndvi").gt(0.8))
var areamask1 =ee.Image.pixelArea().updateMask(test);
var area1=areamask1.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: dianchi,
// crs: 'EPSG:32645', // WGS Zone N 45
scale: 30,
maxPixels: 1E13
});
print(area1.get("area"), 'area1')
var areamask2 =ee.Image.pixelArea().updateMask(img.select("ndvi").gt(0.8))
var area2=areamask2.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: dianchi,
// crs: 'EPSG:32645', // WGS Zone N 45
scale: 30,
maxPixels: 1E13
});
print(area2,"area2");
I am still confused. So which way is right to get the area?
Now I have the thrid question. I checked areamask1 and areamask2. The same pixel of areamask1 and areamask2 has the same value, so why the recuder of them are different? If I masked them differently, areamask1 and areamask2 should also be different.But now they have same value between areamask1 and areamask2?
And I thought areamask2 should be an image of the same value in the whole image, isn't it? If the second case I have a binary mask, then why areamask2 each pixel has different value?