Stata command for computing travel time and distance with OpenStreetMap data using the Open Source Routing Machine (OSRM).
As an alternative, if you have to compute many distance, a standalone CLI program may be more appropriate which does not have the http-api's overhead.
In order to make this command work, you have to install OSRM locally. This stata package provides an automatic install script for windows users.
Please download the release archive and unpack it at a location of your choice.
To install the toolchain from the stata CLI, run the following command (of course, replace the path to the location where you unpacked the content of the release archive)
net describe osrmtime, from("/path/to/extracted/files")
and follow the instructions available there.
In some cases (corporate environments with limited permissions), the automatic installation doesn't work. In these cases, it is also possible to copy the required files manually to the corresponding locations:
- The files
osrmtime.ado
,osrprepare.ado
,osrminterface.ado
andosrmtime.sthlp
have to be copied somewhere into the stata searchpath, preferrablyado/plus/o/
(the location of this directory can be requested from the stata CLI using the commandsysdir
). - The archive
osrm_win_v5.14.zip
has to be extracted somewhere in the filesystem. This directory has to be passed later to the toolchain via the optionosrmdir()
. The default location of the automatic installation on Windows isC:\osrm\
.
Of course, OSRM also runs very well on Linux and should also be available on mac-os. Please follow the installation instructions given in the OSRM Wiki. Remark: I tested these ados up to version 5.22 which is the current release version at the time of writing.
Afer copying the ado
files and the sthlp
file into one of stata's sysdir folders (preferrably HOME_DIR/ado/plus/o/
, this command should work.
// download a map of berlin
mkdir mymaps
copy "http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf" "mymaps/berlin.osm.pbf" , replace
// prepare the map (this takes some time ~5 minutes, depending on your system):
osrmprepare , mapfile("mymaps/berlin.osm.pbf") profile(car) osrmdir("/path/to/osrm/")
// open the latitude and longitude data of the restaurants (file available in
// release archvei) and add destination Berlin, Alexanderplatz:
insheet using "restaurants_berlin.csv" , delimiter(";") clear
gen lat_alex = 52.5219184
gen lon_alex = 13.4132147
// calculate travel time and distances:
osrmtime lat lon lat_alex lon_alex , mapfile("mymaps/berlin.osrm") osrmdir("/path/to/osrm/")
In case something doesn't work, please feel free to contact me at christoph[dot]rust[at]ur[dot]de.