[gdal-dev] beginners programming questions

Jose Luis Gomez Dans josegomez at gmx.net
Fri Feb 15 10:18:56 EST 2008


Hi,
> 1. accessing the cell value of a (float) tiff. I know how to load the 
> map into an array, but this seems to be overkill.

You can read single pixel values or "spectra" (if the image has several bands, you can read all the different bands' values for a particular location). Sample function:

def read_one_pixel (row, col, fname, dtype):
        g = gdal.Open ( fname )
        values = g.ReadRaster( row, col, 1, 1)
        values_f = unpack (dtype*g.RasterCount, values)
        return values_f

> 2. can I get the surrounding cells or better directly (bilinear/cubic) 
> interpolated data? I want to extract the elevation for GPS points, but 
> only the cell value looks not so nice in 3D model as there also 
> interpolation between the heights is done.

Once you have your data points, you can interpolation using numpy/scipy, it's got a large number of interpolators. The choice will depend on many things, but here's some cookbook guidance: <http://scipy.org/Cookbook/Interpolation>
Alternatively, RBFs are also supported:
<http://scipy.org/Cookbook/RadialBasisFunctions>


> 3. can I extract height profiles along a line between two points?

Read the whole array in, and use something like numpy.take().
 
> 4. can I change the resolution of the input map directly in python (as 
> replacement of gdal_translate -tr)?

See answer to Q. 2.

Jose
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


More information about the gdal-dev mailing list