Before starting, make sure you understand these terms. They appear throughout all code blocks in this course.
| Term | Full Name | What it means in simple words |
|---|---|---|
| NDVI | Normalized Difference Vegetation Index | A simple graphical indicator that can be used to analyze remote sensing observations, often from a satellite, and assess whether the target being observed contains live green vegetation. |
| EVI | Enhanced Vegetation Index | An optimized vegetation index designed to enhance the vegetation signal with improved sensitivity in high biomass regions and improved vegetation monitoring through a de-coupling of the canopy background signal and a reduction in atmosphere influences. |
| Sentinel-2 | Sentinel-2 Mission | An Earth observation mission from the Copernicus Programme that systematically acquires optical imagery at high spatial resolution over land and coastal waters. |
| Dynamic World | Google's Dynamic World | A near real-time global land cover dataset at 10m resolution, derived from Sentinel-2 imagery. |
| GEE | Google Earth Engine | A cloud-based platform for planetary-scale geospatial analysis. |
| Classification | Image Classification | The process of sorting pixels into a finite number of individual classes, or categories, of data based on their data file values. |
| ROI | Region of Interest | A specific area selected for analysis. |
| Surface Reflectance | Surface Reflectance | The fraction of incoming solar radiation that is reflected from the Earth's surface. |
| Spectral Bands | Spectral Bands | Specific ranges of the electromagnetic spectrum that are measured by a sensor. |
| Cloud Masking | Cloud Masking | The process of identifying and removing clouds from satellite imagery. |
| Pixel | Pixel | The smallest unit of an image, representing a single measurement of reflectance or other data. |
| Time Series | Time Series Analysis | Analyzing data points indexed in time order. |
| Land Cover | Land Cover | The physical material at the surface of the earth. |
| Composite | Image Composite | A combination of multiple images into a single image, often used to reduce cloud cover or create a more representative view of an area. |
This course introduces the fundamentals of cropland mapping using remote sensing data. We will leverage Sentinel-2 imagery and Google's Dynamic World dataset within the Google Earth Engine (GEE) platform. By the end of this course, you'll be able to map cropland in North Morocco, even with limited prior experience in GEE or remote sensing.
COPERNICUS/S2_SRYou need two browser tabs open side by side throughout this course.
Course9_Cropland Mapping with Sentinel-2 and Dynamic World
The prompt is the core skill of this course. A good prompt includes the exact dataset ID, band names, study area coordinates, dates, preprocessing steps, and desired outputs.
Paste the following code into your GEE code editor and click Run. Read the beginner notes below to understand what each line does.
// Define region of interest (Rif Mountains and Middle Atlas, Morocco)
var roi = ee.Geometry.Rectangle([-6, 32, -2, 35]);
// Function to mask clouds using the QA60 band
var maskS2clouds = function(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
};
// Load Sentinel-2 SR data and filter by date and region
var s2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2023-01-01', '2023-12-31')
.filterBounds(roi)
.map(maskS2clouds);
Add this block after the previous code. It continues the analysis with additional processing and visualization.
// Function to calculate NDVI
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
// Function to calculate EVI
var addEVI = function(image) {
var evi = image.expression(
'2.5 * (NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1)', {
'NIR': image.select('B8'),
'RED': image.select('B4'),
'BLUE': image.select('B2')
}).rename('EVI');
return image.addBands(evi);
};
// Apply NDVI and EVI calculations
var s2_ndvi_evi = s2.map(addNDVI).map(addEVI);
// Load Dynamic World data
var dw = ee.ImageCollection('GOOGLE/DYNAMIC_WORLD/V1')
.filterDate('2023-01-01', '2023-12-31')
.filterBounds(roi);
// Get the most frequent land cover class from Dynamic World
var dw_mode = dw.select('label').reduce(ee.Reducer.mode());
Add this block at the end of your script to export the final map as a GeoTIFF to your Google Drive. After clicking Run, go to the Tasks tab in GEE and click Run next to each export task.
// Export the cropland map to Google Drive
Export.image.toDrive({
image: dw_mode,
description: 'Cropland_Map_Morocco_2023',
folder: 'GEE_Exports',
scale: 10,
region: roi,
maxPixels: 1e13
});
Use DeepSeek to extend the script for each exercise below. Write a follow-up prompt describing what you want to add, then copy the generated code and paste it into your GEE script.
To get the best results from DeepSeek for GEE tasks, always include these elements in your prompts:
| Element | Example |
|---|---|
| Exact dataset ID | COPERNICUS/S2_SR |
| Band names | "select band 'B4' for red, 'B8' for NIR" |
| Study area | "rectangle [-6.5, 33.0, -1.5, 36.0] North Morocco" |
| Date range | "filter from 2020-01-01 to 2023-12-31" |
| Output format | "print area in hectares, add a legend, export to Drive" |
| Error fixing | "The code gives error X. Please fix it." |
| Iteration | "Add a time series chart for each year 2018-2023" |