7

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

3 Answers 3

21

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
2
  • 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
    Commented Jul 29, 2014 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
    Commented Sep 15, 2016 at 12:59
5

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

3
  • 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
    Commented Jul 29, 2014 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
    Commented Aug 4, 2014 at 17:20
  • I did what user10353 suggests, but the command copied the whole .tif file and not only the georeferencing....
    – Steven
    Commented Nov 1, 2021 at 20:19
2

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

3
  • +1 but note that not all versions of listgeo/geotifcp support tiffs > 4GB (i.e "bigtiffs").
    – user2856
    Commented Jul 29, 2014 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
    Commented Jul 29, 2014 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
    Commented Jul 8, 2021 at 23:45

Your Answer

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

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