Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Apologies if the following question is somewhat stupid, but I am only VERY new to this whole GIS thing.

I am trying to convert some projected geoTiff images to WGS84 using gdal in python. I have found a post that outlines the process to transform points within projected GeoTiffs using something similar to the following:

from osgeo import osr, gdal

# get the existing coordinate system
ds = gdal.Open('path/to/file')
old_cs= osr.SpatialReference()

# create the new coordinate system
wgs84_wkt = """
        SPHEROID["WGS 84",6378137,298.257223563,
new_cs = osr.SpatialReference()
new_cs .ImportFromWkt(wgs84_wkt)

# create a transform object to convert between coordinate systems
transform = osr.CoordinateTransformation(old_cs,new_cs) 

#get the point to transform, pixel (0,0) in this case
width = ds.RasterXSize
height = ds.RasterYSize
gt = ds.GetGeoTransform()
minx = gt[0]
miny = gt[3] + width*gt[4] + height*gt[5] 

#get the coordinates in lat long
latlong = transform.TransformPoint(x,y) 

My question is, if I want to convert these points and create a new WGS84 GeoTiff file, is this the best way to go about it? Is there a function that exists that will do such as task in 1 step?


share|improve this question
up vote 14 down vote accepted

One simpler way would be to use the GDAL command line tools:

gdalwarp infile.tif outfile.tif -t_srs "+proj=longlat +ellps=WGS84"

That can be invoked easily enough via scripting for batch jobs. This will warp the raster to a new grid, and there are other options to control the details.

The target (t_srs) coordinate system can be PROJ.4 as shown, or an actual file with WKT, amongst other options. The source (-s_srs) coordinate system is assumed known, but can be set explicitly like the target.

That might be easier to get the job done if you don't have to use the GDAL API via Python.

There is a tutorial for warping with the API here, it says the support for Python is incomplete (I don't know the details):

share|improve this answer
Thanks for the great answer mdsumner! While the solution I am after is supposed to be written in python, perhaps I can get away with just looping this command in a python script. – JT.WK Mar 2 '11 at 20:54

As mdsumner said, it's much easier to use command line than the python bindings, unless you want to execute very complex tasks.

So, if you like python, like I do, you can run the command line tool with:

import os  
os.sys('gdalwarp infile.tif outfile.tif -t_srs "+proj=longlat +ellps=WGS84"')

or iterate through a list of files:

listoffiles=['file1, file2, file3, filen']  
for file in listoffiles:
    os.system('gdalwarp %s %s -t_srs "+proj=longlat +ellps=WGS84"' %(file,'new_'+file))  

And even use multiprocessing tools use the full power of your machine to execute big tasks.

share|improve this answer
Thanks Pablo. The multiprocessing tools is something that I will definitely look into! – JT.WK Mar 2 '11 at 20:55
At gdal 2.0 there is native support for multiprocessing - just append -wo NUM_THREADS=ALL_CPUS to your gdalwarp command. – valveLondon Aug 17 '12 at 19:34
os.sys is a built-in module; you want the os.system command – Mike T Jan 27 '13 at 6:08
My answer is outdated, is a better approach. – Pablo Jan 28 '13 at 10:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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