0

I am trying to summarize all the values from one single raster to get a value (with the total). I ve used this code and I get the total value of the summarize from all the pixels in the region but I don't know how to use that value for other expressions. Could anyone help me?

var image = ee.Image('LANDSAT/LC8_L1T/LC80440342014077LGN00')
.select(['B4']);

var region = geometry1

var sumB4 = image.select('B4').reduceRegion({
 reducer: ee.Reducer.sum(),
 geometry: geometry1,
 scale: 30,
 maxPixels: 1e9
 });

The total value is 654789874.465978 and now I need to use this value to introduce in a NDVI formula.

How can I do it?

  • I don't understand what you mean by "now I need to use this value to introduce in a NDVI formula". Could you better explain this? – Tyler Erickson Sep 13 '17 at 20:29
1

I think the confusion arises from the fact that the return value of the reduceRegion() is a Dictionary. To get the result and do something with it, you need to get() the result from the Dictionary:

var image = ee.Image('LANDSAT/LC8_L1T/LC80440342014077LGN00')
  .select(['B4']);

// Assumes a geometry object that overlays the image.
var sumB4 = image.select('B4').reduceRegion({
 reducer: ee.Reducer.sum(),
 geometry: geometry,
 scale: 30,
 maxPixels: 1e9
});

// ee.Dictionary with reducer outputs keyed by bandname.
print(sumB4);
// ee.Number
print(sumB4.get('B4'));
// Do something with the reducer output.
var thing = ee.Image.constant(sumB4.get('B4'));
Map.addLayer(thing);

Note that the return value is a server object, so you must use Earth Engine functions on it. See this tutorial for instruction on how to use server-side objects.

| improve this answer | |

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.