Last active
January 20, 2023 21:05
-
-
Save jsfenfen/5aab3363b9108d18c414fd72c140d032 to your computer and use it in GitHub Desktop.
Export RGB image from google earth engine's landsat8 collection using GEE's script editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var year_string = '2019' | |
// Bounding box for imagery. The smaller it is, the faster to process | |
var bounding_box = ee.Geometry.Rectangle([-16.6147, 15.8444, -16.4147, 16.2444]); | |
var use_landsat_7 = true; | |
// Landsat7 imagery comes with "striping" that's an artifact of a hardware failure | |
// Compositing helps a little, but is not a fix. | |
// More here: https://blog.mapbox.com/debanding-the-world-94439af16e7f | |
if (use_landsat_7) { | |
// LANDSAT7: 1999-2021 | |
var landsat_mission_string = 'LANDSAT/LE07/C02/T1' | |
} else { | |
//LANDSAT8: 2013 forwards | |
var landsat_mission_string = 'LANDSAT/LC08/C02/T1_RT' | |
} | |
// Many more choices here: https://developers.google.com/earth-engine/datasets/catalog | |
// Use dry-ish season as compositing window | |
var start_date = year_string + '-01-01' | |
var end_date = year_string + '-06-01' | |
var filtered_shp = ee.ImageCollection(landsat_mission_string).filterDate(start_date, end_date) | |
.filterBounds(bounding_box) | |
// https://developers.google.com/earth-engine/apidocs/ee-algorithms-landsat-simplecomposite | |
var composite = ee.Algorithms.Landsat.simpleComposite(filtered_shp).float(); | |
var rgb = composite.select('B4', 'B3', 'B2').unitScale(0,255) | |
var gray = composite.select('B8').unitScale(0,155) | |
var huesat = rgb.rgbToHsv().select('hue','saturation') | |
var satellite_imagery = ee.Image.cat(huesat, gray).hsvToRgb() | |
// The band color names are text at this point | |
// The maxes are a human-generated heuristic | |
// Other prior art uses slighly lower values | |
// Sensor drift may mean this should change slightly year to year | |
// but it is uncorrected here. | |
var viz_params = { | |
bands: ['red', 'green', 'blue'], | |
min: [.02, .04, .06], | |
max: [.4, .4, .4], | |
gamma: 1.2 | |
} | |
Map.addLayer(satellite_imagery, viz_params) | |
Map.setCenter(-16.5147, 15.8444, 13) | |
var landsat_shorthand = 'ls8'; | |
if (use_landsat_7) { | |
landsat_shorthand = 'ls7'; | |
} | |
Export.image.toDrive({ | |
image: satellite_imagery.visualize(viz_params), | |
description: 'stlouis_' + landsat_shorthand + '_' + year_string, | |
scale: 30, | |
region: bounding_box.bounds(), | |
maxPixels:1e11, | |
skipEmptyTiles: true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This requires a login to Google Earth Engine and a variety of google cloud permissions. Imagery is actually saved to google drive.