0

I have the next code:

I am trying to make a mask (only one shape that I would like to use as an analysis region) with: all elevations less than 4.100 meters (from DEM), all area with water (NDWI) and all slopes less than 15 degrees (from DEM).

I could mask it but I don't know how to join the three layers and I dont know either how to convert the 255 value to NoData.

How can I do it to insert all this variables in one layer and then use that layer as a region?

var region= MNDWI_DPS

//NDWI

var NDWI = ee.Image('MODIS/MCD43A4_NDWI/MCD43A4_005_2016_05_16')

var visualize = NDWI.visualize({bands: ['NDWI'], min: -1, max: 0}).clip(region);


//DEM+SLOPE

var MDE = ee.Image('USGS/SRTMGL1_003')

var terrain = ee.Algorithms.Terrain(ee.Image('USGS/SRTMGL1_003'));

var visualize1 = MDE.visualize({bands: ['elevation'], min: 0, max: 4100}).clip(region);

var slope = ee.Terrain.slope(MDE);

var visualize2 = slope.visualize({bands: ['slope'], min: 0, max: 15}).clip(region)

Map.addLayer(visualize.clip(region))
Map.addLayer(visualize1.clip(region))
Map.addLayer(visualize2.clip(region))
0

As I understand, this is what you want.

//NDWI
// NDWI produces an image in which the positive 
// data values are typically open water areas (https://deltas.usgs.gov/fm/data/data_ndwi.aspx)

var NDWI = ee.Image('MODIS/MCD43A4_NDWI/MCD43A4_005_2016_05_16')
var watermask = NDWI.gte(0)
var water = NDWI.updateMask(watermask)

//DEM+SLOPE

var MDE = ee.Image('USGS/SRTMGL1_003');
var terrain = ee.Algorithms.Terrain(MDE);

print("MDE", MDE.bandNames())
print("terrain", terrain.bandNames())

// elevation less than 4100 m
var less_4100_mask = terrain.select('elevation').lte(4100)
var less_4100 = terrain.select('elevation').updateMask(less_4100_mask)

// slope less than 15°
var less_15_deg_mask = terrain.select('slope').lte(15)
var less_15_deg = terrain.select('slope').updateMask(less_15_deg_mask)

// final image
var final = water.addBands(less_4100).addBands(less_15_deg).clip(region)

Map.addLayer(final)

But I think you should use a better approach for water mask, in my case NDWI did not throw good results.

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.