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 am trying to change the pixel value of a tif file (containing projection information) but after the pixel value is changed it is losing projection information.

I am using the Python imaging library for this and the code is like this

import Image
im ="some tif file")

So please help me in solving this ..

share|improve this question
up vote 6 down vote accepted

You need a Python library that supports the GeoTIFF format. Libraries that support only the TIFF file discard the projection and geotransform metadata when they are saved. GDAL is the most used open source Python library for reading/writing spatially aware rasters. So, for your example:

from osgeo import gdal

# Load file, and access the band and get a NumPy array
src = gdal.Open('myfile.tif', gdal.GA_Update)
band = src.GetRasterBand(1)
ar = band.ReadAsArray()

# Assign a new raster pixel value
ar[2,3] = 0

# Save/close the file
del ar, band, src
share|improve this answer
Thanks Mike ... I will you please suggest me some good resource where i can get the gdal related stuffs for Python.. Because I know C++ stuffs for gdal but i get some problems in converting that to the python – Vicky Nov 14 '11 at 6:41
Installing Python bindings for GDAL is simple for most Linux distros. For Windows, there are a few with my personal favourite installer being a simple installer from Christoph Gohlke – Mike T Nov 14 '11 at 8:45

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.