Geoma

How to Resample Sentinel-2 Satellite Imagery Using GDAL

Introduction

Sentinel-2 provides multispectral imagery at different spatial resolutions (10m, 20m, and 60m). For many remote sensing applications, resampling bands to a uniform resolution is necessary to facilitate analysis. In this guide, we will use the GDAL library to resample Sentinel-2 imagery from 20m and 60m resolutions to 10m resolution.

Prerequisites

  • GDAL (Geospatial Data Abstraction Library)
  • Python 3 or above
  • Sentinel-2 imagery (Level-2A product in .jp2 format)

Understanding Sentinel-2 Resampling

Sentinel-2 images consist of multiple bands captured at different resolutions:

  • 10m resolution: Bands 2, 3, 4, 8
  • 20m resolution: Bands 5, 6, 7, 8a, 11, 12
  • 60m resolution: Bands 1, 9, 10

For many applications (such as vegetation analysis), it is beneficial to bring all bands to 10m resolution using a resampling method like nearest neighbor, bilinear, or cubic interpolation.

Python Script for Resampling Sentinel-2 Imagery

The following script automates the resampling of Sentinel-2 images using GDAL.

Loading Required Packages

import os
import re
from osgeo import gdal

Setting Up Paths

rawdataPath: Path to the input Sentinel-2 images. resamplePath: Directory where the resampled images will be saved. If it doesn't exist, the script creates it.

# Define input and output directories
rawdataPath = "./sample_data/input_raster/"
resamplePath = "./sample_data/resample_raster/"

# Create output directory if it doesn't exist
if not os.path.exists(resamplePath):
    os.mkdir(resamplePath)

Resampling Configuration

Choosing the Right Resampling Method. GDAL supports various resampling algorithms. Depending on your use case, you can modify the resampleMethod parameter:

"nearest" → Preserves original pixel values, best for categorical data (e.g., land cover classification).

"bilinear" → Computes an average of surrounding pixels, suitable for continuous data (e.g., temperature, NDVI).

"cubic" → Higher quality interpolation but computationally expensive.

# Output resolution (10m)
outRes = 10

# Resampling method (nearest neighbor)
resampleMethod = "nearest"

Resampling Process

# Loop through each file and resample
for file in os.listdir(rawdataPath):
    srcPath = os.path.join(rawdataPath, file)
    resamplefile = file.replace("_20", "_10").replace("_60", "_10").replace(".jp2", ".tif")
    dstpath = os.path.join(resamplePath, resamplefile)
    
    # Define GDAL warp options
    warpOptions = gdal.WarpOptions(
        format="GTiff",
        outputType=gdal.GDT_UInt16,
        xRes=outRes,
        yRes=outRes,
        resampleAlg=resampleMethod,
        callback=gdal.TermProgress_nocb
    )
    
    # Perform resampling
    gdal.Warp(dstpath, srcPath, options=warpOptions)

Verify the Output

After running the script, the resampled images will be stored in the resamplePath directory. You can visualize them using QGIS

Conclusion

In this guide, we demonstrated how to resample Sentinel-2 imagery using Python and GDAL. This method ensures that all bands are at the same spatial resolution, making it easier for further analysis such as vegetation mapping, land cover classification, or NDVI calculations.

Enjoyed this article? Explore more blogs or give your feedback for this article

The Geoma Team consists of GIS and remote sensing experts passionate about geospatial technology, agriculture, and environmental analysis. Connect with the team on LinkedIn.

Contact Us

Email: contact@geoma.in