This repository is a collection of python scripts for parsing and using SRTM 1 Arc-Second Global (30m) elevation data from USGS/NASA and ALOS World 3D-30m (AW3D30) elevation data from © JAXA .
With gpxsrtm.py
you can update the elevations in GPX tracks.
SRTM (Shuttle Radar Topography Mission) data is a collection of topographic (elevation) data covering nearly 80 percent of Earth's land surfaces. Until September 2014 it was globaly available only in 90-meter resolution (SRTM3), but since then a finer 30-meter resolution (SRTM1) is available for the whole world (JPL Release 2014-321).
Accuracy (90% errors, in meters) | Continent | |||||
---|---|---|---|---|---|---|
Africa | Australia | Eurasia | Islands | N. America | S. America | |
Horizontal | 11.9 | 7.2 | 8.8 | 9.0 | 12.6 | 9.0 |
Absolute Vertical | 5.6 | 6.0 | 6.2 | 8.0 | 9.0 | 6.2 |
Relative Vertical | 9.8 | 4.7 | 8.7 | 6.2 | 7.0 | 5.5 |
Source: SRTM Data Validation and Applications
SRTM 1 Arc-Second Global void filled data (tiles) are available for download via USGS EarthExplorer web site. To download the data you need to register first. The SRTM collections are located under the Digital Elevation category (see picture at the end).
Because of the availability of finer 30-meter resolution data this set of tools doesn't deal with coarser SRTM3 data.
SRTM1 data downloaded via EarthExlorer is available in three file formats:
- Digital Terrain Elevation Data (DTED) (file size approx. 25 MB/tile)
- Band interleaved by line (BIL) (file size approx. 7 MB/tile)
- Georeferenced Tagged Image File Format (GeoTIFF) (file size approx. 25 MB/tile)
The tools in this repository recognize and read all three formats.
Because of different formats and faster processing of actual tasks the
downloaded data must first be converted to internal Python representation
("pickle") with the supplied tool prepare.py
.
Preprocessing of data also takes care of possible voids detected in data (yes, some tiles may still contain voids!) with the built-in interpolation (griddata/linear LNDI) and extrapolation (k-NN/12 neighbours cKDT).
Example of preprocessing a tile with voids:
$ prepare.py s17_w068_1arc_v3.dt2
Reading s17_w068_1arc_v3.dt2
Starting point: 17.0 68.0, size: 3601 x 3601
765385 NaN values, interpolating
Interpolating with griddata
Writing s17_w068_1arc_v3.pickle
ALOS World 3D-30m (AW3D30) elevation data is a free 30-meters resolution dataset obtained by resampling of the 5-meter mesh version of the World 3D Topographic Data, which is considered to be the most precise global-scale elevation data at this time.
Current version (v3.2) released in January 2022 is an improved version with all data voids filled. It's available for download at AW3D30 DSM data map after registration with e-mail confirmation.
ALOS data downloaded via DSM data map is available in GeoTIFF format only (file size approx. 25 MB/tile). The difference from SRTM data is the raster type, which is PixelIsPoint in SRTM data and PixelIsArea in ALOS data:
Because of this the ALOS matrix is 3600 x 3600 and needs to be expanded by one
column and line (right and above) from surrounding tiles to be the same size
as SRTM matrix. This can be done with the supplied tool extpia.py
:
$ extpia.py ALPSMLC30_N046E015_DSM.pickle
Reading ALPSMLC30_N046E015_DSM.pickle
Reading ALPSMLC30_N046E016_DSM.pickle
Reading ALPSMLC30_N047E015_DSM.pickle
Reading ALPSMLC30_N047E016_DSM.pickle
Writing ALPSMLC30_N046E015_EXT.pickle
The resulting ALPSMLC30_N046E015_EXT.pickle
is of size 3601 x 3601 and is
ready to be used for GPX elevation update.
With gpxsrtm.py
you can update the elevations in GPX tracks.
Example:
$ gpxsrtm.py test-s17_w068.gpx
Bounding box: -17 -68 (1 SRTM file)
Reading data/s17_w068_1arc_v3.pickle
Writing test-s17_w068-srtm-bil.gpx
gpxsrtm.py
expects preprocessed SRTM/ALOS data files ("pickles") in
data
subdirectory, but you can also specify the location from command
line (see -h
switch):
$ gpxsrtm.py -h
Usage: gpxsrtm.py [-h] [-s <source>] [-i <interp>] [-d <datadir>] [-p]
<input.gpx> [<input.gpx> ...]
Provides elevation for specified geographic coordinates
positional arguments:
<input.gpx> Input file(s) in GPX format
optional arguments:
-h, --help show this help message and exit
-s <source> Data source: srtm or alos (default: srtm)
-i <interp> Interpolation type: bilinear or idw (default: bilinear)
-d <datadir> SRTM/ALOS data directory (default: <prog>\data)
-p Plot read SRTM/ALOS data (default: False)
This tool uses the following interpolations (selectable) for calculating the elevations between the supplied points from SRTM data files:
- Bilinear interpolation (smoother, default)
- Inverse Distance Weighting (IDW) interpolation
Additional tools for converting "pickles" to JSON format (and vice versa) are
available as pickle2json.py
and json2pickle.py
.
The preprocessed data is a matrix of size 3601 x 3601 with the (0, 0)
coordinates in lower left corner with no void/NaN values. ALOS data values
start with 0.5 offset on coordinate axes.
You can also print the data matrix as tab separated values with
printdata.py
.