-
-
Notifications
You must be signed in to change notification settings - Fork 367
MMPTR Tutorial
- cmake
- postgresql-server
- boost-graph library 1.46
The following commands and instructions should help you install and set up on a fresh Ubuntu system.
sudo apt-get install postgresql
#TODO: Create a user
sudo apt-get install postgis
Refer here for instructions on creating a postgis template database.
If using Ubuntu 11.10, boost 1.46 can be installed from the repository,
sudo apt-get install libboost-graph1.46-dev
Otherwise, download the source and copy the graph library into includes folder
cd /tmp
wget http://sourceforge.net/projects/boost/files/boost/1.46.1/boost_1_46_1.tar.gz
tar -xzvf boost_1_46_1.tar.gz
sudo mkdir -p /usr/local/include/boost
sudo cp -r boost_1_46_1/boost/graph /usr/local/include/boost/
sudo apt-get install gcc g++ cmake
sudo apt-get install postgresql-server-dev-all libpq-dev libcunit1-dev \
libgmp-dev
PGROUTING_PATH=/usr/local/src/pgrouting
cd $PGROUTING_PATH
cmake -DWITH_TRANSIT=1 .
make
sudo make install
- Copy test/settings.sample.py into settings.py
- Edit settings.py with actual database username, password, etc..
- If you don't have a postgis template, refer here
- Invoke
make test
from insidePGROUTING_PATH
DBNAME=transit
createdb $DBNAME -T template_postgis
GTFS data can be easily loaded using gtfs2pgrouting. Please check the project's README file for instructions.
Open a client connection to the transit database(psql transit
) and run the following,
\i /usr/share/pgrouting/routing_core.sql
\i /usr/share/pgrouting/routing_core_wrappers.sql
\i /usr/share/pgrouting/routing_transit.sql
--The following step may take several minutes based on the volume of gtfs data loaded
\i /usr/share/pgrouting/routing_transit_wrappers.sql
SELECT prepare_scheduled('gtfs'); -- where 'gtfs' is the schema name
Now, prepare_scheduled function adds a new column named 'stop_id_int4' to the 'stops' table.
NOTE: The above query may take several minutes to execute and consume 100% CPU during the process.
SELECT s.stop_id, trip_id, waiting_time, travel_time
FROM scheduled_route('gtfs',
(SELECT stop_id_int4 FROM gtfs.stops WHERE stop_id = 'SRC_ID'),
(SELECT stop_id_int4 FROM gtfs.stops WHERE stop_id = 'DEST_ID'),
extract(epoch from timestamp '20-Aug-2011 8:30PM Asia/Kolkata')::INTEGER
) sr,
gtfs.stops s
WHERE sr.stop_id = s.stop_id_int4;
The above query returns a list of stops(changeovers) and the trips to take between them along with the waiting time and travel time (in seconds) for that trip.
The same result can be obtained using a wrapper function:
SELECT stop_id, trip_id, waiting_time, travel_time
FROM gtfs_route('SRC_ID', 'DEST_ID', '20-Aug-2011 8:30PM Asia/Kolkata');