βοΈ Method 1: Google Earth Engine¶
π (Recommended)¶
π°οΈ Most Powerful Method
Perfect for processing large areas and combining with other datasets
π Prerequisites¶
### β
**Step-by-Step Setup**
1. **π Sign up for Google Earth Engine**
- Visit: [https://earthengine.google.com/signup/](https://earthengine.google.com/signup/)
- Wait for approval (usually 1-2 days)
2. **π» Access the Code Editor**
- Go to: [https://code.earthengine.google.com/](https://code.earthengine.google.com/)
π― Step 1: Extract Building Height Raster¶
[](https://code.earthengine.google.com/f90adbd664b59f53dfcaa4530da436c3)
π Complete Script¶
// π― Define your area of interest
// Draw a polygon using the drawing tools or use this example
var geometry = ee.Geometry.Rectangle([
[longitude_min, latitude_min],
[longitude_max, latitude_max]
]);
// π‘ Load the Open Buildings 2.5D Temporal dataset
var openBuildingsTemporal = ee.ImageCollection(
'GOOGLE/Research/open-buildings-temporal/v1');
// π
Select year of interest
var year = 2023;
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = startDate.advance(1, 'year');
// π Filter collection
var filtered = openBuildingsTemporal
.filter(ee.Filter.date(startDate, endDate))
.filter(ee.Filter.bounds(geometry));
// πΊοΈ Get projection and create mosaic
var projection = filtered.first().projection();
var buildingsMosaic = filtered.mosaic()
.setDefaultProjection(projection);
// ποΈ Select building height band
var buildingHeights = buildingsMosaic
.select('building_height');
// π¨ Visualize with beautiful colors
var heightPalette = [
'1d4877', '1b8a5a', 'fbb021', 'f68838', 'ee3e32'];
var heightVisParams = {min:0, max:50, palette: heightPalette};
Map.centerObject(geometry);
Map.addLayer(buildingHeights.clip(geometry),
heightVisParams, 'Building Heights');
// πΎ Export as GeoTIFF
Export.image.toDrive({
image: buildingHeights.clip(geometry),
description: 'Building_Height_Raster_' + year,
folder: 'earthengine',
fileNamePrefix: 'building_height_raster_' + year,
region: geometry,
scale: 4 // 4m resolution
});
π» Step 2: Create Digital Surface Model (DSM)¶
[](https://code.earthengine.google.com/f90adbd664b59f53dfcaa4530da436c3)
π³ Advanced DSM with Trees and Terrain¶
// π² Add Canopy Height (Meta/WRI 1m resolution)
var canopyHeight = ee.ImageCollection(
'projects/meta-forest-monitoring-okw37/assets/CanopyHeight')
.mosaic()
.rename('canopy_height');
var treeMask = canopyHeight.updateMask(canopyHeight.gte(1));
var treeHeight = treeMask.unmask(0);
// π’ Add tree height to building height
var buildingsAndTrees = buildingHeights.add(treeHeight);
// β°οΈ Add Terrain Height (FABDEM 30m)
var fabdem = ee.ImageCollection(
'projects/sat-io/open-datasets/FABDEM');
var fabdemMosaic = fabdem.mosaic()
.setDefaultProjection(projection);
var dem = fabdemMosaic.select('b1');
// π― Create complete DSM
var dsm = buildingsAndTrees.add(dem);
// πΎ Export DSM
Export.image.toDrive({
image: dsm.clip(geometry),
description: 'DSM_' + year,
folder: 'earthengine',
fileNamePrefix: 'dsm_' + year,
region: geometry,
scale: 4
});
π’ Step 3: Extract Building Footprints with Heights¶
[](https://code.earthengine.google.com/f90adbd664b59f53dfcaa4530da436c3)
π Extract Polygon Data with Height Attributes¶
// ποΈ Load Open Buildings V3 Polygons
var openBuildingsPolygons = ee.FeatureCollection(
'GOOGLE/Research/open-buildings/v3/polygons');
var allBuildings = openBuildingsPolygons
.filter(ee.Filter.bounds(geometry));
// π Extract temporal data for each building
var temporalBands = buildingsMosaic.select([
'building_presence', 'building_height']);
// π Zonal statistics to get average height per building
var allBuildingsData = temporalBands.reduceRegions({
collection: allBuildings,
reducer: ee.Reducer.mean(),
scale: 4,
tileScale: 16,
});
// π Filter buildings present in selected year
var buildingsFiltered = allBuildingsData
.filter(ee.Filter.gt('building_presence', 0.5));
// πΊοΈ Reproject to UTM for accuracy
var buildingsReprojected = buildingsFiltered
.map(function(f) {
return f.transform({
proj: projection,
maxError: 0.1});
});
// π Select properties for export
var selectedProperties = ['area_in_meters', 'building_height'];
var renamedProperties = ['area', 'height'];
var buildingsExport = buildingsReprojected.select(
selectedProperties, renamedProperties);
// πΎ Export as shapefile
Export.table.toDrive({
collection: buildingsExport,
description: 'Building_Polygons_with_Height_' + year,
folder: 'earthengine',
fileNamePrefix: 'building_polygons_with_height_' + year,
fileFormat: 'SHP',
selectors: renamedProperties
});
π¨ Visualization Tips¶
π¨ Color Palettes
Height Visualization:
['1d4877', '1b8a5a', 'fbb021', 'f68838', 'ee3e32']
π Scale Settings
- Testing: scale: 16
- Production: scale: 4
- High Detail: scale: 2
β‘ Performance Optimization¶
Setting | Value | Purpose |
---|---|---|
tileScale | 16 | Reduces memory usage |
maxPixels | 1e9 | Prevents timeout errors |
pyramidingPolicy | 'mean' | Smooth visualization |
π Congratulations!
You've mastered the most powerful method for extracting building heights!