usse/documentation/build/_sources/osm.rst.txt

70 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-02-20 22:38:24 +00:00
################
Open Street Maps
################
Much like Google Maps, ``Openstreetmaps`` is a map that allows you to navigate the world.
The main difference being that OSM is free and can be self hosted.
However there is not a *plug-and-play* solution that will host your own maps.
It turns out that hosting your own maps, including geolocation and calculating distances is quite a big task, especially if you want to suppor the whole world.
OSRM
####
**O**\pen **S**\ource **R**\outing **M**\achine (OSRM) is a project that allows you to calculate distances from a OSM map.
See more about the project `here <https://project-osrm.org/>`_
Setup
-----
Setting OSRM up is straightforward, but it requires you to the same docker container several times. In short the commands for the Netherlands are as follows:
.. code-block:: console
#Download The Netherlands
mkdir -p data/
cd data/
wget https://download.geofabrik.de/europe/netherlands-latest.osm.pbf
cd ../
docker run --name osrm-backend -t -v "${PWD}/data:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/netherlands-latest.osm.pbf
# Process the data
docker run -a osrm-backend -t -v "${PWD}/data:/data" osrm/osrm-backend osrm-contract /data/netherlands-latest.osrm
docker run -t -v "${PWD}/data:/data" osrm/osrm-backend osrm-partition /data/netherlands-latest.osrm
docker run -t -v "${PWD}/data:/data" osrm/osrm-backend osrm-customize /data/netherlands-latest.osrm
# Finaly run the routing engine
docker run -t -i -p 5998:5000 -v "${PWD}/data:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/netherlands-latest.osrm
Now you can use curl to do requests to port ``5998``.
.. note::
When using Google Maps coordinates to send requests to OSRM, make sure that the Longitude and Latitude coordinates are not swapped.
Nominatim
#########
As it turns out, ``OSRM`` is a very good routing engine but it can't do geolocation. To solve this ``Nominatim`` was used to resolve postal codes to coordinates.
.. code-block:: console
$ cat run_nominatim.sh
#! /bin/bash
docker run -it \
-e PBF_PATH=/nominatim/data/netherlands-latest.osm.pbf \
-v "${PWD}/data:/nominatim/data" \
-e REPLICATION_URL=https://download.geofabrik.de/europe/netherlands-updates/ \
-p 5999:8080 \
--name nominatim \
mediagis/nominatim:4.2
This will result in a website that is accessible on port 5999 to which you can send queries.
IP Firewall
###########
Procesing routing data is hard.
In order to prevent bots from misusing these interfaces a firewall rule was added to only allow incomming traffic from specific ip addresses.
.. code-block:: console
$ sudo ufw allow from <ip_addr> to any port 5998
$ sudo ufw allow from <ip_addr> to any port 5999