From 0b305e79f829961427147a676d9fdde9398202e5 Mon Sep 17 00:00:00 2001 From: Adrian Date: Fri, 19 Apr 2024 13:59:37 +0200 Subject: [PATCH] docs: Added reference to postgresql-server-dev-all as a dependency --- readme.md | 118 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/readme.md b/readme.md index d1c1250..b661ee0 100644 --- a/readme.md +++ b/readme.md @@ -20,76 +20,82 @@ PGTFS is a PostgreSQL extension designed to facilitate routing on top of the GTF 1. Clone the PGTFS repository: -```sh -git clone https://github.com/adrianprelipcean/pgtfs.git -``` + ```sh + git clone https://github.com/adrianprelipcean/pgtfs.git + ``` -2. Build and install the extension: +2. Install the server development packages (e.g., for Ubuntu): -```sh -cd pgtfs -make && make install -``` + ```sh + apt-get install postgresql-server-dev-all + ``` -3. Enable the extension in your PostgreSQL database: +3. Build and install the extension: -```sql -CREATE EXTENSION pgtfs; -``` + ```sh + cd pgtfs + make && make install + ``` + +4. Enable the extension in your PostgreSQL database: + + ```sql + CREATE EXTENSION pgtfs; + ``` ## Usage 1. Make sure you have imported GTFS data (i used [this GTFS feed](https://www.transit.land/feeds/f-u8-romania~interregionalcalatori~regiotrans~cfrc%C4%83l%C4%83tori~softrans~trans) for this example) in the database you want to test this extension in. At a minimum, you would need data for the following tables. -```sql -CREATE TABLE IF NOT EXISTS stops ( - stop_id TEXT PRIMARY KEY, - stop_name TEXT, - stop_lat DOUBLE PRECISION, - stop_lon DOUBLE PRECISION -); - -CREATE TABLE IF NOT EXISTS trips ( - route_id TEXT, - service_id TEXT, - trip_id TEXT PRIMARY KEY, - trip_short_name TEXT -); - -CREATE TABLE IF NOT EXISTS stop_times ( - trip_id TEXT, - arrival_time INTERVAL, - departure_time INTERVAL, - stop_id TEXT, - stop_sequence INTEGER, - PRIMARY KEY (trip_id, stop_sequence), - FOREIGN KEY (trip_id) REFERENCES trips (trip_id), - FOREIGN KEY (stop_id) REFERENCES stops (stop_id) -); -``` + ```sql + CREATE TABLE IF NOT EXISTS stops ( + stop_id TEXT PRIMARY KEY, + stop_name TEXT, + stop_lat DOUBLE PRECISION, + stop_lon DOUBLE PRECISION + ); + + CREATE TABLE IF NOT EXISTS trips ( + route_id TEXT, + service_id TEXT, + trip_id TEXT PRIMARY KEY, + trip_short_name TEXT + ); + + CREATE TABLE IF NOT EXISTS stop_times ( + trip_id TEXT, + arrival_time INTERVAL, + departure_time INTERVAL, + stop_id TEXT, + stop_sequence INTEGER, + PRIMARY KEY (trip_id, stop_sequence), + FOREIGN KEY (trip_id) REFERENCES trips (trip_id), + FOREIGN KEY (stop_id) REFERENCES stops (stop_id) + ); + ``` 2. Create the PGTFS extension -```sql -CREATE EXTENSION pgtfs; -``` + ```sql + CREATE EXTENSION pgtfs; + ``` 3. Call the Connection Scan Algorithm function for the route between an origin ('10017') and destination ('55770), given a departure time (this day at 12:00:00 AM) and the GTFS trips. -```sql -SELECT *, to_timestamp(arrival_time) FROM pgtfs_csa('10017', '55770', EXTRACT(EPOCH from current_date), -' - SELECT - trip_id, - stop_id, - EXTRACT(EPOCH FROM current_date+arrival_time) AS arrival_time, - EXTRACT(EPOCH FROM current_date+departure_time) AS departure_time, - stop_sequence - FROM stop_times - ORDER BY trip_id, stop_sequence -'); -``` - -> Note: This example is for demonstrative purposes only, dealing with multi-day trips, timezones and non-gtfs routing is not in scope. + ```sql + SELECT *, to_timestamp(arrival_time) FROM pgtfs_csa('10017', '55770', EXTRACT(EPOCH from current_date), + ' + SELECT + trip_id, + stop_id, + EXTRACT(EPOCH FROM current_date+arrival_time) AS arrival_time, + EXTRACT(EPOCH FROM current_date+departure_time) AS departure_time, + stop_sequence + FROM stop_times + ORDER BY trip_id, stop_sequence + '); + ``` + + > Note: This example is for demonstrative purposes only, dealing with multi-day trips, timezones and non-gtfs routing is not in scope. ## Important notes