Reading National Elevation Dataset (ArcGrid/GridFloat/IMG) with Python only tools?

Working with the IMG file directly in python is straightforward with the GDAL bindings. For example, you can read the data directly into a NumPy array:

from osgeo import gdal
geo = gdal.Open('imgn36w100_11.img')
arr = geo.ReadAsArray()
print repr(arr)
array([[ 744.31896973,  743.68762207,  743.1116333 , ...,  550.42498779,
         553.77813721,  556.18640137],
       [ 744.22955322,  743.66082764,  743.05273438, ...,  552.05706787,
         554.81365967,  557.55877686],
       [ 744.0133667 ,  743.49041748,  743.00061035, ...,  553.0123291 ,
         555.78076172,  558.01312256],
       ...,
       [ 568.70880127,  567.33666992,  566.56170654, ...,  447.68035889,
         447.68804932,  447.65426636],
       [ 568.01116943,  566.95739746,  564.23382568, ...,  447.6696167 ,
         447.71224976,  447.62734985],
       [ 565.62896729,  562.65325928,  560.78759766, ...,  447.67129517,
         447.67529297,  447.65179443]], dtype=float32)

For a more complete example of plotting IMG format data, see this script which generated the image below. For your transformation of GPS data into altitude, you'll have to sample the resulting NumPy array.

enter image description here


The National Map Viewer used to use a different software platform, which made it possible to convert the data to GeoTIFF after selection of tiles. Some regional data provider do prefer GeoTIFF as well. But that may be of no help to you.

However, the good news is that gdal is able to work with all three of these formats. ArcGrid is an ESRI binary format, GridFloat USGS's DEM data format and IMG proprietary to Erdas, who make the Imagine software. I would probably download either the ArcGrid or the IMG format and convert to GeoTIFF: The USGS themselves have a bundle of conversion scripts based on gdal for download (direct link to ZIP file). You should find the resources you need there.