0

I need to perform analysis on Landsat images on Google Earth Engine. My study area is large and needs about 6 to 10 Landsat tiles. What's the best way to mosaic the tiles together considering that the tiles most likely won't have same acquisition date and some tiles might not be available for some date range or covered with cloud.

1

1 Answer 1

1

You could create a median composite for a date range - use the median value of all (cloud-masked) images in your date range. That usually give you nice and clean composites. Here's an example:

// Replace with your region and date range
var region = Map.getBounds(true) // For now, the region is the current map bounds
var startDate = '2021-01-01'
var endDate = '2021-06-01'

var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') // Landsat 8 SR collection
  .filterBounds(region) // Only include scenes from your region of interest
  .filterDate(startDate, endDate) // Only include scenes from date range
  .map(maskClouds) // Call the maskCounds() function for every image in the collection

// Take the median value for every band in the collection
var composite = collection.median()

// Visualize the composite
Map.addLayer(composite, {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000, gamma: 1.3}) 

function maskClouds(image) {
  var qa = image.select('pixel_qa')
  // Look at the "Bitmask for pixel_qa" section in
  // https://developers.google.com/earth-engine/datasets/catalog/LANDSAT_LC08_C01_T1_SR
  var clear = bitwiseExtract(qa, 1) // Bit for "clear" is 1
  var water = bitwiseExtract(qa, 2) // Bit for "water" is 2
  return image.updateMask(
    clear.or(water) // Keep pixels classified as clear or water
  )
}

function bitwiseExtract(value, fromBit, toBit) {
  if (toBit === undefined)
    toBit = fromBit
  var maskSize = ee.Number(1).add(toBit).subtract(fromBit)
  var mask = ee.Number(1).leftShift(maskSize).subtract(1)
  return value.rightShift(fromBit).bitwiseAnd(mask)
}

https://code.earthengine.google.com/fa56d83cc04573f246c29b430c873dd8

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.