0

I am working with Landsat 8/9 in Google Earth Engine (GEE) and would like some help. I have a list of Landsat images and want to do dNBR calculations to each of them and later displaying each as a layer. I get this list using variable dates so I believe it would be best to have a function where I can iterate over the list, apply the calculation and then display the scene using a designated name. I pretty new to GEE so I wanted to ask for help. I would greatly appreciate some guidance. Thank you!

I wrote code that displays images using specific numbers for example: var img1 = ee.Image(listofImages.get(0)); but this relies heavily on me editing the code to get each layer.

These image do not have the NBR calculation applied to it but I believe:

.normalizedDifference(['B5', 'B7'])

should work within a function that can iterate throughout the list as well as subtracting the scene by the prefire scene to get the dNBR by using:

var dNBR= preNBR.subtract(postNBR)

1 Answer 1

0

Here is the code how to Define a function to calculate NBR for a given Landsat image

// Function to calculate NBR
var calculateNBR = function(image) {
  var nbr = image.normalizedDifference(['B5', 'B7']).rename('NBR');
  return nbr;
};

// List of Landsat images (replace this with your list)
var listOfImages = [ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318'),
                    ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20150120')];

// Select pre-fire and post-fire images
var preFireImage = ee.Image(listOfImages[0]);
var postFireImage = ee.Image(listOfImages[1]);

// Calculate NBR for pre-fire and post-fire images
var preNBR = calculateNBR(preFireImage);
var postNBR = calculateNBR(postFireImage);

// Calculate dNBR
var dNBR = postNBR.subtract(preNBR).rename('dNBR');

// Display the results
Map.centerObject(postFireImage, 10);
Map.addLayer(preNBR, {min:-1, max:1, palette:['FF0000', '00FF00']}, 'Pre-fire NBR');
Map.addLayer(postNBR, {min:-1, max:1, palette:['FF0000', '00FF00']}, 'Post-fire NBR');
Map.addLayer(dNBR, {min:-1, max:1, palette:['FF0000', '00FF00']}, 'dNBR');

Make sure to replace listOfImages with your actual list of Landsat images. This code will calculate NBR for each image, then subtract the pre-fire NBR from the post-fire NBR to get dNBR, and finally display all three layers on the map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.