[gdal-dev] Re: Reading height data from DEM files
İsmail Dönmez
ismail at namtrac.org
Mon Jun 9 13:06:52 EDT 2008
Hi,
On Mon, Jun 9, 2008 at 7:44 PM, Christopher Barker
<Chris.Barker at noaa.gov> wrote:
> İsmail Dönmez wrote:
>>
>> Since I have to calculate elevation for all points in dted file, I
>> tried something like this:
>>
>>>>> from osgeo import gdal
>>>>> f = gdal.Open("n30.dt0")
>>>>> f.ReadAsArray()
>>
>> array([[ 0, 0, 0, ..., 76, 75, 77],
>> [ 0, 0, 0, ..., 54, 57, 59],
>> [ 0, 0, 0, ..., 62, 60, 63],
>> ...,
>> [ 18, 17, 16, ..., -28, -28, -19],
>> [ 22, 17, 17, ..., -21, -19, -27],
>> [ 20, 16, 14, ..., -29, -27, -38]], dtype=int16)
>>
>> So in the final array, array [x][y] would give me elevation data for
>> (x,y) coordinates (relative to the dted file), am I correct?
>
> You want to use: array[x,y] -- the array is a 2-d array. What you wrote will
> work, but is far less efficient -- it creates a 1-d array object, then pulls
> your item out of that.
Indeed it takes like 0.2 seconds per DTED file.
> Do go read up on numpy -- it provides a lot of nifty features for this kind
> of work.
Thanks for the pointer.
--
Never learn by your mistakes, if you do you may never dare to try again.
More information about the gdal-dev
mailing list