Assignment 2: Export a Classified Map
Your task is to create a simple land cover map and export it as a GeoTIFF file to your Google Drive.
What is Land Cover Classification?
Land cover classification is the process of categorizing the physical material on the surface of the Earth. Common classes include water, egetation, urban areas, and bare land. In this assignment, we will perform a simple unsupervised classification, where the algorithm automatically groups pixels with similar spectral properties into clusters. Exporting the result as a GeoTIFF allows you to use the map in other GIS software like QGIS or ArcGIS for further analysis.
Instructions
Prepare Your Image
Define an Area of Interest (AOI) and create a cloud-free composite image for that region using Landsat 8 data. A median composite over a year is a good approach.
Create Training Data
Use the input composite itself as training data. We will use an unsupervised approach, so we don't need to manually create labels.
Train a Classifier
Initialize a `ee.Clusterer.wekaKMeans` clusterer with a specified number of clusters (e.g., 5). Train the clusterer with your composite image.
Classify the Image
Apply the trained clusterer to your input composite to create a classified image where each pixel has a cluster ID.
Export to Drive
Use the `Export.image.toDrive()` function to save your classified map. Give it a description, set the scale (e.g., 30 meters for Landsat), and specify your region (AOI). Run the script and click "Run" in the Tasks tab.
Starter Code Snippet
Use this code in the GEE Code Editor to begin. You will need to complete the classification and export steps.
// 1. Define Area of Interest and create a composite image.
var aoi = ee.Geometry.Rectangle([-90.5, 41.5, -90.0, 42.0]);
var landsat = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(aoi)
.filterDate('2020-01-01', '2020-12-31');
var composite = ee.Algorithms.Landsat.simpleComposite({
collection: landsat,
asFloat: true
});
// 2. Create a training dataset.
var training = composite.sample({
region: aoi,
scale: 30,
numPixels: 5000
});
// 3. Train a clusterer.
// --- YOUR CODE HERE ---
var clusterer = /* ... initialize ee.Clusterer.wekaKMeans() and train it ... */;
// 4. Classify the image.
// --- YOUR CODE HERE ---
var classified = /* ... apply the clusterer to the composite ... */;
// Display the classified map.
Map.centerObject(aoi, 9);
Map.addLayer(classified.randomVisualizer(), {}, 'Classified Map');
// 5. Export the image to your Google Drive.
// --- YOUR CODE HERE ---
/* ... Use Export.image.toDrive() ... */
Start Assignment
Expected Result
After running the export task, you should find a new GeoTIFF file in your Google Drive. When opened in a GIS program, it will look like a raster map where pixel values correspond to the different land cover classes you created.