views:

328

answers:

1

I am making a Python script which will read in a GeoTIFF file, and will do both: convert the GeoTIFF into a static JPEG (that is much smaller in size), and create a separate text file which contains the GeoTIFF headers.

Using the Python GDAL API, I am able to get the script to open a GeoTIFF file, and print details, such as the RasterXSize, RasterYSize, RasterCount, etc.

The problem is with saving a JPEG. I have researched the driver.CreateCopy() method, however, all it does is create a very large JPEG file that is blank and can't be opened.

Also, which method retrieves all of the GeoTIFF Headers that I can save to a file?

I'm neither an expert on GeoTIFFs nor GDAL, and I greatly appreciate the assistance!

+1  A: 

I figured it out myself with some Googling.

To save the .jpg file with varying level of quality, you need to use the following code:

# Assume this retrieves the dataset from a GeoTIFF file.
dataset = getDataSet(tiffFileLocation)      

saveOptions = []
saveOptions.append("QUALITY=75")

# Obtains a JPEG GDAL driver
jpegDriver = gdal.GetDriverByName("JPEG")   

# Create the .JPG file
jpegDriver.CreateCopy("imageFile.jpg", dataset, 0, saveOptions)  

The parameters I need are stored in both the theDataset.GetGeoTransform(), and the theDataset.GetProjection() methods.

Special thanks to this site: http://adventuresindevelopment.blogspot.com/2008/12/python-gdal-set-jpeg-quality-values-and.html

Phanto