1

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?

1
  • 1
    Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking One question per Question. Please Edit this to contain a single question.
    – Vince
    Jul 9, 2021 at 11:41

1 Answer 1

1

In the first calculation you don't actually mask the pixel area with a binary mask. Instead you mask it by the NDVI values bigger than 0.8.

var test=img.updateMask(img.select("ndvi").gt(0.8))
var areamask1 =ee.Image.pixelArea().updateMask(test);

This also explains your question about decimal points. Masking in GEE works by weighting each pixel by the mask in calculations. So if the mask is 0, the pixel value is multiplied by it and practically ignored. However if the mask value is e.g. 0.888 the area is multiplied by that, leading to decimal numbers.

So for your example: The pixel value is 30mx30m = 900m², then if you weigh it with your mask value0.888 you get 0.888*900 = 799.2

In the second case you actually have a binary mask, so why would you still get decimal numbers?

If your geometry dianchi partially overlaps some pixels they also get weighted by the amount the geometry overlaps them. You can read more about it here.

2
  • hello, thank you for you answer. But I am still confused why the area results are different and which is the right way to do it.
    – una
    Jul 10, 2021 at 14:03
  • The right way is the second way
    – JonasV
    Jul 11, 2021 at 9:47

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.