[FWTools] random access querying raster image - help

Frank Warmerdam warmerdam at pobox.com
Fri Aug 25 15:49:19 EDT 2006


Kenton Williams wrote:
> Hello,
> 
> I am needing to write a simple (I think) program/script that takes a
> coordinate pair as input, queries a raster at those coordinates, and
> returns the raster's value at that point.  I would prefer to use Python,
> but I am open to better suggestions. Is this possible to do using any of
> FWtools or GDAL's utility programs?  If it's possible, could someone write
> a very brief list of the sequence of suggested steps?  Any help would be
> greatly appreciated.  Thanks in advance.

Kenton,

This should be fairly straight forward in python.

You would:

  o open the file.
  o fetch the file coordinate system (via GetGeotransform()).
  o Transform georeferenced coordinates into pixel/line coordinates
    using the geotransform.
  o get the target raster band.
  o Use ReadRaster() to read the target pixel, assuming it is on the file.
  o the returned buffer may need to be read using something funky since it
    will be returned as a "binary string".  I know I have used some sort of
    binary string packer/unpacker before, but I can't seem to find an
    example.

Good luck,
-- 
---------------------------------------+--------------------------------------
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 FWTools mailing list