GDAL Command Line – How to Copy Projections

gdalgdalwarpgeotiff-tiffimagejraster

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

Best Answer

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
Related Question