Skip to content

Instantly share code, notes, and snippets.

@pmgreen
Created December 21, 2025 22:20
Show Gist options
  • Select an option

  • Save pmgreen/d526d32c2bf24abc07117016a01cc0e7 to your computer and use it in GitHub Desktop.

Select an option

Save pmgreen/d526d32c2bf24abc07117016a01cc0e7 to your computer and use it in GitHub Desktop.
/* Google Earth Engine script to get forest loss and gain since 2016 for an area of interest in TN (because TN LiDAR data dates back to 2016).
Images (GeoTIFF) can be exported to Google Drive then downloaded and imported into QGIS.
Adapted from Josef Clifford's Udemy course Open Source GIS & Remote Sensing for Conservation (Advanced). */
// Set map center over NRC in Grainger County, TN
Map.setCenter(-83.6562908309219, 36.326523130233674, 13);
// Load US Grainger county dataset
var graingerCounty = ee.FeatureCollection('TIGER/2018/Counties')
.filter(ee.Filter.eq('GEOID', '47057'));
// Add land cover dataset
var lc = ee.ImageCollection('ESA/WorldCover/v200').first();
// clip to Grainger County
var lc_grainger = lc.clip(graingerCounty);
// Extract waterbodies
var water_grainger = lc_grainger.updateMask(lc_grainger.eq(80));
var lcVis = {
bands: ['Map'],
};
// Load Hansen GFC dataset
var gfc2022 = ee.Image('UMD/hansen/global_forest_change_2022_v1_10');
// Add forest cover layer to the map
Map.addLayer(gfc2022.select('treecover2000'), {palette: ['000000', '#37c756'], max: 100}, 'Forest Cover 2000');
// tree cover loss years
var treeLossYrVisParam = {
bands: ['lossyear'],
min: 16,
max: 22,
palette: ['yellow', 'red']
};
Map.addLayer(gfc2022, treeLossYrVisParam, 'tree loss year');
// tree cover loss pixels
var treeLossVisParam = {
bands: ['loss'],
min: 0,
max: 1,
palette: ['000000', 'red']
};
Map.addLayer(gfc2022.mask(gfc2022), treeLossVisParam, 'tree loss');
// tree cover gain pixels
var treeGainVisParam = {
bands: ['gain'],
min: 0,
max: 1,
palette: ['000000', 'purple']
};
Map.addLayer(gfc2022.mask(gfc2022), treeGainVisParam, 'tree gain');
// add land cover layers
Map.addLayer(lc_grainger, lcVis, 'Landcover');
Map.addLayer(water_grainger, lcVis, 'Waterbodies');
Map.addLayer(graingerCounty, null, "Grainger");
/*
// export files to Google Drive
Export.image.toDrive({
image: gfc2022.select('lossyear','loss','gain','treecover2000'), // bands to export
description: 'gfc_grainger',
region: graingerCounty,
scale: 250 // adjust resolution here as needed
});
Export.image.toDrive({
image: lc_grainger,
description: 'lc_grainger',
region: graingerCounty,
scale: 250
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment