Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

Calculating loss area of elevation classes in Google Earth Engine

I would like to calculate the loss area in a certain elevation class in GEE. When I run code 1 below, it gives the same amount as the total loss area in my study region, code 2. I switched arealoss and class3 in code 1 as well, and didn't work. Besides, elevation(1), (2), .. all classes give the same result. How can I calculate the loss area for each elevation class?

code 1:

var class3 = elevation.eq(3).selfMask();
var stats1 = arealoss.reduceRegion({ reducer: 
ee.Reducer.sum(),
geometry: class3.geometry(),
scale: 30,
maxPixels: 1e9,
bestEffort: true });

code 2:

var stats2 = arealoss.reduceRegion({
            reducer: ee.Reducer.sum(),
            geometry: peru.geometry(),
            scale: 30, 
            maxPixels: 1e9,
            bestEffort: true });

Besides, I want to repeat this calculation for 7 different elevation classes. is it possible to write a function for this calculation in GEE?

question from:https://stackoverflow.com/questions/65602090/calculating-loss-area-of-elevation-classes-in-google-earth-engine

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

class3.geometry() just gives you the footprint of the image — the region in which it is known to have data. It doesn't care at all about the mask, or the values of the pixels.

What you need is to mask the image that you're reducing by your classification. When you do that, the reducer (which works on a per-pixel basis) will ignore all masked pixels.

var class3 = elevation.eq(3);
var stats1 = arealoss
  .updateMask(class3)  // This hides all non-class-3 pixels in arealoss
  .reduceRegion({ 
    reducer: ee.Reducer.sum(),
    geometry: peru.geometry(),   // This only needs to be big enough, not exact
    scale: 30,
    maxPixels: 1e9,
    bestEffort: true
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...