Skip to content

Commit

Permalink
docs: Added reference to postgresql-server-dev-all as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianprelipcean committed Apr 19, 2024
1 parent 375a443 commit 0b305e7
Showing 1 changed file with 62 additions and 56 deletions.
118 changes: 62 additions & 56 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0b305e7

Please sign in to comment.