Our friends at Airbus offer a myriad of medium and high resolution imagery products that look great on Mapbox. This morning, I used a short bash script to stitch together sample imagery from the SPOT-6 satellite and prepare it for upload to Mapbox.com. The script below processes the imagery so you can upload beautiful, web-projected, color-corrected imagery to your personal account in just a few steps.

1,700 km2 of 1.5-meter imagery of the outskirts of historic Detroit, MI. Pan around to see the mixture of agricultural fields, mining sites, golf courses, and the juxtaposition of new vs. old development. View full screen map.

After trimming the source images to three bands, reprojecting them to web mercator, and stitching together the individual pieces to make a mosaic, I was able to upload the resulting TIFF directly to Mapbox.com.

You can use the same script that I did by copying and pasting the script below into a text editor and saving it as an executable bash file. Drop it into the same folder as your Airbus sample images then execute it from the command line with your input images as command line arguments. I saved the file as "process", navigated to the folder where the executable and my image files live, and called:

Executable bash file:

./process input-file-1.tif input-file-2.tif input-file-3.tif .... etc



# for each image: reproject, scale to 8-bit, cut to 3 bands, clean up no data values
for var in $@; do
export var=${var%.JP2}

gdalwarp -s_srs EPSG:32616 -t_srs EPSG:3857 -r cubic -dstnodata 0 ${var}.JP2 ${var}-3857.tif

gdal_translate -scale 0 3393 0 255 -ot Byte -b 1 -b 2 -b 3 -co photometric=rgb -a_srs EPSG:3857 -a_nodata "0 0 0" -of GTiff ${var}-3857.tif ${var}-3857-rgb.tif;

# merge together separate images
gdal_merge.py -o merged.tif -n 0 *rgb.tif

# use color formula to brighten
convert -channel b -gamma 0.98 -channel rgb -sigmoidal-contrast 18,15% -modulate 100,108 merged.tif merged-color.tif

# add geo information back to file after imagemagick command
gdal_translate -a_srs EPSG:3857 -a_nodata "0 0 0" merged-color.tif processed.tif
listgeo -tfw merged.tif
mv merged.tfw processed.tfw
gdal_edit.py -a_srs EPSG:3857 processed.tif

# clean up processing files, leaving just the original images & final processed composite image
for var in $@; do
  export var=${var%.tif}
  rm ${var}-3857.tif
  rm ${var}-3857-rgb.tif
  rm ${var}-3857-rgb.tif.aux.xml
  rm ${var}-3857-rgb-nb.tif
  rm merged.tif
  rm merged-color.tif
  rm processed.tfw;

If you'd like to modify this script for a different imagery source, you'll want to pay attention to the starting projection of the image, the "no data" values, the number of bands your source image has, and whether it needs to be scaled to 8-bit.

Questions? Hit me up on Twitter (@camillacaros) or reach out to us at satellite@mapbox.com.