0

I am working on a land use land cover analysis using GEE. I have written my code to visualize the area of interest imagery in my map. The image shows on my map layers but it is not loading one my UI. Here is the code.

 var boundary = ee.FeatureCollection('users/Angwenyi/Laikipia_Samburu_Ecosystem_Boundary');
var geometry = boundary.geometry();

// Zoom to selected district
Map.centerObject(geometry, 5);
Map.addLayer(geometry);

var startDate = '2022-01-01';
var endDate = '2022-02-27';

// identify the Landsat 8 Surface Reflectance Tier 1 product

var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR');

// set  up the cloud masking function

function maskL8srClouds(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

// build the basic composite
var l8compositeMasked = l8.filterDate(startDate,endDate)
                .filterMetadata('CLOUD_COVER','less_than',50)
                .map(maskL8srClouds)
                .median();

// Add visualization dictionary.  Note that one can change 
// the min and max values for the stretch for each of the three bands. 

var L8_754_viz = {bands:['B7', 'B5', 'B4'], min:[500,500,500], max:[2000,4500,1500]}

// now add the image to the map
Map.addLayer(l8compositeMasked,L8_754_viz,'Landsat 8 composite masked');

What can I do to display my raster?

2 Answers 2

0

The landsat collection 1 is deprecated in GEE. You have to use the collection 2 images. I have modified the code accordingly. The band names has been changed with prefix 'SR' and the pixel quality band is renamed to QA_PIXEL. You need to apply a scale factor to the images as per the documentation. The min-max value in the Map.addLayer() has also been changed.

   Map.centerObject(geometry);
    Map.addLayer(geometry);
    
    var startDate = '2022-01-01';
    var endDate = '2022-02-27';
    
    // identify the Landsat 8 Surface Reflectance Tier 1 product
    
    var l8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2');
    
    // set  up the cloud masking function
    
    function maskL8srClouds(image) {
      // Bits 3 and 5 are cloud shadow and cloud, respectively.
      var cloudShadowBitMask = (1 << 3);
      var cloudsBitMask = (1 << 5);
      // Get the pixel QA band.
      var qa = image.select('QA_PIXEL');
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                    .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
      return image.updateMask(mask);
    }
    function applyScaleFactors(image) {
      var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
      var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
      return image.addBands(opticalBands, null, true)
                  .addBands(thermalBands, null, true);
    }
    // build the basic composite
    var l8compositeMasked = l8.filterDate(startDate,endDate)
                    .filterMetadata('CLOUD_COVER','less_than',50)
                    .map(applyScaleFactors)
                    .map(maskL8srClouds)
                    .median().clip(geometry);
    
    // Add visualization dictionary.  Note that one can change 
    // the min and max values for the stretch for each of the three bands. 
    
    var L8_754_viz = {bands:['SR_B7', 'SR_B5', 'SR_B4'], min:0, max:0.3}
    
    // now add the image to the map
    Map.addLayer(l8compositeMasked,L8_754_viz,'Landsat 8 composite masked');
0
// set  up the cloud masking function

function maskL8srClouds(image) {
  // Bits 4 and 3 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 4);
  var cloudsBitMask = (1 << 3);
  // Get the pixel QA band.
  var qa = image.select('QA_PIXEL');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}
function applyScaleFactors(image) {
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
  return image.addBands(opticalBands, null, true)
              .addBands(thermalBands, null, true);
}
// build the basic composite
var l8compositeMasked = l8.filterDate(startDate,endDate)
                .filterMetadata('CLOUD_COVER','less_than',50)
                .map(applyScaleFactors)
                .map(maskL8srClouds)
                .median().clip(geometry);

// Add visualization dictionary.  Note that one can change 
// the min and max values for the stretch for each of the three bands. 

var L8_754_viz = {bands:['SR_B7', 'SR_B5', 'SR_B4'], min:0, max:0.3}

// now add the image to the map
Map.addLayer(l8compositeMasked,L8_754_viz,'Landsat 8 composite masked');

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.