Image for post
Image for post
Intensely-colored wildflowers covered the Carrizo Plain in the spring of 2017. Photograph ©2017 Steve Corey. cc by-nc-nd 2.0.

A Gentle Introduction to GDAL Part 4: Working with Satellite Data

Robert Simmon
Apr 23, 2017 · 11 min read
A very wet winter brought an incredible blanket of flowers to California in the spring of 2017. These Planet RapidEye images show how the flowers transformed Carrizo Plain National Monument. (Lindsay Hoshaw of KQED found these data in the Planet archive & wrote about the super bloom — thanks!) ©2017 Planet Labs Inc., cc-by-sa 4.0.
  1. Re-order or assemble bands into the desired order (red, green, blue; or near-infrared, red, green; etc.)
  2. Increase the resolution with pan-sharpening, if desired.
  3. Contrast-stretch and color-correct the imagery, either algorithmically or by hand.
  4. Restore georeferencing information, if necessary.
  5. Crop, re-project, and re-size image to merge with other data.

Using gdal_translate to Re-order Bands

Let’s start with the data that went into the March 31 image of the Carrizo Plain. Download a single scene here, or sign up for a Planet Explorer account. (It’s free, and you’ll be able to access PlanetScope and RapidEye data from California. Navigate to Carrizo Plain National Monument (about -119.725, 35.120) and download the RapidEye ortho tile with this ID: 20170331_190720_1155205_RapidEye-3 and its neighbors.) Now open the file 1155205_2017–03–31_RE3_3A.tif with your TIFF viewer of choice.

Image for post
Image for post
Blue, green, red RapidEye image of the Carrizo Plain. ©2017 Planet Labs Inc., cc-by-sa 4.0.
gdalinfo 1155205_2017–03–31_RE3_3A.tif
Band 1 Block=5000x1 Type=UInt16, ColorInterp=RedNoData Value=0Band 2 Block=5000x1 Type=UInt16, ColorInterp=GreenNoData Value=0Band 3 Block=5000x1 Type=UInt16, ColorInterp=BlueNoData Value=0Band 4 Block=5000x1 Type=UInt16, ColorInterp=UndefinedNoData Value=0Band 5 Block=5000x1 Type=UInt16, ColorInterp=UndefinedNoData Value=0
gdal_translate 1155205_2017-03-31_RE3_3A.tif 1155205_2017-03-31_RE3_3A_rgb.tif -b 3 -b 2 -b 1 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
Image for post
Image for post
Unstretched red, green, blue RapidEye image. ©2017 Planet Labs Inc., cc-by-sa 4.0.
gdalinfo -mm 1155205_2017-03-31_RE3_3A_rgb.tif
Band 1 Block=5000x1 Type=UInt16, ColorInterp=BlueComputed Min/Max=1422.000,41645.000NoData Value=0Band 2 Block=5000x1 Type=UInt16, ColorInterp=GreenComputed Min/Max=2108.000,49122.000NoData Value=0Band 3 Block=5000x1 Type=UInt16, ColorInterp=RedComputed Min/Max=3482.000,49572.000NoData Value=0

Algorithmic Image Enhancement

Since our eyes sense light proportionally, the data still need to be stretched to compensate, despite filling most of the available range. Like so:

gdal_translate 1155205_2017-03-31_RE3_3A_rgb.tif 1155205_2017–03–31_RE3_3A_rgb_scaled.tif -scale 1422 49572 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
Image for post
Image for post
Histogram stretched and square-root scaled red, green, blue RapidEye image. ©2017 Planet Labs Inc., cc-by-sa 4.0.
gdal_translate  1155205_2017-03-31_RE3_3A.tif 1155205_2017-03-31_RE3_3A_nir.tif -b 5 -b 3 -b 2 -scale 1051 49122 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
Image for post
Image for post
Histogram stretched and square-root scaled near-infrared, red, green RapidEye image. ©2017 Planet Labs Inc., cc-by-sa 4.0.

Combining Bands with gdal_merge.py

So far so good. These images show the Carrizo Plain in the relatively recent past (at least at the time I’m writing this)—what did the region look like last year, after a merely rainy (not biblically wet) winter?

gdal_merge.py -o carrizo-20160325-oli-rgb.tif -separate LC80420362016085LGN00_B4.TIF LC80420362016085LGN00_B3.TIF LC80420362016085LGN00_B2.TIF -co PHOTOMETRIC=RGB -co COMPRESS=DEFLATE
Image for post
Image for post
True-color Landsat 8 image collected on March 25, 2016. Data courtesy NASA/USGS Landsat.
gdal_pansharpen.py LC80420362016085LGN00_B8.TIF carrizo-20160325-oli-rgb.tif carrizo-20160325-oli-pan.tif -r bilinear -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
Pan-sharpening a Landsat image bumps the resolution from 30 meters per pixel (left) to 15 meters per pixel (right). Images based on data courtesy NASA/USGS Landsat.
gdal_pansharpen.py LC80420362016085LGN00_B8.TIF LC80420362016085LGN00_B4.TIF LC80420362016085LGN00_B3.TIF LC80420362016085LGN00_B2.TIF carrizo-20160325-oli-pan.tif -r bilinear -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB
gdaltindex 1155205_2017-03-31_RE3_3A_extent.shp 1155205_2017-03-31_RE3_3A.tif
gdalwarp -tr 5 5 -cutline 1155205_2017-03-31_RE3_3A_extent.shp -crop_to_cutline carrizo-20160325-oli-pan-8bit.tif carrizo-20160325-oli-pan-crop-5m.tif -co COMPRESS=LZW -co PHOTOMETRIC=RGB
Although there were some flowers in the spring of 2016, they can’t hold a candle to 2017’s bumper crop. Images based on data courtesy NASA/USGS LAndsat (left) and ©2017 Planet Labs Inc., cc-by-sa 4.0.
gdalcopyproj.py carrizo-20160325-oli-rgb.tif carrizo-20160325-oli-rgb-corrected-nogeo.tif

Planet Stories

Using space imagery to tell stories about our changing…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store