Skip to main content

Creates OpenStreetMap suitable contour lines from NASA SRTM data

Project description

Python: 3.9, 3.10 GitHub GitHub Workflow Status Code style: black Hatch project linting - Ruff types - Mypy DeepSource Codacy Badge Maintainability

pyhgtmap is a fork of the original phyghtmap 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.

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.

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 --source=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:

PACA 10m contours

PACA 10m contours - zoom in mountains area

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 Comparison between RDP 0 and 0.00001 results Comparison between RDP 0, 0.0001 and 0.00001 results
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 hatch.

The one-liner for formatting and local validation:

hatch run fmt && hatch run all

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhgtmap-3.3.tar.gz (47.3 kB view details)

Uploaded Source

Built Distribution

pyhgtmap-3.3-py2.py3-none-any.whl (54.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyhgtmap-3.3.tar.gz.

File metadata

  • Download URL: pyhgtmap-3.3.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for pyhgtmap-3.3.tar.gz
Algorithm Hash digest
SHA256 a2e8c3bd8f4526b6458f1553869bec4e25800103b2ae6c32fe01fdca3ddfa48a
MD5 3ff61ed471c310c4f71b7296488c2f69
BLAKE2b-256 a43df604380c9c8011c90d6c5fa358942e7f74c9bfd64a3176d80dd1a160e3fd

See more details on using hashes here.

Provenance

File details

Details for the file pyhgtmap-3.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pyhgtmap-3.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 54.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for pyhgtmap-3.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 84ce785a254b57dcbf8d71281b513d99704b1a3ba65ecbcd92aa1430ec64673d
MD5 bfc62f70dbf5ead1ccaa02b2a46ab32c
BLAKE2b-256 0be2faf2ecf35ca881fb432ad2fd55ced32f50edde092ee949bd44a1b8b7abf8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page