TransWikia.com

Create a custom buffer in Google Earth Engine

Geographic Information Systems Asked on March 23, 2021

I am working to make mosaics of Landsat 5 scenes that cover watersheds in Montana, and am currently struggling to deal with the "rough edges" on the east/west sides of scenes that get incorporated into the mosaics.

My current solution is to buffer the primary scene in the mosaic (the one that covers most of the watershed) by a negative amount sufficient to remove the edges of the scene prior to making the mosaic. This works in many cases but in some, it also removes valuable data from the top and bottom of the scene that could otherwise be used.

Is there a way to specify a custom buffer that would trim the scene by a variable amount depending on the side of the scene (i.e. trim the east/west sides by enough to remove the bad pixels but leave the north/south edges alone)?

===================== VISUALIAZTION PARAMETERS ================================
=============================================================================*/

// viz parameters for displaying scenes at Landsat 8 TOA scale
var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B3','B2','B1']
};

/*=============================================================================
====================== USER CONTROLS ==========================================
=============================================================================*/

var huc08 = "10050004" // ID of the watershed of interest at the HUC08 level

/*=============================================================================
====================== VECTOR DATA ============================================
=============================================================================*/

// Define bounds of the state of MT
var mt = ee.FeatureCollection("TIGER/2018/States").filterMetadata('NAME', 'equals', 'Montana').geometry()
// print(mt)
// Map.addLayer(mt)

// import all of the HUC08 boundaries and retain only those that intersect MT
var fc = ee.FeatureCollection("USGS/WBD/2017/HUC08").filterBounds(mt)
  .map(function(feature){
    return feature.intersection(mt)
  });
// print(fc)

var feature = fc.filter(ee.Filter.eq('huc8', huc08)) // identify individual HUCs by Name

var ROI = feature.geometry() // turn the desired watershed into a geometry object

/*=============================================================================
=================================== LANDSAT SCENES =============================
=============================================================================*/

var primary = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_038026_20090902')

var secondary = ee.Image('LANDSAT/LT05/C01/T1_TOA/LT05_037026_20090725')

Map.addLayer(primary, rgbVis, 'least cloudy - best scene', false)
Map.addLayer(secondary, rgbVis, 'least cloudy - best scene_1', false)

/*=============================================================================
=================================== MOSAIC ====================================
=============================================================================*/

var mosaic = ee.ImageCollection([secondary,primary]).mosaic() // default mosaic opertor = "LAST"
Map.addLayer(mosaic, rgbVis, 'mosaic l5 scene for roi', false)

/*=============================================================================
=============================== SOLUTION ====================================
=============================================================================*/

var fp = primary.geometry() // get the footprint of the primary scene
var fp_buff = fp.buffer(-8000)

var primary_clip = primary.clip(fp_buff)

var newMosaic = ee.ImageCollection([secondary,primary_clip]).mosaic()

Map.addLayer(newMosaic, rgbVis, 'clipped mosaic l5 scene for roi', false)



Map.centerObject(feature,9); // zoom the map to the HUC of interest
Map.addLayer({eeObject: feature, name: 'watershed bounds'}) // watershed of interest

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP