[Gdal-dev] Find elevation data at specific point
Frank Warmerdam
warmerdam at pobox.com
Fri Jun 4 13:06:48 EDT 2004
Gerald Brandt wrote:
> Hi,
>
> I would like to know how to get the elevation from a specific coordinate
> (in latitude/longitude or UTM). I can convert between lat/long and UTM
> as needed for the specific map data loaded, but I don't know how to get
> the elevation of that coordinate.
>
> I'm assuming that I need to get the xpixel and yline values, and
> reference off of that somehow. But, being new to GDAL, I'm not quite
> sure.
Gerald,
I haven't got time to prepare a proper demonstration. But the brief answer
is you need to:
o Transform your coordinate into the coordinate system of the image.
For instance if you start with lat/long but the image is in UTM, convert
it to UTM.
o Convert that coordinate to image pixel/line coordinates. Assuming the
image is north-up (no rotational coefficients) then this would be:
pixel_x = (geo_x - gt[0]) / gt[1]
pixel_y = (geo_y - gt[3]) / gt[5]
Where gt[] is the Geotransform array fetched with the GetGeotransform()
method on the GDALDataset.
o Read just that pixel with RasterIO().
eg.
double dfElev;
poDS->GetRasterBand(1)->RasterIO( GF_Read, pixel_x, pixel_y, 1, 1,
&dfElev, 1, 1, GDT_Float64 );
or something like that.
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 | Geospatial Programmer for Rent
More information about the Gdal-dev
mailing list