Package: pyhgtmap
pyhgtmap is a fork of the originaltool,
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.Sourcespyhgtmap supports several HGT data sources. Those are identified by a 4-character "nickname" + one digit resolution suffix, which can be specified with the--sourceparameter of pyhgtmap.SRTMNASA Shuttle Radar Topography Mission v3.0Available for 1" and 3" resolutions.This source requires creating an earthexplorer account onhttps://ers.cr.usgs.gov/register/.VIEWVIEWFINDER PANORAMAS DIGITAL ELEVATION DATAAvailable for 1" and 3" resolutions.SONNSonny's LiDAR Digital Terrain Models (DTM) of European countriesAvailable 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 inGoogle drive's documentationand save the client secrets JSON file in pyhgtmap config directory (~/.pyhgtmap/client-secret.json).InstallationFor 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:sudoaptupdate
sudoaptinstallpython3python3-pippython3-venv
python3-mvenvmy_venv# Switch to venv../my_venv/bin/activate# Install pyhgtmap with dependencies from PyPipipinstallpyhgtmapWith GeoTiff optional supportsudoaptupdate
sudoaptinstallpython3python3-pippython3-venv# Install GDAL via system package, as it's painful to install through PIPsudoaptinstallpython3-gdal# Create virtual env (allow --system-site-packages to use system's GDAL)python3-mvenv--system-site-packagesmy_venv# Switch to venv../my_venv/bin/activate# Install pyhgtmap with dependencies from PyPipipinstallpyhgtmap[geotiff]Install directly from GitHub (useful to test non-released fixes)sudoaptupdate
sudoaptinstallpython3python3-pippython3-venvgit
python3-mvenvmy_venv# Switch to venv../my_venv/bin/activate# Install latest pyhgtmap development version from githubpipinstall-Ugit+https://github.com/agrenott/pyhgtmap.gitUsageFor a detailed help, runpyhgtmap --helpon the console.Example outputGenerating contours for FrancePACA regionwith 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
104Contour lines displayed over OSM map using QGis:A word on contour simplificationpyhgtmap now uses very efficientpybind11-rdpRamer-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 valuesDisabled00.000010.0001Visual detailsBlue 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)184017171424716Number of nodes (1 tile)869685761085559678210744DevelopmentThis project uses.(Mini)Conda can be used to easily setup given version of Python and GDAL:condacreate-npython39-cconda-forgepython=3.9
condaactivatepython39
condainstall-cconda-forgegdalhatch
hatch-egeotiffshell# To start VSCode using the proper python envcode.The one-liner for formatting and local validation:hatchrunfmt&&hatchrunallProfilingpipinstallyappi
python-myappi-fcallgrind-oyappi_ex1.out../../pyhgtmap/main.py--pbf--log=DEBUGN43E006.hgtThen openyappi_ex1.outwith some callgrind viewer (eg. QCacheGrind).