I have two images, a georeferenced Tiff and a second Tiff without a reference. The second image is a copy of the first, but it lost its reference. Now, I want to copy the reference from the first Tiff to the second Tiff using GDAL using the command line.

I had a look at several gdal utilities like gdalwarp, gdal_translate etc. but it seems that they only work on one image at a time and cannot "copy" a projection.

How can I do this?

I am using ImageJ for image analysis (segmentation) on 600 Tiff-images, all formerly geotiffs. However, during import ImageJ sets the xmin,ymin to (0,0) and looses all spatial information. Now, I try to use GDAL within an ImageJ macro to reload the spatial information so that the segmentation output also has a proper spatial reference


I would recommend to use gdalcopyproj.py, a sample file from the GDAL repository done for this purpose as mentioned directly in the script:

Duplicate the geotransform and projection metadata from one raster dataset to another, which can be useful after performing image manipulations with other software that ignores or discards georeferencing metadata.

The command line is just:

gdalcopyproj.py source_file dest_file
  • Thank you! I think that this would be the best way, however I am too stupid to setup python/gdal on windows 7. I have the OSGEO4W installed (with GDAL 1.11.0), yet I failed to get the python bindings running. I ended up with downloading GDAL, and then SWIG, which I could not get running, neither the python command examples...any suggestions where to start?
    – Jens
    Jul 29 '14 at 19:49
  • NB this does not seem change the original dest_file but stores the srs information in an XML file. At least that was the case for a set of jp2 files.
    – j08lue
    Sep 15 '16 at 12:59

Use gdalsrsinfo to get the srs of the tiff that still has the projection:

gdalsrsinfo -o wkt tiffwithsrs.tiff

Then copy the output and use gdal_translate to apply it to a new tiff:

gdal_translate -a_srs '...' tiffwithoutsrs.tif newfixedtif.tif

just paste your projection after the -a_srs option

  • Yes, that sounds like a good idea, however, I just realized that I also need the extent from the former image, not just the projection. -o wkt only gets the projection (what I asked for, I know...)
    – Jens
    Jul 29 '14 at 19:55
  • Ah. You can use gdal_edit.py to edit corners and srs. It just overwrites data: gdal.org/gdal_edit.html
    – user10353
    Aug 4 '14 at 17:20
  • I did what user10353 suggests, but the command copied the whole .tif file and not only the georeferencing.... Nov 1 at 20:19

I would use listgeo http://www.remotesensing.org/geotiff/listgeo.html and then geotifcp.

  • +1 but note that not all versions of listgeo/geotifcp support tiffs > 4GB (i.e "bigtiffs").
    – user2856
    Jul 29 '14 at 2:34
  • Great, that worked. It took me a while to figure out HOW it works. It is a two step process. First dump the projection info into a text file, then use geotifcp to glue that header onto the "headerless" tif-file. And all info is used. Thank you!
    – Jens
    Jul 29 '14 at 20:17
  • This worked for me, and I found this answer that explained the usage of these utilities gis.stackexchange.com/a/48383
    – ice cream
    Jul 8 at 23:45

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.