Processing satellite imagery
Familiarity with front-end development concepts. Some advanced JavaScript required.
In this tutorial, you will compare historical and present-day scenes of Dubai in the United Arab Emirates that show the landscape before and after Dubai's period of economic growth in the early 2000s.
To do this, you will download satellite imagery, use command line tools to process it, and use Mapbox GL JS with the Mapbox GL Compare plugin to create an interactive map with a 'swipe to compare' control.
You will use imagery from the USGS Landsat program to create georeferenced composite images that prioritize the natural look of land and water.
Landsat imagery is particularly appropriate for this use case because the program has been continually acquiring images of the Earth's surface for nearly 50 years, at a high enough spatial resolution to capture significant changes at the landscape scale.
This tutorial uses Landsat scenes covering Dubai, but you may also try out the process using other locations. A free NASA Earthdata account will let you use EarthExplorer, where the data for this tutorial comes from, and where you can get other Landsat scenes.
Getting started
If you are new to working with satellite imagery, or are unfamiliar with bands or the raster data type, read the How satellite imagery works guide before getting started.
There are a few tools you will need to complete this tutorial:
- GDAL GDAL is a low-level GIS toolkit that Rasterio depends on. Install GDAL using the method recommended for your operating system.
- Rasterio Rasterio is a tool for reading and writing geospatial raster data. You can install Rasterio on the command line with the command
pip install rasterio
. - rio-color rio-color is a Rasterio plugin for applying basic color-oriented image operations to geospatial rasters. You can install rio-color by following these instructions.
- Your Mapbox access token You can find your access token on your Mapbox Account page.
- A text editor. Use the text editor of your choice for writing HTML, CSS, and JavaScript.
- Mapbox GL Compare A freely available Mapbox GL JS plugin that adds an interactive 'swipe to compare' control to a Mapbox GL JS web map.
- Landsat scenes Download these two scenes from two different satellites in the Landsat series:
- Command line. You will also need to use your computer's command line to complete this tutorial.
Understanding Landsat scenes
Landsat image data is cut into scenes, which are roughly square images, for distribution. You can think of a scene as a single frame from a camera. A Landsat scene covers about 170 × 185 kilometers (105 × 115 miles).
The two scenes in this tutorial come from two different satellites in the Landsat series:
- The before image is from Landsat 5, which was decommissioned in 2013.
- The after image is from Landsat 8, the latest satellite.
Some features change between these satellites, but in general the Landsat program maintains as much consistency as possible, which makes this kind of comparison possible.
For a more detailed understanding of Landsat's imaging process, see the Landsat Data Continuity Mission documentation.
Examine the bundle contents
-
Create a new folder for your project files, and move the two Landsat files you downloaded in Getting started into the folder.
-
The Landsat Level 1 products that you downloaded are compressed
.tar.gz
files called bundles. Unpack both bundles. The method you use to unpack them will vary depending your computer's operating system, or your web browser may unzip or fully unpack them automatically. As long as the unpacked bundles are directories in your project folder, you will be able to follow the processing instructions exactly.
Each bundle will unpack into a directory that contains 14 items, mostly TIFF images. Each item's name starts with the Landsat product ID and ends with the band number. For example, LT05_L1TP_160043_20011208_20180930_01_T1_B1.TIF
is the Band 1 readout for the Landsat 5 LT05_L1TP_160043_20011208_20180930_01_T1
scene.
Open LT05_L1TP_160043_20011208_20180930_01_T1_B1.TIF
to see what Band 1 for the Landsat 5 scene looks like.
Process Landsat 5 imagery
Now that you have the images you want, you will process them so that you can use them in a live map. In this section, you will work entirely from the command line, starting with the Landsat 5 bundle you downloaded earlier.
In the following steps, you will composite the bands into a single image, reproject these bands into the Web Mercator (EPSG:3857
) projection, then color-correct the image.
Composite the bands
The aim of this tutorial is to make a visible image, and the natural choice would be to use the red, green, and blue bands to make a red, green, blue image. But Landsat 5 doesn’t have a blue band, so instead you will make a slightly false-color image with green for blue, red for green, and near-infrared for red. This wouldn’t work for scientific analysis, but it’s fine for visualization purposes.
The numbers of the Landsat 5 bands you’ll use, which will map respectively to red, green, and blue, are 3, 2, and 1.
To stack those bands into an RGB image, you will use the Rasterio command rio stack
to composite the TIFF files for Bands 1-3 and export them as a new file.
-
In your command line, navigate to the folder you created for the two Landsat scenes you downloaded.
-
Copy the following command and paste it into your command line:
rio stack --rgb LT05_L1TP_160043_20011208_20180930_01_T1/LT05_L1TP_160043_20011208_20180930_01_T1_B{3,2,1}.TIF landsat5_stack.tif
The --rgb
option tells viewing software (for example Photoshop) that the bands should be interpreted as red, green, and blue.
The last argument in this command is the new output file (landsat5_stack.tif
). The LT05_L1TP_160043_20011208_20180930_01_T1_B{3,2,1}.TIF
argument specifies the files that get combined. This command uses a shell expansion to specify bands 3, 2, and 1 instead of separately naming each band file.
After the command runs, check your project folder. You will see the new landsat5_stack.tif
file. Open this file to see what the new composite image looks like.
Reproject the image
Next, you will reproject the composite image into the Web Mercator (EPSG:3857) projection with rio warp
. You will tell rio warp
to reproject with bilinear sampling, a method that does not leave pixelation.
- Copy the following command and paste it into your command line:
rio warp --resampling bilinear --dst-crs EPSG:3857 landsat5_stack.tif landsat5_mercator.tif
The --dst-crs EPSG:3857
option sets the projection to Web Mercator. The last argument in this command is the new output file (landsat5_mercator.tif
).
After the command runs, open the new file with the reprojected image, landsat5_mercator.tif
. It will look like the image in landsat5_stack.tif
because the original projection is fairly close to Web Mercator.