Skip to content Skip to footer

Cropping Landsat Scenes from their Bounding Box using Python | by Conor O’Sullivan | Feb, 2024


Removing the outer border of Landsat satellite images using the stac file

(source: author)

Telling stories with satellite images is straightforward. The mesmerising landscapes do most of the work. Yet, visualising them takes some work such as selecting and scaling the RGB channels. In this article, we will go further. We will see how we can get rid of that ugly bounding box. Specifically, we will:

  • Crop and rotate Landsat scenes using the stac file
  • Discuss how we can do this but also keep the geolocation of pixels

We will discuss key pieces of Python code and you can find the full project on GitHub.

We start by downloading a Landsat scene. You can do this using the EarthExplorer portal. Alternatively, if you want to use Python, the article below takes you through the process:

In the end, you should have a folder like Figure 1. These are all the files available for a Landsat level 2 science product. We’ll be working with the highlighted files. These are the 3 visible light bands and the SR_stac file.

Figure 1: Landsat level-2 science product files (source: author)

This particular scene was taken above Cape Town, South Africa. To see this we visualise the visible light bands using the get_rgb function. This takes the file name/ ID as a parameter. It will then load the bands (lines 8–10), stack them (line 13), scale them (line 14) and clip them (line 17).

import tifffile as tiff
import numpy as np
data_file = "./data/"

def get_rgb(ID):

# Load Blue (B2), Green (B3) and Red (B4) bands
R = tiff.imread(data_file +'{}/{}_SR_B4.TIF'.format(ID, ID))
G = tiff.imread(data_file +'{}/{}_SR_B3.TIF'.format(ID…



Source link