I have a huge set of compressed GeoTIFF files. Someone forgot to set the projection while creating the GeoTIFF files and I would like to add it now.

If I use

gdalwarp -t_srs source.tif target.tif

the result is an uncompressed file. I would like to avoid the (de)compressing if possible, since I expect it will degrade the final result due to the recompression and because it will require more time to decompress and compress each file again.

I assume that the projection information is stored in the header.

Is there an easy way to just update the projection information in a GeoTIFF file?

  • ok..didn't get your question first time..removing ans..
    – vinayan
    Jun 6, 2012 at 9:56

2 Answers 2


Make a tiny Python script named "UpdateSRS.py":

import sys
from glob import glob
from osgeo import gdal, osr

# Define your projection here
sr = osr.SpatialReference()
# For example, UTM Zone 11
sr_wkt = sr.ExportToWkt()

file_list = set()
for arg in sys.argv[1:]:
for file in file_list:
    ds = gdal.Open(file, gdal.GA_Update)
    if ds:
        print('Updating projection for ' + file)
        res = ds.SetProjection(sr_wkt)
        if res != 0:
            print('Setting projection failed ' + str(res))
        ds = None # save, close
        print('Could not open with GDAL: ' + file)

Run it from a command prompt with arguments, something like this:

python UpdateSRS.py *.tif

You will need to update the logic to generate sr_wkt. It could be as simple as just pasting the WKT for the projection, if you know it.

  • Just was I was looking for. I wasn't sure if GDAL through Python would allow the projection to be updated without changing the image part of the file, but it does :) Thanks a lot for your help and answer!
    – Chau
    Jun 6, 2012 at 11:54

You can also use .prj files with projection info. In this way you can avoid any modification of source tiffs and this is the fastest way for large amount of data I believe.

PS using .prj file outside Esri software can be tricky and is not supported everywhere. So, check if it is supported in the software where you are planning to use your rasters.

  • 1
    For GeoTIFF, this is a hack, which might work for Esri software. Using the GTiff GDAL driver, a .prj file is ignored, since this metadata needs to be in the header.
    – Mike T
    Jun 6, 2012 at 11:18
  • Oh, thats a useful info! Have not realized that it is not fully supported in GDAL. There is some way to use it by specifying in -s_srs parameter for some tools but anyway I agree - it is quite unreliable outside Esri world. I have updated my answer, thanks! Jun 6, 2012 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.