Skip to content

βš™οΈ Method 1: Google Earth Engine

πŸ›°οΈ Most Powerful Method

Perfect for processing large areas and combining with other datasets

Google Earth Engine

πŸš€ 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

[![Open in Google Earth Engine](assets/gee_icon.jpg)](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)

[![Open DSM Script](assets/gee_icon.jpg)](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

[![Open Footprints Script](assets/gee_icon.jpg)](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!