Supervised Land Cover Classification using Google Earth Engine and JavaScript

--

Google Earth Engine (GEE) is a powerful cloud-based platform for planetary-scale geospatial analysis. It combines a multi-petabyte catalog of satellite imagery and geospatial datasets with powerful analysis capabilities.

The Supervised Classification process in remote sensing involves training a classifier to recognize patterns in data that correspond to known classes of interest (e.g., forest, water, urban).

This tutorial will guide you through the process of performing supervised land cover classification using Google Earth Engine (GEE) and JavaScript. We will use a k-means clustering algorithm to train a decision tree-based classifier.

Please create a Google Earth Engine account before starting this process.

Step 1: Importing a Landsat 8 Image

The first thing we need is a satellite image to perform our classification on. For this tutorial, we will use an image from the Landsat 8 satellite.

// Import a Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');

This code imports a Landsat 8 image by its specific ID.

Step 2: Defining the Region of Interest

Next, we define a point around which we’ll buffer a region of interest for our analysis.

// Define a region of interest with a point.
var geometry = ee.Geometry.Point([-122.3942, 37.7295]);
var region = geometry.buffer(50000); // 50 kilometers

Here, we’ve defined a point (a longitude, latitude pair) and buffered a region of 50 kilometers around it.

Step 3: Displaying the Image

We can display the imported image on the Map using the Map.addLayer() method.

// Display the image.
Map.addLayer(image, {bands: ['B4', 'B3', 'B2'], max: 0.3}, 'Landsat 8 original image');

We’re using the RGB composite for visualization.

Step 4: Sampling Image and Creating Training and Testing Sets

Next, we sample points in this region on our Landsat 8 image and divide them into a training set and a testing set.

// Sample the image at the points and add a random column.
var points = image.sample({
region: region,
scale: 30,
numPixels: 5000,
seed: 0,
geometries: true // Set this to false to ignore geometries
}).randomColumn();
// Make a training-testing split.
var training = points.filter(ee.Filter.lt('random', 0.7));
var testing = points.filter(ee.Filter.gte('random', 0.7));

In the above snippet, image.sample() method is used to sample points in the specified region. randomColumn() function adds a random column to these points. These points are then divided into training and testing sets using a random split.

Step 5: Training the Clusterer

Next, we instantiate a k-means clusterer and train it on our training set.

// Instantiate the clusterer and train it.
var clusterer = ee.Clusterer.wekaKMeans(15).train(training);

We’re using the k-means algorithm from the Weka library, requesting 15 clusters.

Step 6: Clustering the Image

After training the clusterer, we apply it to the image.

javascript

// Cluster the input using the trained clusterer.
var result = image.cluster(clusterer);

// Display the clusters with random colors.
Map.addLayer(result.randomVisualizer(), {}, 'clusters');

The cluster() method applies the trained clusterer to the image. We then visualize the resulting clusters.

Step 7: Training the Classifier

Next, we use the clusters to train a decision tree classifier.

// Now, use the clusters as a classifier!

var trained = ee.Classifier.smileCart().train({
features: training,
classProperty: 'cluster',
inputProperties: image.bandNames()
});

We are using the decision tree classifier from the Smile library.

Step 8: Classifying the Image

After the classifier is trained, we apply it to the image to classify it.

// Classify the image.
var classified = image.classify(trained);

// Display the classification result.
Map.addLayer(classified.randomVisualizer(), {}, 'classification');

The classify() method applies the trained classifier to the image. We then visualize the resulting classification.

Finally, click “Run” to execute the script and observe the results.

This script clusters the image into 15 different land cover categories based on their spectral signatures and then visualizes these categories. It’s a powerful tool in remote sensing for understanding land cover or other spatial phenomena. However, real-world application of these techniques might involve more complex methodologies.

--

--