[gdal-dev] Re: beginners programming questions

WolfgangZ wollez at gmx.net
Fri Feb 15 10:31:50 EST 2008


Jose Luis Gomez Dans schrieb:
> 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

Hi Jose,
thanks for your answer! I thought some functionality is already included 
in gdal that was why I was asking, but it seems that I have to use Numpy 
to do that. I already used on of the Scipy Cookbook examples some time 
ago, but I will look into that again.
Many thanks
Wolfgang



More information about the gdal-dev mailing list