Link Search Menu Expand Document

Tutorial 3

Image and vector display

// Create a variable that points to a particular Landsat image in the Earth Engine collection.  
var myimage = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

// Center the map and display the image.
Map.setCenter(-76.147, 43.046, 10); // Center on City of Syracuse using level 10 scale

Map.addLayer(myimage);

//Display the image using a specific band combination and call the image ColorIR composite.
//Possible band combinations: http://web.pdx.edu/~nauna/resources/10_BandCombinations.htm
Map.addLayer(myimage, {bands:['B4', 'B3', 'B2']}, 'ColorIR composite',false);
Map.addLayer({visParams: {bands:['B4', 'B3', 'B2']}, eeObject: myimage, name: 'ColorIR composite2'},false);
Map.addLayer({visParams: {bands:['B1', 'B4', 'B7']}, eeObject: myimage, name: 'Urban composite'},false);
Map.addLayer({visParams: {bands:['B3', 'B2', 'B1']}, eeObject: myimage, name: 'Natural composite'},false);

// Define visualization parameters to display the image in the map window.
var vizParams = {
bands: ['B4', 'B3', 'B2'],
min: 0,
max: 0.5,
gamma: [0.95, 1.1, 1]
};
Map.addLayer(myimage, vizParams, 'Color IR composite',false);

// Create a circle by drawing a 2000 meter buffer around a point and saving this to variable roi.
var roi = ee.Geometry.Point([-76.147, 43.046]).buffer(20000);

// Display the 2000meter buffer.
Map.addLayer(roi);

Performing image band calculations

/* Create a function to compute NDVI from Landsat 5 imagery where B4 is the NIR band and B3 is the red band. */
var getNDVI = function(image) {
return image.normalizedDifference(['B4', 'B3']);
};

// Load two Landsat 5 images, 20 years apart.
var image1 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_19880619');
var image2 = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

// Display NDVI
Map.addLayer(image1,{bands:['B3', 'B2', 'B1']},"1st image");
Map.addLayer(image2,{bands:['B3', 'B2', 'B1']},"2nd image");

// Compute NDVI from the scenes.
var ndvi1 = getNDVI(image1);
var ndvi2 = getNDVI(image2);

// Display NDVI
Map.addLayer(ndvi1,{},"1st image NDVI");
Map.addLayer(ndvi2,{},"2nd image NDVI");

// Compute the difference in NDVI.
var ndviDifference = ndvi2.subtract(ndvi1);

Map.addLayer(ndviDifference,{},"NDVI difference");

Image metadata

// // Create a variable that points to a particular Landsat image in the Earth Engine collection.  
// var myimage = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_015030_20100531');

// print(myimage);