<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marcel Radischat on Medium]]></title>
        <description><![CDATA[Stories by Marcel Radischat on Medium]]></description>
        <link>https://medium.com/@quiqua?source=rss-dbbaa828bb4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Marcel Radischat on Medium</title>
            <link>https://medium.com/@quiqua?source=rss-dbbaa828bb4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:36:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@quiqua/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Tutorial: Routing with OSRM and Node.js]]></title>
            <link>https://medium.com/tech-blog-door2door/tutorial-routing-with-osrm-and-node-js-646060489b4c?source=rss-dbbaa828bb4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/646060489b4c</guid>
            <category><![CDATA[project-osrm]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Marcel Radischat]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 08:12:50 GMT</pubDate>
            <atom:updated>2018-04-04T08:12:50.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*kPGCkN2K6QkX_F07WnszHw.png" /></figure><p>Routing applications and services provided by <a href="https://google.com/">Google</a>, <a href="https://here.com/">HERE</a>, <a href="https://www.mapbox.com/">Mapbox</a> or <a href="https://www.graphhopper.com/">GraphHopper</a> and others provide useful information to guide you from any location to your destination.</p><p>The APIs and data they provide can be useful to create new applications for specific use-cases, but depending on wether you are just building an application for yourself or as a business, those services may become quite costly.</p><p>As one alternative you can also build your application by making use of open-source software, e.g. <a href="https://github.com/Project-OSRM/osrm-backend">Project-OSRM</a> and <a href="https://github.com/graphhopper/graphhopper">GraphHopper’s routing engine</a>.</p><p>This tutorial will guide you to set up your own production-ready instance of Project-OSRM with <em>Node.js </em>and<em> Docker</em>.</p><p><em>Note: Some commands used in this tutorial are specific to macOS and may not work with Linux or Windows.</em></p><h3>Local setup of your machine.</h3><p><em>Note: I’d recommend to use </em><em>homebrew to install missing libraries and applications to your Mac.</em></p><p>The only real dependencies we have right now will be <em>Docker</em> and <em>Git</em> as all the other parts are or will be containerised. Those components can be installed via your terminal:</p><pre>$ brew cask docker install<br>$ brew install git</pre><p>After the installation of Docker is complete, start the Docker Application and check that the daemon is running:</p><pre>$ open /Applications/Docker.app<br>$ docker version</pre><p>The result should be similar to this:</p><pre>➔ docker version<br>Client:<br> Version: 18.03.0-ce-rc1<br> API version: 1.37<br> Go version: go1.9.4<br> Git commit: c160c73<br> Built: Thu Feb 22 02:34:03 2018<br> OS/Arch: darwin/amd64<br> Experimental: false<br> Orchestrator: swarm</pre><pre>Server:<br> Engine:<br>  Version: 18.03.0-ce-rc1<br>  API version: 1.37 (minimum version 1.12)<br>  Go version: go1.9.4<br>  Git commit: c160c73<br>  Built: Thu Feb 22 02:42:37 2018<br>  OS/Arch: linux/amd64<br>  Experimental: true</pre><p>The last preparation for now would be to create a new directory for the new application:</p><pre>$ mkdir -p ~/sandbox/express-osrm<br>$ cd ~/sandbox/express-osrm</pre><h3>Let’s continue with data.</h3><p>OSRM can create a routable graph with different input data. One way to feed OSRM with data is making use of <a href="https://www.openstreetmap.org/">OpenStreetMap</a>.</p><blockquote>OpenStreetMap is built by a community of mappers that contribute and maintain data about roads, trails, cafés, railway stations, and much more, all over the world.</blockquote><p>The data itself can be downloaded from various sources:</p><ul><li>OSM Export: <a href="https://www.openstreetmap.org/export">https://www.openstreetmap.org/export</a></li><li>Geofabrik Downloads (Regularly-updated extracts of continents, countries, and selected cities): <a href="http://download.geofabrik.de/">http://download.geofabrik.de/</a></li><li>Planet OSM (Regularly-updated copies of the complete OpenStreetMap database): <a href="http://planet.openstreetmap.org/">http://planet.openstreetmap.org/</a></li><li>Other sources: <a href="http://wiki.openstreetmap.org/wiki/Download">http://wiki.openstreetmap.org/wiki/Download</a></li></ul><p>The OSM Export option is simple and easy: just select an area from the map and all data in this rectangle will be exported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddsLp1usHLylNO4eCyVz7A.png" /><figcaption>Export OSM data via <a href="https://www.openstreetmap.org/export">https://www.openstreetmap.org/export</a></figcaption></figure><p>Yet if you need data on a larger scale, I’d recommend to make use of the service provided by Geofabrik . It allows to download a dataset of a specific region in various formats:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kOYIo9SJ3gvWqjavJRirnQ.png" /><figcaption>Export OSM data via <a href="http://download.geofabrik.de/europe/germany.html">http://download.geofabrik.de/europe/germany.html</a></figcaption></figure><h4>Missing your favourite area? No Problem!</h4><p>It can happen that any of the sources listed above won’t provide you with the exact data you need for your application and some adjustments are required.</p><p>If you are in need for your application to provide routing information for Berlin and London only, you will have to download the OSM dataset for Europe from Geofabrik:</p><pre>~/sandbox/express-osrm<br>$ curl --create-dirs --output data/europe-latest.osm.pbf http://download.geofabrik.de/europe-latest.osm.pbf</pre><p>After the download completed, we want to clip the original data. The tool of choice for this task is osmium-tool</p><blockquote>A multipurpose command line tool based on the Osmium Library [to manipulate OSM data].</blockquote><p>We will install osmium-tool via a newly created docker container.</p><pre>~/sandbox/express-osrm<br>$ touch Dockerfile.osmium-tool</pre><p>Open the docker file, paste the instructions and save it:</p><pre>FROM alpine:3.7<br><br>RUN echo &quot;http://dl-cdn.alpinelinux.org/alpine/edge/testing&quot; &gt;&gt; /etc/apk/repositories<br><br>WORKDIR /usr/src/apps<br><br>RUN apk add --no-cache \<br>        boost-dev \<br>        bzip2-dev \<br>        cmake \<br>        expat-dev \<br>        g++ \<br>        gdal-dev \<br>        geos-dev \<br>        git \<br>        make \<br>        proj4-dev \<br>        sparsehash \<br>        zlib-dev &amp;&amp; \<br>    git clone https://github.com/mapbox/protozero.git &amp;&amp; \<br>        cd protozero &amp;&amp; \<br>        mkdir build &amp;&amp; \<br>        cd build &amp;&amp; \<br>        cmake .. &amp;&amp; \<br>        make &amp;&amp; \<br>    cd /usr/src/apps &amp;&amp; \<br>    git clone https://github.com/osmcode/libosmium.git &amp;&amp; \<br>        cd libosmium &amp;&amp; \<br>        mkdir build &amp;&amp; \<br>        cd build &amp;&amp; \<br>        cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_EXAMPLES=OFF .. &amp;&amp; \<br>        make &amp;&amp; \<br>    cd /usr/src/apps &amp;&amp; \<br>    git clone https://github.com/osmcode/osmium-tool &amp;&amp; \<br>        cd osmium-tool &amp;&amp; \<br>        mkdir build &amp;&amp; \<br>        cd build &amp;&amp; \<br>        cmake -DCMAKE_BUILD_TYPE=MinSizeRel .. &amp;&amp; \<br>        make &amp;&amp; \<br>        make install &amp;&amp; \<br>    cd /usr/src/apps &amp;&amp; \<br>    apk del git cmake make<br><br>ENTRYPOINT [&quot;osmium&quot;] </pre><pre>CMD [&quot;--help&quot;]</pre><p>Now we can install osmium-tool as a Docker container via:</p><pre>~/sandbox/express-osrm<br>$ docker build -t osmium-tool -f Dockerfile.osmium-tool .</pre><p>All that is left is to create a my-area.poly file defining the polygons of the areas we want to keep. (<em>Read more about Poly-files </em><a href="http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format"><em>here</em></a><em>.)</em></p><pre>~/sandbox/express-osrm<br>$ touch data/my-area.poly</pre><p>Open the poly file and paste in the following polygon definitions.</p><pre>london<br>1<br>     -0.57403 51.23096<br>      0.36804 51.23096<br>      0.36804 51.71171<br>     -0.57403 51.71171<br>     -0.57403 51.23096<br>END<br>END</pre><pre>berlin<br>1<br>     13.06823 52.32023<br>     13.77960 52.32023<br>     13.77960 52.70967<br>     13.06823 52.70967<br>     13.06823 52.32023<br>END<br>END</pre><p>With our defined areas in place, we can now clip the initial OSM data and trim it down. For this we will link our local directory ~/sandbox/express-osrm/data to /data of theosmium-tool docker container and execute the clipping operation inside of the container:</p><pre>~/sandbox/express-osrm<br>$ docker run -it -v $(pwd)/data:/data osmium-tool extract -p /data/my-area.poly /data/europe-latest.osm.pbf -o /data/my-area.osm.pbf</pre><p>The clipped file is now available at ~/sandbox/express-osrm/data/my-area.osm.pbf .</p><h3>Create a routable graph</h3><p>Once you have your favourite OSM data locally available, we can create a routable graph via OSRM.</p><p>The first step is to pull an image of the latest OSRM version via docker:</p><pre>$ docker pull osrm/osrm-backend:v5.16.1</pre><p>Afterwards we can pass our OSM file (~/sandbox/express-osrm/data/my-area.osm.pbf) to the OSRM container to create a routable graph with a given profile (car, foot, bike, …) with the contraction hierarchies algorithm:</p><pre># extract the network and create the osrm file(s)<br>docker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.16.1 osrm-extract -p /opt/car.lua /data/my-area.osm.pbf<br><br># create the graph<br>docker run -it -v $(pwd)/data:/data osrm/osrm-backend:v5.16.1 osrm-contract /data/osrm/my-area.osrm</pre><p>The dataset is now available at ~/sandbox/express-osrm/data/my-area.osrm and can be used by any OSRM instance running the same version as this dataset was generated with.</p><h3>Create a Node.js application to serve OSRM functionality</h3><p>We have now the required osrm-dataset available and can use this in combination with using OSRM via Node.js bindings to provide a powerful routing application.</p><p>An example application can be found at <a href="https://github.com/door2door-io/osrm-express-server-demo">https://github.com/door2door-io/osrm-express-server-demo</a>.</p><p>The application will launch an <a href="https://expressjs.com/">Express-Server</a> via a Docker container and make use of the recently generated osrm-dataset.</p><ul><li>Clone the application:</li></ul><pre>~/sandbox/express-osrm<br>$ git clone <a href="https://github.com/door2door-io/osrm-express-server-demo.git">https://github.com/door2door-io/osrm-express-server-demo.git</a></pre><ul><li>Copy the dataset into the application folder:</li></ul><pre>~/sandbox/express-osrm<br>$ cp data/osrm/ osrm-express-server-demo/data/osrm/example-areas/</pre><ul><li>Build the application container:</li></ul><pre>~/sandbox/express-osrm<br>$ cd osrm-express-server-demo<br>$ docker build -t osrm-express-server -f Dockerfile.nodejs .</pre><ul><li>Modify the environment variables for the container. It is important to mention that you will modify the environment variables of the container. So if you are linking your dataset from your host to the container, be aware that the path for `OSRM_GRAPH` should be valid inside the container:</li></ul><pre>~/sandbox/express-osrm/osrm-express-server-demo<br>$ cp .env.example .env</pre><pre># edit the contents with your favourite editor:<br>$ vi .env </pre><h3>Start the application</h3><p>In order to launch the application with the specified dataset (see above), run the container with the required environment variables, port mapping and volume bindings:</p><pre>docker run --env-file .env -d -p 5000:5000 -v $(pwd)/data:/data osrm-express-server</pre><p>Also please make sure to map the correct volumes (host and container) as well as the ports in order to access the server.</p><p>After the application has loaded the graph in memory, you can make requests to the server running at <a href="http://localhost:5000/">http://localhost:5000/</a></p><h4>API-Endpoints</h4><p>This example application has 3 different endpoints</p><ul><li>GET /health: A simple ping endpoint to check that the server is running.</li><li>POST /route: Implements calls to osrm.route to calculate the way from A to B.<br><em>Example body</em>:{ coordinates: [[13.3905, 52.5205], [13.3906, 52.5206]] }</li><li>POST /table: Implements calls to osrm.table to get a travel times matrix for all provided locations.<br><em>Example body</em>:{ coordinates: [[13.3905, 52.5205], [13.3906, 52.5206]] }</li></ul><p>The source code should be simple enough to provide an overview and to get started for further extensions and your own development.</p><h3>Conclusion</h3><p>With this introduction you should be able to setup your own containerised routing application and the necessary steps to ingest data.</p><p>You could now explore the different <a href="https://github.com/Project-OSRM/osrm-backend/blob/master/docs/nodejs/api.md">services provided by OSRM</a> and also expose them in your application, experiment with different datasets and add <a href="https://github.com/Project-OSRM/osrm-backend/tree/master/profiles">different routing profiles</a>.</p><p>Happy routing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=646060489b4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-blog-door2door/tutorial-routing-with-osrm-and-node-js-646060489b4c">Tutorial: Routing with OSRM and Node.js</a> was originally published in <a href="https://medium.com/tech-blog-door2door">door2door Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>