I have forestry and DEM datasets. I would like to combine them to be able to calculate the amount of forest for each elevation zones. I would like to do it with Google Earth Engine. I reclassified DEM into several zones. How can I combine these two datasets? Is there any need to convert them to vector?
Asked
Active
Viewed 708 times
1 Answers
0
see this updated answer and let me know if you have further questions
// Load a aoi boundary
var aoi = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
.filter(ee.Filter.eq('country_na', 'Luxembourg'));
// Load dem image, clipped to the aoi border.
var dem = ee.Image("MERIT/DEM/v1_0_3")
.select('dem')
.clipToCollection(aoi);
//// Dem zones ================================================================================================
// Define arbitrary thresholds on the 6-bit dem image.
var zones_raster = dem.gt(400).add(dem.gt(200)).add(dem.gt(100));
zones_raster = zones_raster.updateMask(zones_raster.neq(0));
// Convert the zones of the thresholded dem to vectors.
var zones_vectors = zones_raster.addBands(dem).reduceToVectors({
geometry: aoi,
crs: dem.projection(),
scale: 1000,
geometryType: 'polygon',
eightConnected: false,
labelProperty: 'zone',
reducer: ee.Reducer.mean()
});
print('zones_vectors', zones_vectors)
// Display the thresholds.
Map.setCenter(8, 50, 8);
Map.addLayer(zones_raster, {min: 1, max: 3, palette: ['0000FF', '00FF00', 'FF0000']}, 'raster');
// Make a display image for the vectors, add it to the map.
var display = ee.Image(0).updateMask(0).paint(zones_vectors, '000000', 3);
Map.addLayer(display, {palette: '000000'}, 'zones_vectors');
//// forst loss data ==========================================================================================
var bands = ['treecover2000', 'loss', 'gain', 'lossyear']
var gfc = ee.Image("UMD/hansen/global_forest_change_2020_v1_8")
.clip(aoi)
.select(bands);
var lossImage = gfc.select(['loss']);
var maskYear = gfc.select(['lossyear'])
var loss_year1 = lossImage.updateMask(maskYear.eq(1))
print('loss_2001', loss_year1)
Map.addLayer(loss_year1, {}, 'loss_2001');
//// loss stats by zones =====================================================================================
//// to calculate how many loss pixel in each zone
var stats = loss_year1.reduceRegions({
collection: zones_vectors,
reducer: ee.Reducer.sum(),
scale: 30
});
print('zone with the largest loss: ', stats.sort('sum', false).first().get('sum'), 'pixels');
// stats.sort('sum', false).first().get('sum')
var stats_top5 = stats
.sort('sum', false)
// Get only the 5 highest volume watersheds.
.limit(15)
// Extract the names to a list.
.reduceColumns(ee.Reducer.toList(), ['sum']).get('list');
print('loss on the top 5: ', stats_top5, 'pixels');
//// to calculating loss Areas in each zone
var areaImage = loss_year1.multiply(ee.Image.pixelArea());
var stats = areaImage.reduceRegions({
collection: zones_vectors,
reducer: ee.Reducer.sum(),
scale: 30
});
print('one with the largest loss: ', stats.sort('sum', false).first().get('sum'), 'square m');
you can also view the code here at https://code.earthengine.google.com/8ab48e16f100a67f12a55771d4ed1f2b?accept_repo

Yingjie
- 48
- 5
-
1This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/28993784) – tomerpacific May 17 '21 at 18:12
-
@tomerpacific sorry, I thought this is an easy question. I have revised my answer. – Yingjie May 18 '21 at 20:40