Clipping a raster with GDAL

Tim Sutton’s  excellent post from last year gives a recipe for creating a professional looking color relief background map from elevation data, and using only GDAL tools. I’d like to suggest one additional procedure to his step-by-step guide.

 One of the popular sources for freely available digital elevation data is NASA’s SRTM program. These DEM tiles are distributed in GeoTiff format (among others) and each tile covers a 5 degree by 5 degree square. Often your area of interest will fall across several tiles. When you complete Tim’s process, including using a polygon “cutline”  your final color relief raster will show the country (or region) of interest with white space around the edges. In many cases this white space can be quite large, making the final tiff file much larger than is necessary. For example, I created a color relief of Burkina Faso. This African country extends from about 2 degrees W to about 6 degrees W. So I needed two SRTM tiles  to cover the E-W extent: one from 0 to 5 degrees W and another from 5-10 degrees W. Also in the N-S direction I needed two 5 degree tiles to cover the country. So I started with four SRTM DEM tiles covering an area about four times the size of the Burkina Faso. After running

gdalwarp -cutline  ....

I was left me with a raster hundreds of kilometers larger in each direction than the actual borders. To clip out only the extent I needed required one more application of a GDAL tool: gdal_translate with the -projwin option. This allowed me to define the upper left and lower right X-Y coordinates of a “window” to be clipped out of the original raster thus creating a new GeoTiff file, less than 1/2 the size of the original.

In my case, the invocation of gdal_translate was:

gdal_translate -projwin -6 15.1 -2.5 8.5 bkf_relief.tif bkf_relief_clipped.tif


Leave a Reply

Your email address will not be published. Required fields are marked *