1

I want to attach the values from one raster to another raster. Using simple band math I can multiply the value of the base raster which is the presence of mangroves and therefore 1 or masked by the value of the other raster, which is the change in water from the Pekel water layer. This works for where both rasters have a value but where the Pekel layer is masked I would want the value in the mangrove layer to be the nearest pixel in Pekel layer.

//import Pekel data
var gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');
var change = gsw.select("change_abs");


//import Mangroves of the World   
var mangrove = ee.Image(ee.ImageCollection('LANDSAT/MANGROVE_FORESTS').first()); 

//////////////////////////////////////////////////////////////
// Constants
//////////////////////////////////////////////////////////////

var VIS_CHANGE = {
    min:-100,
    max:100,
    palette: ['red', 'black', 'limegreen']
};


var MANGROVE_COL = {
  palette: ['orange']
};

//////////////////////////////////////////////////////////////
// Calculations
//////////////////////////////////////////////////////////////

var combine = mangrove.select('1').multiply(change.select('change_abs'))

//////////////////////////////////////////////////////////////
// Map Layers
//////////////////////////////////////////////////////////////

Map.addLayer({
  eeObject: mangrove, 
  visParams: MANGROVE_COL, 
  name: 'mangrove extent', 
  shown: false
});

//Change in water intensity
Map.addLayer({
  eeObject: change,
  visParams: VIS_CHANGE,
  name: 'occurrence change intensity', 
  shown: false
});




//Change in water intensity
Map.addLayer({
  eeObject: combine,
  visParams: VIS_CHANGE,
  name: 'occurrence change intensity in mangrove', 
  shown: true
});

1 Answer 1

1

You can unmask() using another image. Masked values in the first image will be replaced by the values in the second.

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.