If you're looking to trace villages in OpenStreetMap or count cars in a shopping center parking lot, DigitalGlobe's satellite constellation offers the highest resolution available on the commercial market. The short bash script below stitches together sample imagery from DG's satellites and prepares it for upload to Mapbox.com. You can use it to upload beautiful, web-projected, color-corrected imagery to your Mapbox account in just a few steps.

Riyadh's King Abdullah Petroleum Studies and Research Center (KAPSARC) campus is filled with cutting edge architecture and LEED certified buildings.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 DG 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%.TIF}
    gdalwarp -s_srs EPSG:32638 -t_srs EPSG:3857 -r cubic -dstnodata 0 ${var}.tif ${var}-3857.tif
    gdal_translate -scale 0 2047 0 255 -ot Byte -b 4 -b 3 -b 2 -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 -sigmoidal-contrast 8,10% 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.