Lab 15 Lecture - Spring 2023 - Visualizing SRTMs
Objective: In this lab, you will bring an SRTM into Google Earth Engine and apply a color ramp. You will turn in a URL of your final code from Earth Engine.
1 - Image Constructor
First, you will need to instantiate an image with the Image constructor. The image constructorLinks to an external site. ee.Image() gives you access to the raster datasets stored on GEE, and is made using a string ID of an image in the Earth Engine data catalog.
Search the Earth Engine data catalog using the search tool at the top of the Code Editor to discover an image ID.
- Type 'elevation' into the search field and note that a list of rasters is returned.

- Click the 'SRTM Digital Elevation Data Version 4' entry for more information about that dataset.
- On the left side of the dataset description is an Image ID field.

- Click the Import button on the dataset description or the import link on the right side of the search results.
- When you click the import link or button, a variable is automatically created in a special section named 'Imports'Links to an external site., at the top of your script.
- Rename the variable by clicking on its name in the imports section, and change it from image to 'srtm'. It is good practice not to use default naming.

2 - Configuring the Map
The Map.setCenter() method centers the map view at given coordinates with the given zoom level. It takes three arguments:
- The longitude of the center, in decimal degrees.
- The latitude of the center, in decimal degrees.
- The zoom level, from 0 to 24.
For example, the following code centers the map on the Grand Canyon. Put this code in the code editor of GEE:
// Zoom to a location.
Map.setCenter(-112.8598, 36.2841, 9); // Center on the Grand Canyon.

3- Adding a layer to the Map
Now use the Mapobject's addLayer() method to add an image to the map display in the Code Editor.
// Display the image on the map.
Map.addLayer(srtm); //SRTM is the name of my var for the image.
4 - Push Run
Push run, and your screen should look like this:

5 - Customizing layer visualization
Notice that the image comes in with a default grayscale. It is not very easy to visualize the elevation through this. So we will customize the visualization.
- To change how the data are stretched, you can provide another parameter to the Map.addLayer() call. Specifically, the second parameter, visParams, lets you specify the minimum and maximum values to display. To discover what values to use, activate the Inspector tab and click around on the map to get an idea of the range of pixel values.
-
Suppose that through such experimentation, the data should be stretched to [0, 3000]. To display the image using this range, use:
Map.addLayer(srtm, {min: 0, max: 3000}, 'custom visualization');
Note that the
visParamsparameter is an object, with properties specifying theminand themax.
The third argument is the custom name of the image that will show up in the layer manager. -

6 - Working with color
To display a single band using a color palette, add a palette property to the visParams object:
Map.addLayer(srtm, {min: 0, max: 3000, palette: ['blue', 'green', 'red']},
'custom palette');

7 - Making a Hillshade
To display a hillshade we will use some algorithms that are built into the GEE library.
The ee.Terrain.hillshade function computes a simple hillshade from a digital elevation model (DEM). It takes four arguments:
- The elevation image, in meters.
- The illumination azimuth in degrees from north.
- The illumination elevation in degrees.
- The exaggeration factor, which controls the steepness of the shadows.
//add a hillshade
var hills = ee.Terrain.hillshade(srtm, 270, 45)
//add hillshade to map
Map.addLayer(hills, {min: 0, max: 500},'Hillshade')

8 - Share the link
Push the Get Link button and submit the link to your code. Be sure to comment you code.
Lab Submission
Submit lab via email.
Subject: Lab 15 - Visualizing SRTM Data - [Your Name]