Creates OpenStreetMap suitable contour lines from NASA SRTM data
Project description
pyhgtmap is a fork of the original tool,
which doesn't seem to be maintained anymore.
This is a little program which lets you easily generate OSM contour lines from NASA SRTM data. It was initially created as replacement for srtm2osm which stopped working when the NASA changed the server and started distributing the raw SRTM data via http instead of ftp. In the meanwhile, srtm2osm is working again due to the efforts of bomm.
However, pyhgtmap has some advantages compared to srtm2osm. One is that you won't need a C# runtime environment installed on your machine. Another important thing is that pyhgtmap generates already tiled data. Furthermore, pyhgtmap seems to slightly outperform srtm2osm. If you are using a multi-core machine and are running a POSIX compliant operating system you can use a very simple form of parallelization and the advance will be dramatical.
Note that the intended use is not to upload generated contour OSM data to the OSM servers but to use it for fancy maps.
Sources
pyhgtmap supports several HGT data sources. Those are identified by a 4-character "nickname" + one digit resolution suffix, which can be specified with the --sources parameter of pyhgtmap.
SRTM
NASA Shuttle Radar Topography Mission v3.0
Available for 1" and 3" resolutions.
This source requires TIFF support.
This source requires creating an earthexplorer account on https://ers.cr.usgs.gov/register/.
VIEW
VIEWFINDER PANORAMAS DIGITAL ELEVATION DATA
Available for 1" and 3" resolutions.
SONN
Sonny's LiDAR Digital Terrain Models (DTM) of European countries
Available for 1" and 3" resolutions.
This source require usage of Google Drive API. To use it, you have to generate API client OAuth secret as described in Google drive's documentation and save the client secrets JSON file in pyhgtmap config directory (~/.pyhgtmap/client-secret.json).
ALOS
ALOS Global Digital Surface Model "ALOS World 3D - 30m (AW3D30)"
Available for 1" resolution only.
This source requires TIFF support.
This source requires creating an AW3D30 account on https://www.eorc.jaxa.jp/ALOS/en/dataset/aw3d30/registration.htm.
Installation
For ubuntu-like system:
Ligther deployment (without GeoTiff support)
GDAL dependency is required only to add GeoTiff support, and is quite painful to install. If you don't need GeoTiff support, simply install the default version of pyhgtmap:
sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 -m venv my_venv
# Switch to venv
. ./my_venv/bin/activate
# Install pyhgtmap with dependencies from PyPi
pip install pyhgtmap
With GeoTiff optional support
sudo apt update
sudo apt install python3 python3-pip python3-venv
# Install GDAL via system package, as it's painful to install through PIP
sudo apt install python3-gdal
# Create virtual env (allow --system-site-packages to use system's GDAL)
python3 -m venv --system-site-packages my_venv
# Switch to venv
. ./my_venv/bin/activate
# Install pyhgtmap with dependencies from PyPi
pip install pyhgtmap[geotiff]
Install directly from GitHub (useful to test non-released fixes)
sudo apt update
sudo apt install python3 python3-pip python3-venv git
python3 -m venv my_venv
# Switch to venv
. ./my_venv/bin/activate
# Install latest pyhgtmap development version from github
pip install -U git+https://github.com/agrenott/pyhgtmap.git
Usage
For a detailed help, run pyhgtmap --help on the console.
Configuration
Thanks to ConfigArgParse module, all command line options can also be passed by environment variable or stored in a config file (~/.pyhgtmap/config.yaml). This is especially useful for credentials to access some sources.
Example:
alos-user: myuser
alos-password: mypassword
srtm-user: someotheruser
srtm-password: someotherpassword
If a value is specified in more than one way then: command line > environment variables > config file values > defaults.
Example output
Generating contours for France PACA region with a 10m step and 0.00001 RDP Epsilon (taking less than a minute on Intel 13600K via Windows WSL 1):
> pyhgtmap --polygon=provence-alpes-cote-d-azur/provence-alpes-cote-d-azur.poly --step=10 --pbf --hgtdir=work/hgt --sources=view1,view3 --simplifyContoursEpsilon=0.00001 -j16
...
> du -shc lon*.pbf |tail -3
196K lon7.00_7.75lat44.69_44.75_view1.osm.pbf
168K lon7.00_7.75lat44.75_44.88_view1.osm.pbf
81M total
> ls -l lon*.pbf |wc -l
104
Contour lines displayed over OSM map using QGis:
A word on contour simplification
pyhgtmap now uses very efficient pybind11-rdp Ramer-Douglas-Peucker Algorithm library for contour simplification. This makes RDP activation the best solution in most cases, as the slight overhead in computing performance is compensated by the reduced number of points to write (which is now the most time consuming part). It also reduces the final file size.
Epsilon value must be chosen with care to get the proper tradeoff between efficiency and quality.
Here is an example originating from a "view1" source with 10m step (lon6.00_7.00lat43.00_43.25_view1.osm.pbf):
| RDP Epsilon values | Disabled | 0 | 0.00001 | 0.0001 |
|---|---|---|---|---|
| Visual details | ||||
| Blue lines (Epsilon=0.00001) are almost indistinguishable from red ones (Epsilon=0) | Clear difference appears for green lines (Epsilon = 0.0001) | |||
| File size (1 tile, PBF format, KiB) | 1840 | 1717 | 1424 | 716 |
| Number of nodes (1 tile) | 869685 | 761085 | 559678 | 210744 |
Development
This project uses .
(Mini)Conda can be used to easily setup given version of Python and GDAL:
conda create -n python39 -c conda-forge python=3.9 gdal hatch
conda activate python39
hatch -e geotiff shell
# To start VSCode using the proper python env
code .
The one-liner for formatting and local validation:
hatch run +py=3.14 fmt && hatch run all
Run test for a given python version:
hatch run +py=3.14 test:test
Profiling
pip install yappi
python -m yappi -f callgrind -o yappi_ex1.out ../../pyhgtmap/main.py --pbf --log=DEBUG N43E006.hgt
Then open yappi_ex1.out with some callgrind viewer (eg. QCacheGrind).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhgtmap-4.0.tar.gz.
File metadata
- Download URL: pyhgtmap-4.0.tar.gz
- Upload date:
- Size: 55.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.2 cpython/3.14.0 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be25066c07dd07d08a9d612f9b037167c1cc8691dccbde76060e6640c0b788f4
|
|
| MD5 |
8da2eefd27d3293044de35c1460159ad
|
|
| BLAKE2b-256 |
31d820a9a242e16826f1db0009ac28a041dea2f6e8da922bcf67cd4faf624646
|
File details
Details for the file pyhgtmap-4.0-py3-none-any.whl.
File metadata
- Download URL: pyhgtmap-4.0-py3-none-any.whl
- Upload date:
- Size: 68.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.2 cpython/3.14.0 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02528f779a8aac239ebdaed612a8b9f80b598ad6529d7757f9b088999478181f
|
|
| MD5 |
3ab2f83341a69edf14d93a257ac4b72a
|
|
| BLAKE2b-256 |
2473fb9c5ba90c8778951a9cf3dd7de73ffbc8e442ede704a8a705c07f8a4aa9
|