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

I'm trying to read as array two raster files using ReadAsArray in GDAL/python, perform some map algebra operation on it using numpy and then write the resulting raster file in GTiff format using WriteArray in GDAL/Python. The spatial reference system of the input raster files are the same. I want to know the resulting GTiff file will have the same coordinate system or not?

share|improve this question
up vote 3 down vote accepted

The only Python WriteArray() method I know of is gdal.Band.WriteArray() which is called on an existing file. It would be at the point where the file is created that it's coordinate system and geotransform is established. So a simplistic use of gdal.Driver.Create() and gdal.Band.WriteArray() will not preserve the coordinate system.

You have a couple options.

  1. Create the output file with gdal.Driver.Create() and carefully set the projection and geotransform to match the source image.
  2. Alternatively write the array using the gdal_array.SaveArray() method which includes a prototype input file from which the georeferencing info should be closed.

eg. (not actually tested)

img1 = gdal_array.LoadFile("abc.tif")
img2 = img1 * 2
gdal_array.SaveArray(img2, "out.tif", "GTiff", gdal.Open("abc.tif"))
share|improve this answer
great! Thank you – f.ashouri Nov 7 '12 at 23:57

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.