Reproject a spatial dataset using GDAL/OGR

Use the GDAL/OGR utilities ogr2ogr or gdalwarp to reproject vector data (points, lines, and polygons) or raster data, respectively. These are command line utilities, which you can use by typing the appropriate statements at a terminal window prompt (OS X, Linux) or at a DOS Command Prompt (Windows). Below are some examples of basic usage. Note that ogr2ogr is always used for vector data, and gdalwarp is always used for raster data.



Reproject vector data (points, lines, and polygons)

The examples below assume a shapefile, but the input and output data can be in any vector format supported by your installed version of GDAL/OGR (used ogrinfo --formats to check). Both the input and output projections can be specified in several ways, although in many cases the input projection can be determined automatically from the data source. When using ogr2ogr, remember that the output filename should come before the input filename!

  • Example 1: Use the EPSG code (if known) to specify the output projection
    ogr2ogr -t_srs EPSG:2784 output_vector.shp input_vector.shp
  • Example 2: Specify the output projection using the full Proj.4 definition string
    ogr2ogr -t_srs '+proj=tmerc +lat_0=21.16666666666667 +lon_0=-158 \
                    +k=0.999990 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs' \
                    output_vector.shp input_vector.shp
  • Example 3: Use an appropriate file (e.g. the *.prj file associated with a shapefile) to specify the output projection
    ogr2ogr -t_srs some_shapefile.prj output_vector.shp input_vector.shp

Reproject raster data (gridded images)

Because a rectangular grid in one projection is not necessarily a rectangular grid in another, reprojecting a raster layer often requires "warping". Fortunately, this can usually be done quite easily using gdalwarp. The examples below assume a GeoTIFF, but the input and output data can be in any raster format supported by your installed version of GDAL/OGR (used gdalinfo --formats to check). As with other GDAL/OGR tools, the projection can be specified in several ways. The syntax is similar to that of ogr2ogr, and again the projection can be specified in several ways. However, in contrast to ogr2ogr, the output filename should come after the input filename.

  • Example 1: Use the EPSG code (if known) to specify the output projection
    gdalwarp -t_srs EPSG:2784 input_raster.tif output_raster.tif
  • Example 2: Specify the output projection using the full Proj.4 definition string
    gdalwarp -t_srs '+proj=tmerc +lat_0=21.16666666666667 +lon_0=-158 \
                    +k=0.999990 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs' \
                    input_raster.tif output_raster.tif

Learning More:

scicomp: