Google Earth Engine Tutorial: Load Sentinel 2 Imagery in GEE
Credit: Youtube Channel “Terra Spatial, Step-by-step guide on importing and displaying Sentinel 2 satellite imagery in Google Earth Engine.”
You can see all the tutorials from here: Techgeo Academy.
Google Earth Engine (GEE) is a powerful cloud-based platform that allows researchers and developers to analyze geospatial datasets at a planetary scale. One of its most valuable features is the ability to access and process satellite imagery, including the high-resolution Sentinel-2 data from the European Space Agency. This tutorial will guide you through loading Sentinel-2 imagery in GEE using JavaScript.
What is Sentinel-2 Imagery?
Sentinel-2 is a multispectral imaging mission developed by the European Space Agency (ESA) as part of the Copernicus program. It consists of two identical satellites (Sentinel-2A and Sentinel-2B) that provide high-resolution optical imagery with a revisit time of 5 days at the equator. The satellites capture data in 13 spectral bands with spatial resolutions of 10m, 20m, and 60m, making it ideal for land monitoring applications such as vegetation analysis, urban planning, and environmental monitoring.
Setting Up Your GEE Environment
Before we start loading Sentinel-2 imagery, ensure you have a Google Earth Engine account. If you don’t have one, you can sign up at the GEE website. Once you have access, navigate to the GEE Code Editor where we’ll write our JavaScript code.
Loading Sentinel-2 Collections
Google Earth Engine hosts several Sentinel-2 collections. The most commonly used ones are:
- Sentinel-2 MSI: MultiSpectral Instrument, Level-1C – Top-of-atmosphere reflectance
- Sentinel-2 MSI: MultiSpectral Instrument, Level-2A – Bottom-of-atmosphere reflectance (atmospherically corrected)
For most applications, we recommend using Level-2A data as it provides surface reflectance values that are more suitable for analysis. Here’s how to load the Sentinel-2 Level-2A collection:
// Load Sentinel-2 Level-2A collection
var sentinel2 = ee.ImageCollection('COPERNICUS/S2_SR');
// Print collection information to console
print('Sentinel-2 Collection:', sentinel2);
Filtering by Date and Location
Working with the entire Sentinel-2 collection would be computationally intensive. We need to filter the collection based on our area of interest and time period:
// Define a point of interest (example: coordinates for Paris, France)
var pointOfInterest = ee.Geometry.Point([2.3522, 48.8566]);
// Define date range
var startDate = '2023-06-01';
var endDate = '2023-08-31';
// Filter collection by date and location
var filteredCollection = sentinel2
.filterDate(startDate, endDate)
.filterBounds(pointOfInterest);
// Print filtered collection
print('Filtered Collection:', filteredCollection);
Selecting and Preprocessing Images
Now let’s sort the images by cloud cover and select the least cloudy image:
// Sort by cloud cover and get the least cloudy image
var leastCloudyImage = filteredCollection
.sort('CLOUDY_PIXEL_PERCENTAGE')
.first();
// Print selected image
print('Least Cloudy Image:', leastCloudyImage);
// Select RGB bands for visualization
var rgbBands = ['B4', 'B3', 'B2']; // Red, Green, Blue
var rgbImage = leastCloudyImage.select(rgbBands);
Adding Images to the Map
To visualize our Sentinel-2 image, we need to add it to the map:
// Define visualization parameters
var rgbVisParams = {
min: 0,
max: 3000,
bands: ['B4', 'B3', 'B2']
};
// Center map on our point of interest
Map.centerObject(pointOfInterest, 10);
// Add image to map
Map.addLayer(rgbImage, rgbVisParams, 'Sentinel-2 RGB');
Advanced Filtering and Processing
For more sophisticated analysis, we can apply additional filters and processing steps:
// Comprehensive filtering example
var processedCollection = sentinel2
.filterDate('2023-06-01', '2023-08-31')
.filterBounds(pointOfInterest)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20)
.sort('CLOUDY_PIXEL_PERCENTAGE');
// Create a median composite from multiple images
var medianComposite = processedCollection
.select(['B2', 'B3', 'B4', 'B8'])
.median();
// Add composite to map
Map.addLayer(medianComposite, {
bands: ['B4', 'B3', 'B2'],
min: 0,
max: 3000
}, 'Sentinel-2 Median Composite');
Working with Spectral Indices
Sentinel-2’s multispectral capabilities make it perfect for calculating vegetation indices like NDVI:
// Calculate NDVI (Normalized Difference Vegetation Index)
var ndvi = medianComposite.normalizedDifference(['B8', 'B4']).rename('NDVI');
// Add NDVI to map
Map.addLayer(ndvi, {
min: -1,
max: 1,
palette: ['blue', 'white', 'green']
}, 'NDVI');
Complete Working Example
Here’s a complete example that puts everything together:
// Complete Sentinel-2 loading example
// Define area of interest
var aoi = ee.Geometry.Rectangle([2.2, 48.7, 2.5, 48.9]);
// Load and filter Sentinel-2 collection
var s2Collection = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2023-07-01', '2023-07-31')
.filterBounds(aoi)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)
.sort('CLOUDY_PIXEL_PERCENTAGE');
// Get the best image
var s2Image = s2Collection.first();
// Create RGB visualization
Map.centerObject(aoi, 11);
Map.addLayer(s2Image, {
bands: ['B4', 'B3', 'B2'],
min: 0,
max: 3000
}, 'Sentinel-2 RGB Image');
// Calculate and display NDVI
var ndvi = s2Image.normalizedDifference(['B8', 'B4']).rename('NDVI');
Map.addLayer(ndvi, {
min: -1,
max: 1,
palette: ['red', 'yellow', 'green']
}, 'NDVI');
// Print image information
print('Selected Image Info:', s2Image);
print('Cloud Coverage:', s2Image.get('CLOUDY_PIXEL_PERCENTAGE'));
Best Practices and Tips
- Use Level-2A data for most analysis tasks as it provides atmospherically corrected surface reflectance
- Filter by cloud cover to ensure quality results (typically < 20%)
- Use median composites for time-series analysis to reduce cloud effects
- Check available bands for your specific application
- Optimize visualization parameters for different regions and seasons
FAQ Section
What is the difference between Sentinel-2 Level-1C and Level-2A data?
Level-1C data provides top-of-atmosphere reflectance, while Level-2A data provides bottom-of-atmosphere (surface) reflectance after atmospheric correction. Level-2A data is more suitable for most scientific applications as it removes atmospheric effects.
How often does Sentinel-2 revisit the same area?
Sentinel-2 has a 10-day repeat cycle with two satellites (Sentinel-2A and Sentinel-2B). This results in a 5-day revisit time at the equator under cloud-free conditions.
What are the spatial resolutions of Sentinel-2 bands?
Sentinel-2 has three spatial resolutions: 10m (bands B2, B3, B4, B8), 20m (bands B5, B6, B7, B8A, B11, B12), and 60m (bands B1, B9, B10).
How can I reduce cloud cover in my Sentinel-2 images?
You can filter by the ‘CLOUDY_PIXEL_PERCENTAGE’ metadata property, use median composites of multiple images, or apply cloud masking algorithms available in Earth Engine.
What are the most commonly used Sentinel-2 bands?
For RGB visualization: B4 (red), B3 (green), B2 (blue). For vegetation analysis: B8 (NIR) and B4 (red) for NDVI calculation. B11 and B12 are commonly used for water and soil analysis.
Can I access Sentinel-2 data in real-time through GEE?
Google Earth Engine typically receives Sentinel-2 data with a delay of a few days to a week. For real-time access, you would need to download directly from ESA’s Copernicus Open Access Hub.
How do I export processed Sentinel-2 images from Earth Engine?
You can use the Export.image.toDrive() function to export images to your Google Drive. For example: Export.image.toDrive({image: ndvi, description: ‘NDVI_export’, scale: 10, region: aoi});
Are there any limitations to using Sentinel-2 data in Google Earth Engine?
Main limitations include: data processing delays, regional cloud cover affecting availability, and computational limits in GEE for very large area exports. Also, spatial resolution limitations for certain applications requiring higher detail.
What projection system does Sentinel-2 data use in Earth Engine?
Sentinel-2 data in Earth Engine is provided in the UTM (Universal Transverse Mercator) projection system with WGS84 datum. Each tile preserves its original UTM zone projection.
How can I improve visualization of urban areas in Sentinel-2 imagery?
For urban areas, consider using false color composites like SWIR-NIR-Red (B12,B8,B4) or NIR-Red-Green (B8,B4,B3). Adjust the min/max visualization parameters to enhance contrast in built-up areas.