GEE Tutorials

Google Earth Engine Tutorial: Supervised Classification with Sentinel-2A

Credit: Youtube Channel “Terra Spatial, Comprehensive guide on performing supervised classification using high-resolution Sentinel-2A imagery.”

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

Google Earth Engine Tutorial: Supervised Classification with Sentinel-2A

Supervised classification in Google Earth Engine (GEE) involves training a model to distinguish land cover types using labeled training data. Sentinel-2A provides high-resolution multispectral imagery, making it ideal for classifications like land cover, agricultural monitoring, or urban area identification. Below is a step-by-step guide to perform supervised classification with Sentinel-2A in GEE.

Step 1: Load Sentinel-2A Data

Begin by loading a Sentinel-2A image collection and filtering it by date, location, and cloud cover. For example:

var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2023-01-01', '2023-12-31')
.filterBounds(ee.Geometry.Point([longitude, latitude]))
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20);

Select a median composite to minimize cloud and noise effects:

var image = dataset.median().select(['B2', 'B3', 'B4', 'B8', 'B11', 'B12']);

Step 2: Prepare Training Data

Create or import a polygon dataset representing different land cover classes. Define a function to extract band values for each class and generate a training sample:

var training = image.sampleRegions({
collection: trainingFeatures,
properties: ['landcover'],
scale: 10
});

Ensure the training data is balanced and covers a representative range of the study area.

Step 3: Choose a Classifier

Use the ee.Classifier API to specify the algorithm. Popular choices include ee.Classifier.randomForest(), ee.Classifier.logisticRegression(), or ee.Classifier.svm(). Example:

var classifier = ee.Classifier.randomForest({
numberOfTrees: 50,
maxNodes: 1000
});

Train the classifier using the training data:

var trained = classifier.train({
trainingCollection: training,
inputProperties: ['B2', 'B3', 'B4', 'B8', 'B11', 'B12'],
classProperty: 'landcover'
});

Step 4: Apply the Classifier

Use the trained model to classify the entire image:

var classified = image.classify(trained);

Visualize the result by adding the classified image to the map:

Map.addLayer(classified, {palette: ['red', 'green', 'blue', 'yellow']}, 'Land Cover');

Step 5: Evaluate Accuracy

Split the training data into training and testing sets to validate the model. Calculate accuracy metrics using a confusion matrix:

var test = training.randomColumn('random');
var trainTest = test.filter(ee.Filter.lt('random', 0.7));
var testTest = test.filter(ee.Filter.gte('random', 0.7));
var testAccuracy = trained.confusionMatrix().accuracy();
print('Classification Accuracy:', testAccuracy);

Use Map.addLayer to display an accuracy assessment map if needed.

Step 6: Export Results

Export the classified image to a Google Drive or other cloud storage:

Export.image.toDrive({
image: classified,
description: 'sentinel2_classification',
fileNamePrefix: 'landcover',
region: geometry,
scale: 10,
crs: 'EPSG:4326'
});

Ensure the output format (e.g., GeoTIFF) and parameters match your requirements.

FAQ

What is the best time frame for Sentinel-2A images for classification?

The optimal time frame depends on the study area and phenological cycles. For agricultural monitoring, use images during crop growth periods. Avoid rainy or cloudy seasons to minimize noise.

How to handle cloud cover in Sentinel-2A images?

Use the CLOUDY_PIXEL_PERCENTAGE metadata to filter images. For remaining clouds, apply a cloud masking algorithm or use the cloudMasking function from GEE’s built-in tools.

Is Sentinel-2A data free for use in GEE?

Yes, Sentinel-2A data is freely accessible through the GEE platform. However, ensure you comply with the Copernicus data policy and licensing.
More info

What are the common classes for land cover classification?

Classes typically include forests, water bodies, urban areas, agricultural land, and bare soil. Custom classes can be defined based on project needs.

How to improve classification accuracy in GEE?

Use high-quality training data, ensure spectral features are relevant, and apply preprocessing steps like atmospheric correction. Experiment with different classifiers and tune hyperparameters.

Can I use other sensors alongside Sentinel-2A for classification?

Yes. GEE allows combining datasets from Sentinel-1, Landsat, or MODIS for enhanced accuracy. Use ee.Image and select to merge bands as needed.

Similar Posts

Leave a Reply

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