source: DPPP/ukcip02_server/trunk/png_to_tif.py @ 3360

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/DPPP/ukcip02_server/trunk/png_to_tif.py@5243
Revision 3360, 593 bytes checked in by spascoe, 12 years ago (diff)

Quick import of code I have been working on to server ukcip02 data.
This code may well move soon.

Line 
1#!/usr/bin/python
2"""
3Convert a PNG to a GeoTIFF.  Assumes EPSG:4326 and global extent -180,-90,180,90.
4
5"""
6
7import sys
8
9from osgeo import gdal
10from osgeo import osr
11
12infile = sys.argv[1]
13
14d = gdal.Open(infile)
15srs = osr.SpatialReference()
16srs.SetWellKnownGeogCS('EPSG:4326')
17d.SetGCPs([gdal.GCP(-180, 90, 0, 0, 0),
18           gdal.GCP(-180, -90, 0, 0, 480),
19           gdal.GCP(180, 90, 0, 960, 0),
20           gdal.GCP(180, -90, 0, 960, 480)],
21          srs.ExportToWkt())
22d.SetProjection(srs.ExportToWkt())
23
24dTIFF = gdal.GetDriverByName('GTIFF')
25dst = dTIFF.CreateCopy(infile+'.tif', d, 0)
Note: See TracBrowser for help on using the repository browser.