0

I'm a GIS Student and I'm learning how to use Google Earth Engine. I'm trying to make a GEE APP in which through a dropdown menu I select an index (in this case NDWI_Veg or NDWI_Water) and it shows on the map. This is made for a single image "LANDSAT/LC08/C01/T1_RT_TOA/LC08_219077_20200531".

I've followed this great tutorial about "Publishing an Earth Engine App to Accompany your Research Paper" (https://www.youtube.com/watch?v=saaecbImPmI) which helped me to create the grounds to work with.

I've tried to modify the code of the video and I'm getting the error

"NDWI_VEG: Layer error: Image.select: Pattern 'NDWI_VEG' did not match any bands."

I'm not quite sure how to correct this. The code is as follows:

var m = {};

m.img = ee.Image("LANDSAT/LC08/C01/T1_RT_TOA/LC08_219077_20200531")

var NDWI_Veg = m.img.expression(
  '(nir-swir )/(nir + swir )',
  {
    swir: m.img.select('B6'),  
    nir: m.img.select('B5'),  
  } ).rename('NDWI_VEG');
  
var NDWI_Water = m.img.expression(
  '(green-nir )/(green + nir )',
  {
    green: m.img.select('B3'),  
    nir: m.img.select('B5'),  
  } ).rename('NDWI_WATER');
  

m.imgInfo = {
  bands:{
    'NDWI_VEG':{
      bname: 'NDWI_VEG',
      color: 'd4e7b0',
      vis: {
        min: -1,
        max: 1,
      }
    },
    'NDWI_WATER': {
      bname: 'NDWI_WATER',
      color: 'd2cdc0',
      vis: {
        min: -1,
        max: 1,
      }
    },
    }
};


var c = {};

c.controlPanel = ui.Panel();
c.map = ui.Map();

c.info = {};

c.info.titleLabel = ui.Label('Placeholder Title');
c.info.aboutLabel = ui.Label(
  'Placeholder About');
c.info.panel = ui.Panel([
  c.info.titleLabel, c.info.aboutLabel
  ]);


c.selectBand = {};
c.selectBand.label = ui.Label('Select a band to display');
c.selectBand.selector = ui.Select(Object.keys(m.imgInfo.bands), null, 'NDWI_VEG'); 
c.selectBand.panel = ui.Panel([c.selectBand.label, c.selectBand.selector]);

c.dividers = {};
c.dividers.divider1 = ui.Panel()
c.dividers.divider2 = ui.Panel()


ui.root.clear();
ui.root.add(c.controlPanel);
ui.root.add(c.map);

c.controlPanel.add(c.info.panel);
c.controlPanel.add(c.dividers.divider2);
c.controlPanel.add(c.selectBand.panel);

var s = {};

s.aboutText = {
  fontSize: '13px',
  color: '505050'
};

s.widgetTitle = {
  fontSize: '15px',
  fontWeight:'bold',
  margin: '8px 8px 0px 8px',
  color: '383838'
};

s.stretchHorizontal = {
  stretch: 'horizontal'
};

s.divider = {
  backgroundColor: 'F0F0F0',
  height: '4px',
  margin: '20px 0px'
};

c.controlPanel.style().set({
  width: '275px'
});

c.info.titleLabel.style().set({
  fontSize: '20px',
  fontWeight: 'bold'
});

c.info.aboutLabel.style().set(s.aboutText);

c.selectBand.label.style().set(s.widgetTitle);
c.selectBand.selector.style().set(s.stretchHorizontal);

Object.keys(c.dividers).forEach(function(key){
  c.dividers[key].style().set(s.divider);
  }
);

function updateMap(){
  var band = c.selectBand.selector.getValue();
  
  var img = m.img.select(m.imgInfo.bands[band].bname);
    
  var layer = ui.Map.Layer({
    eeObject: img,
    visParams: m.imgInfo.bands[band].vis,
    name: band
  });
  c.map.layers().set(0,layer);
}

c.selectBand.selector.onChange(updateMap);

updateMap()

I'm still learning how to code.

1 Answer 1

0

The error message is indicating that the 'NDWI_VEG' band is not in the image you are calling. Thus, you just need to add the NDWI bands to the original image. Add the following line, after creating both NDWI_Veg and NDWI_Water images.

m.img = m.img.addBands(NDWI_Veg.addBands(NDWI_Water));
1

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.