3

Alright, so I'm getting closer to figuring this out but I'm stuck at one (that I know of) thing... how do I use GDAL to apply a known origin of a GeoTiff to another that has been processed in Photoshop?

The snippet below is what I'm trying to get working. It's a pretty rough 'sketch' of what I want to accomplish and will work it out once I get going in the right direction. I'm just hoping that you can tell what I mean by looking.

So, I take the data from a good gtiff image, and want to copy it to the same image that has been broken. Is there any way to do that?

def applyRefs(input, output):
print "processing %s" %input
in_file = gdal.open(input)
gt = in_file.GetGeoTransform()
if not geotransform is None:
print 'Origin = (',geotransform[0], ',',geotransform[3],')'
else:
print" this is where the function to copy world file info to processed tif `will go"`

https://github.com/minorsecond/GIS/blob/master/tifFix.py

1 Answer 1

2

Use affine to load the world file, translate it from center to corner reference, and reorder the coefficients for GDAL.

import os
import affine
from osgeo import gdal
gdal.UseExceptions()

ds = gdal.Open(input, gdal.GA_Update)
gt = ds.GetGeoTransform()
if not gt:
    # guess the name of the world file, if it exists
    inputwf = os.path.splitext(input)[0] + '.tfw'
    # then read and apply the world file
    with open(inputwf) as fp:
        A = affine.loadsw(fp.read())
    ds.SetGeoTransform(A.to_gdal())

There also old school methods with libgeotiff utility programs:

  • Extract a world file: listgeo -tfw myfile.tif
  • Copy a world file: geotifcp -e myfile.tfw input_without_gt.tif output_with_gt.tif

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.