[Gdal-dev] coordinates with gdal_array

Frank Warmerdam warmerdam at pobox.com
Tue Nov 13 10:59:50 EST 2007


sandric ionut wrote:
> Hello:
>  
> I am using gdal_array to read data as array, process the data, and write 
> it back as raster data. When I save the array to raster, using any 
> format supported by gdal, I loose the coordinates. How can I keep the 
> coordinates after I process the array?

Ionut,

The plain arrays unfortunately can't carry around coordinate and other
types of metadata.  So the workaround is that the gdal_array.SaveArray()
method has a 4th argument which is a prototype dataset.  This prototype
dataset will be used as a source of coordinate system and georeferencing
information for the created file.

So you could do something like:

data = gdal_array.LoadFile('src.tif')

data = (data - 15) * 1.33

gdal_array.SaveArray( data, 'dst.tif', prototype = 'src.tif' )

The prototype argument can be either the name of a datasource (which
will be opened internally) or an existing open GDAL dataset handle.
This approach doesn't help much if you are resizing, or subsetting
the data as part of your processing (unfortunately).

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the gdal-dev mailing list