1

I am new to Google Earth Engine (GEE). Recently I hope to show the ocean bathymetry contour lines by using the ETOPO1 dataset.

Here is my code:

// Import ETOPO1 bathymetry dataset and choose a band. 
// ETOPO1 bathymetry dataset details at https://developers.google.com/earth-engine/datasets/catalog/NOAA_NGDC_ETOPO1
var bathy_dataset = ee.Image('NOAA/NGDC/ETOPO1');
var dataset_band = bathy_dataset.select('bedrock');

// Set min, max and interval elevation parameters.
var min_elevation = -2000;
var max_elevation = 2000;
var interval_elevation = 50;

// Generate the contour lines
var lines = ee.List.sequence(min_elevation, max_elevation, interval_elevation)
var contourlines = lines.map(function(line) {
  var mycontour = dataset_band
    .resample('bicubic')
    .convolve(ee.Kernel.gaussian(5, 3))
    .subtract(ee.Image.constant(line)).zeroCrossing() 
    .multiply(ee.Image.constant(line)).toFloat();
  return mycontour.mask(mycontour);
})
contourlines = ee.ImageCollection(contourlines).mosaic()

// Add a layer to show the contour lines
Map.addLayer(contourlines, {min: min_elevation, max: max_elevation, palette:['00ff00', 'ff0000']}, 'contours')

However, after running the code, I can only see the contour lines of land, not ocean bathymetry.

enter image description here

I don't know where goes the error. Could you point it out?

Code link here: https://code.earthengine.google.com/437bb62bac2814b8a605d18b140a2a86

1 Answer 1

1

Here is the problem:

  var mycontour = dataset_band
    .resample('bicubic')
    .convolve(ee.Kernel.gaussian(5, 3))
    .subtract(ee.Image.constant(line)).zeroCrossing() 
    .multiply(ee.Image.constant(line)).toFloat();
  return mycontour.mask(mycontour);

You multiplied the zero-crossings by the line depth. Therefore, the lines below zero elevation have a negative value. Negative mask values are equivalent to zero, so all underwater contours were masked off.

Instead, you can make the mask from the zero-crossing image before multiplication:

  var binary_contour = dataset_band
    .resample('bicubic')
    .convolve(ee.Kernel.gaussian(5, 3))
    .subtract(ee.Image.constant(line)).zeroCrossing();
    
  return binary_contour
    .multiply(ee.Image.constant(line)).toFloat()
    .mask(binary_contour);

This seems to get the result you wanted:

enter image description here

1
  • Many many thanks, Kevin. That really solves the problem! Sep 29, 2022 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.