Open Elevation Api Server Upgrade
date: 2025-02-02
Introduction
A while back I left an open-elevation-api-server running on Debian 10, and I can't remember why.
But I have now worked out how to get it running on Debian 10, Debian 11, and Debian 12 so I want to have what I learned written down here.
What is This?
The api returns an elevation when you query it with gps coordinates.
i.e. you want the elevation at Boring Bowling Alley and Petting Zoo?
curl 'https://elevation.boringonian.com/api/v1/lookup?locations=45.42949,-122.37563'
{"results": [{"latitude": 45.42949, "longitude": -122.37563, "elevation": 157}]}
What changed?
Going from Debian 10 to Debian 11, you have to change how to import gdal and osr.
# gdal_interfaces.py
# import gdal, osr
from osgeo import gdal, osr
...
python3-lazy
is now installable from apt-get
;
no more cowboy-pip3-installs ; all dependencies are now available from apt-get
.
Debian 10 Installation
install dependencies
Here's how I got this working on Debian 10.
apt install python3-bottle python3-gunicorn
apt install gdal-bin python3-gdal
apt install python3-rtree python3-pip
pip3-install lazy
create user and home directory
mkdir /var/lib/elevation
useradd -r -s /sbin/nologin -d /var/lib/elevation elevation
setup your data directory
Follow the instructions
for extracting your 400 *.tif
files and 1 summary.json
to /var/lib/elevation/data/
.
Also place gdal_interfaces.py
and server.py
in
/var/lib/elevation/
in server.py
I comment out the config-parser stuff and just hardcode
the following
# server.py
interface = GDALTileInterface('data/', 'data/summary.json')
interface.create_summary_json()
And of course then at the very bottom of server.py
adjust the
run command for the host and port that you want gunicorn to listen on.
Debian 11 Installation
In upgrading from Debian 10 to Debian 11, change how you import gdal and osr.
# gdal_interfaces.py
# import gdal, osr
from osgeo import gdal, osr
...
/usr/local/lib/python3.7/
and then once again installed lazy
.
rm -rf /usr/local/lib/python3.7/
# installs lazy in /usr/local/lib/python3.9/
pip3-install lazy
Debian 12 Installation
In upgrading from Debian 11 to Debian 12, it is no longer necessary to install lazy with pip.
rm -rf /usr/local/lib/python3.9/
apt install python3-lazy
Run as Systemd Service
This is probably just based on a google search how to run a bottle
server with gunicorn
from systemd
.
# /etc/systemd/system/elevation.service
[Unit]
Description=Bottled Elevation API
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
User=elevation
Group=elevation
WorkingDirectory=/var/lib/elevation
ExecStart=/usr/bin/python3 /var/lib/elevation/server.py
StandardOutput=inherit
StandardError=inherit
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target