GEE Tutorials

Google Earth Engine Tutorial: Supervised Classification with Landsat 8

Credit: Youtube Channel “Terra Spatial, Complete tutorial on supervised classification techniques using Landsat 8 satellite imagery.”

You can see all the tutorials from here: Techgeo Academy.

Introduction to Supervised Classification

Supervised classification in Google Earth Engine (GEE) involves training a model using labeled training data to categorize land cover features. Landsat 8 provides high-resolution multispectral imagery ideal for this task, with bands like Surface Reflectance (SR) to capture detailed spectral information. This tutorial guides you through the process of building a classifier using Landsat 8 data and GEE’s tools.

Step 1: Load and Preprocess Landsat 8 Data

To begin, load Landsat 8 Surface Reflectance data and apply preprocessing steps:


  // Load Landsat 8 data
  var landsat = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
    .filterDate('2020-01-01', '2020-12-31')
    .filter(ee.Filter.eq('WRS_PATH', 139))
    .filter(ee.Filter.eq('WRS_ROW', 37));
  
  // Select relevant bands
  var image = landsat.select(['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'SR_B10', 'SR_B11']);
  
  // Create a median composite
  var medianImage = image.median();
  
  // Clip to a region of interest (ROI)
  var roi = ee.Geometry.Rectangle([11.76, 40.86, 12.04, 40.99]);
  var clipped = medianImage.clip(roi);
  

Step 2: Create Training Data

Use ground-truth data from an existing dataset (e.g., the Global Land Cover dataset) to generate training points:


  // Load land cover training data
  var landCover = ee.Image('COPERNICUS/GLC30');
  
  // Define training region and properties
  var training = landCover.select('Map').sample({
    region: roi,
    scale: 30,
    numPixels: 5000
  });
  
  // Create a training dataset with the selected bands
  var trainingData = training.select(['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'SR_B10', 'SR_B11', 'Map']);
  

Step 3: Train the Classifier

Choose a classifier (e.g., Random Forest) and train it using the training data:


  // Define and train the classifier
  var classifier = ee.Classifier.smileRandomForest(10).train({
    features: trainingData,
    classProperty: 'Map',
    inputProperties: ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7', 'SR_B10', 'SR_B11']
  });
  

Step 4: Classify the Image

Apply the trained classifier to the image and visualize the results:


  // Classify the clipped image
  var classified = clipped.classify(classifier);
  
  // Add the classification to the map
  Map.addLayer(classified, {min: 0, max: 11, palette: ['red', 'green', 'blue']}, 'Land Cover Classification');
  

Step 5: Evaluate the Classification

Use a confusion matrix to assess the classifier’s accuracy:


  // Generate and print the confusion matrix
  var test = trainingData.randomColumn();
  var split = 0.7;
  var trainingSet = test.filter(ee.Filter.lt('random', split));
  var validationSet = test.filter(ee.Filter.gte('random', split));
  
  var validation = validationSet.classify(classifier);
  var confusionMatrix = validation.errorMatrix('Map', 'classification');
  print('Confusion Matrix:', confusionMatrix);
  print('Overall Accuracy:', confusionMatrix.accuracy());
  

FAQ

What is supervised classification in GEE?
Supervised classification uses labeled training data to teach a model to classify land cover features. The user provides sample data with known classes, and the model learns patterns to apply to new imagery.

Which classifier should I use for Landsat 8?
Common choices include Random Forest (smileRandomForest), Logistic Regression (ee.Classifier.logisticRegression), and Tree-based methods (smileDecisionTree). Random Forest is popular for its accuracy and robustness to noise.

How to handle cloud coverage in Landsat 8 data?
Use the SR_BQA (Surface Reflectance Quality Assessment) band to mask clouds. Add a mask using `image.select(‘SR_BQA’).bitwiseAnd(1 << 4)` to exclude cloud pixels.

Can I use other sensors besides Landsat 8?
Yes! GEE supports other datasets like Sentinel-2 or MODIS. Ensure preprocessing aligns with their spectral characteristics and resolution.

How to improve classification accuracy?
Collect more training samples, use additional spectral indices (e.g., NDVI), and apply cross-validation. Also, refine the classifier’s parameters for better performance.

Where can I find training data for my region?
Use public datasets like the COPERNICUS/GLC30 land cover map, or digitize custom training areas using the GEE code editor’s geometry tools.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *