Using GDAL commands to view, convert, and reproject maps

The GDAL command line programs allow simple ways of viewing and converting between different image formats, or changing map projections. You can also use ArcGIS and QGIS to do these things. Understanding the commands is useful for understanding the way QGIS describes these processes. (Further information about using GDAL commands in QGIS using the Gdaltools plugin).

Download the GDAL and OSGeo4W programs

The GDAL command line programs can be downloaded as part of the OSGeo4W software. (This also includes QGIS). To install OSGeo4W:

  • Download and run the OSGeo4W installer:
  • Following installation, the OSGeo4W icon should now be on your desktop, and the OSGeo4W Shell opens as a command line
  • Within the command line window, type "gdal16", to have the active gdal 1.6 version of all the tools

View information about a raster map image file with gdalinfo

The gdalinfo program is useful for listing information about a map image, for example, its format, size, coordinate system, extent, and any nodata pixels.The command takes the form:

gdalinfo file

For example, gdalinfo c:\edgar.tif

See full list of gdalinfo options

Convert vector files between different formats and projections with ogr2ogr

The ogr2ogr program is useful for converting vector map files to different formats. For example, an ESRI shapefile can be converted into a KML file with ogr2ogr. The command takes the form:

ogr2ogr [-t_srs srs_def] [-s_srs srs_def] [-f format_name] destination_image source_image

-a_srs srs_def is used to assign the resulting Spatial Reference System. For example, -a_srs EPSG:27700 puts the output file into the British National Grid.

-t_srs srs_def is used to reproject/transform to this Spatial Reference System on output.

[-f format_name]. Some possible formats are -f "ESRI Shapefile" or -f "KML". View list of supported vector formats.

Convert raster map images with gdal_translate

The gdal_translate program converts map images between different formats, for example, from TIFF to JPEG. The command takes the form:

gdal_translate [-of format] [-a_nodata value] source_image destination_image

For example, gdal_translate -of JPEG c:\edgar.tif c:\edgar.jpeg converts the TIFF image c:\edgar.tif to create a new file edgar.jpeg

The -a_nodata element can specify and maintain nodata or blank pixels, useful especially for mosaicking images. For example, if nodata pixels are white (255), use the command gdal_translate -of JPEG -a_nodata 255 c:\edgar.tif c:\edgar.jpeg

See full list of gdal_translate options. View list of supported raster formats.

Change the projection of raster map images with gdaltransform

The gdaltransform program converts map images between different projections, for example, from the British National Grid to the Global Spherical Mercator projection. The command takes the form:

gdaltransform [-s_srs srs_def] [-t_srs srs_def] [-a_nodata value] [sourcefilename] [destinationfilename]

-s_srs srs_def is used to assign the source Spatial Reference System. For example, -s_srs EPSG:27700 confirms the input file as being in the British National Grid projection.

-t_srs srs_def: is the target Spatial Reference System on output.

For example, to transform / reproject a map in the British National Grid projection (EPSG: 27700) into the WGS 84 Spherical Mercator projection (EPSG: 4326) use the command:

gdaltransform -s_srs "EPSG:27700" -t_srs "EPSG:4326" [sourcefilename] [destinationfilename]

By swapping the -s_srs and -t_srs parameters, the file can be converted from the WGS84 Spherical Mercator (EPSG: 4326) to the British National Grid (EPSG: 27700):

gdaltransform -s_srs "EPSG:4326" -t_srs "EPSG:27700" [sourcefilename] [destinationfilename]

Further information about Coordinate / Spatial Reference Systems and EPSG codes.

Help. For all the GDAL commmands, type a -- help suffix after the command to display the full list of options/parameters for that command, eg. gdal_translate --help

Using GDAL commands in QGIS

The GdalTools plugin in QGIS presents these GDAL commands, and others, through a graphic interface with natural language for options and settings. To use this, open QGIS and under Plugins > Manage Plugins, scroll down and select the GdalTools plugin. The GDAL tools then appear as a set of options under the Raster menu, including Information, Translate, and Warp.