Child pages
  • Merging rasters with GDAL
Skip to end of metadata
Go to start of metadata

Dozen of times you come across a pile of tiles of raster. In most cases to use them you want to merge them. This article describes how to do that using open source GDAL combined with good old batching under windows. A nice source of ASCII raster file just (September 2015) made available are Digital Terrain models from the United Kingdom. These can be found via or directly via


  1. GDAL installed (can be as site package of python via or otherwise as part of the OSGEO4W suite of software)
  2. check if is available in the installation (if not download it from github)

Step-by-step guide

Follow these steps

  1. Download the appropriate zit of tiles
  2. Unpack them
  3. Open a command prompt in windows and navigate to the folder with ASCII's (note, not only ASCII's are supported by GDAL, check this page for all supported raster formats)
  4. Using the dir command create a list of ASCII's

    dir command
    dir /b /s *.asc > listofascs.txt
  5. Create a batch file in your favorite (plain) text editor with the following line of code

    GDAL merge command
    c:\python27\python.exe c:\python27\lib\site-packages\osgeo\ -n -9999 -v -o output.tif --optfile listofascs.txt

    Note! In this case Python in c:\Python27 is used including the (downloaded from github) under the osgeo site-package of Python27.
    More information on the options of can be found on the utilities page of GDAL

  6. In the last step you

    1. can add a coordinate reference system to you file

    2. select a subset of you image

      Adding an SRID and subsetting the raster
      c:\python27\lib\site-packages\osgeo\gdal_translate -projwin ulx uly lrx lry -of GTiff -a_srs EPSG:code input.format output.format


      1. -projwin is the window in coordinates (ul = Upper Left and lr = Lower Right) in the projection system specified under -a_srs
      2. -a_srs is if the SRID number (WGS84 has EPSG:4326) causes an error than download the correct version from You need the Human-Readable OGC WKT version of the list of projection formats. For the UK the data is in EPSG:27700
      3. -of is the output format
  7. Make a nice visualisation in you favorite software. The picture below is created in QGIS2.10 using two cpt_city colorramps combined.