In this script, I take an image and mask off everything below certain elevation. The result looks really interesting as one can still see the names of the towns and roads where the image is masked off.

var geometry = 
    /* color: #98ff00 */
    /* displayProperties: [
        "type": "rectangle"
    ] */
        [[[-83.87143189191625, 28.313819801664945],
          [-83.87143189191625, 24.92605449144572],
          [-78.66391236066625, 24.92605449144572],
          [-78.66391236066625, 28.313819801664945]]], null, false);

 * Function to mask clouds using the Sentinel-2 QA band
 * @param {ee.Image} image Sentinel-2 image
 * @return {ee.Image} cloud masked Sentinel-2 image
function maskS2clouds(image) {
  var qa = image.select('QA60');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)

  return image.updateMask(mask).divide(10000);

// Map the function over one year of data and take the median.
// Load Sentinel-2 TOA reflectance data.
var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2018-01-01', '2018-06-30')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))

var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],

var coper2 = dataset.median()

//Map.addLayer(coper2.clip(geometry), rgbVis, 'RGB');

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

var above0 = coper2.updateMask(elevation.gt(0))
var above10 = coper2.updateMask(elevation.gt(10))
var above100 = coper2.updateMask(elevation.gt(100))

Map.addLayer(geometry, {color:'blue'}, 'inundated')
Map.addLayer(above10.clip(geometry), rgbVis, 'above10')

var img = above10.visualize({
  bands:['B4', 'B3', 'B2'], min: 0, max: 0.3

  image: img,
  description: 'florida_above_10',
  scale: 1000,
  maxPixels: 3e9,
  region: geometry})

Here's what is seen in GEE in the browser:


with the geometry added as a map layer, and


with no geometry added as a map layer.

Is it possible to export an image file that will be able to show what's seen in either of these when opened (perhaps with the map in the background)?

1 Answer 1


If you want to download the masked image, just create a new clipped variable and export it. Add this piece of code to the end your script (I selected bands 4, 3 and 2 in order to get an RGB):

// create clipped RGB
var clipped = above10.select(['B4','B3','B2']).clip(geometry)

// Export clipped with your chosen parameters
  image: clipped,
  description: 'florida_above_10',
  scale: 1000, 
  maxPixels: 3e9,
  region: geometry})

The map in the background is google maps and as far as I know it is not possible to export it from google earth engine.

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.