I have a .tif file that I created with Python and when I open it in ArcMap it says it doesn't have spatial reference information. Is there a way to set the spatial reference with GDAL if I have a .prj file? I have tried running this command through Python:

gdalwarp -t_srs ESRI::file.prj tmp.tif ouput.tif

Where -t_srs is the 'target spatial reference set', but it gives me the error: "Unable to compute a transformation between pixel/line and georeferenced coordinated for tmp.tif"

Is there an easy way to set the spatial reference of a .tif file with GDAL?

  • 1
    Your command should work according to gdal.org/… but maybe you must give also -s_srs with the same reference because obviously gdalwarp does not find it automatically. However, gdal_edit.py is better option. Best of all would be to make your python code to write projection info directly into the file it creates.
    – user30184
    Commented Mar 11, 2015 at 15:12
  • Thanks @user30184! For future users, this method works too: gdalwarp -s_srs ESRI::file.prj tmp.tif ouput.tif (All I had to do was change -t_srs to -s_srs)
    – user45567
    Commented Mar 16, 2015 at 13:37

1 Answer 1


if you have a geotiff you can write this information in the header. Open your .prj in a text editor to identify the code (EPSG code, see spatialreference.org if it is not in your .prj). Then you can use gdal_edit.py to define the projection (without writing a new file). Example below with the EPSG code of WGS84.

gdal_edit.py -a_srs EPSG:4326 yourimage.tif

Note that you can also use the "define projection" tool using arcpy if you have ArcGIS on the computer where you run your Python script.

import arcpy
coordinateSystem = arcpy.SpatialReference("path_to_prj")
arcpy.DefineProjection_management("path_to_file", coordinateSystem)

Of course, I assume here that your image is already georeference, but that the information about your coordinate system are missing. In you also need to georeference, have a look at this answer with gdal_translate, or add a tfw file with your .tif.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.