Edgar Medina

Downloading Landsat Composites from Google Earth Engine

PURPOSE
The purpose of this doc is to outline the steps to downloading landsat composites for a specific area of interest (AOI) using Google Earth Engine.

PRE REQUISITE

GOOGLE EARTH ENGINE

The following code accesses Landsat 5 archives to tap into 2010 imagery used to create a 432 landsat composite the shape of San Luis Obispo County.

var table: Table users/you-google-username/shapefile

var Landsat5BandCombo = ['B4', 'B3', 'B2'] // 4,3,2 stack is good for discriminating agriculture

var Landsat5Visualize = {
  bands: Landsat5BandCombo,
  min: 0,
  max: 0.5,
  gamma: [0.95, 1.1, 1]
};

//Function to mask clouds
function maskLandsatclouds(image) {
  var qa = image.select('BQA')
  var cloudBitMask = ee.Number(2).pow(4).int()
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
  return image.updateMask(mask)
      .select("B.*")
      .copyProperties(image, ["system:time_start"])
}
//Landsat 5 TM, available from 1984-2012
//Tapping into the ee.ImageCollection for Landsat5
var L5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA") 
  .filterDate('2010-07-01', '2010-08-31') // Date range to use for imagery
  .filterBounds(geometry2)
  .map(maskLandsatclouds)
  .select(Landsat5BandCombo)
  
var Landsat5_mosaic = L5.median().clip(geometry2); // calculating median of each collection and clipping
Map.addLayer(Landsat5_mosaic, Landsat5Visualize, "Landsat5_mosaic")

Map.centerObject(geometry2)

// Edit the description to give output a name
Export.image.toDrive({ 
  image: Landsat5BandCombo,
  description: 'Landsat5_2010_July_August',  //Name your output
  scale: 30, 
  maxPixels: 1e13, 
  region: geometry2
});