|
1 |
| -====== |
| 1 | +=========== |
2 | 2 | GTFSDB
|
3 |
| -====== |
| 3 | +=========== |
| 4 | + |
4 | 5 |
|
5 | 6 | .. image:: https://badges.gitter.im/Join%20Chat.svg
|
6 | 7 | :alt: Join the chat at https://gitter.im/OpenTransitTools/gtfsdb
|
7 | 8 | :target: https://gitter.im/OpenTransitTools/gtfsdb?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
8 | 9 |
|
9 | 10 |
|
10 | 11 | Supported Databases
|
11 |
| -=================== |
| 12 | +******************* |
12 | 13 |
|
13 |
| -- PostgreSQL (PostGIS for Geo tables) - preferred |
14 |
| -- Oracle - tested |
15 |
| -- MySQL - tested |
16 |
| -- SQLite - tested |
| 14 | +* PostgreSQL (PostGIS for Geo tables) - preferred |
| 15 | +* Oracle - tested |
| 16 | +* MySQL - tested |
| 17 | +* SQLite - tested |
17 | 18 |
|
18 | 19 |
|
19 | 20 | GTFS (General Transit Feed Specification) Database
|
20 |
| -================================================== |
| 21 | +************************************************** |
21 | 22 |
|
22 |
| -Python code that will load GTFS data into a relational database, and SQLAlchemy ORM bindings to the GTFS tables in the gtfsdb. |
23 |
| -The gtfsdb project's focus is on making GTFS data available in a programmatic context for software developers. The need for the |
24 |
| -gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code |
25 |
| -to read GTFS data (whether that's an in-memory loader, a database loader, etc...); GTFSDB can hopefully reduce the need for such |
26 |
| -drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format. |
| 23 | +Python code that will load GTFS data into a relational database, and SQLAlchemy ORM bindings to the GTFS tables in the gtfsdb. The gtfsdb project's focus is on making GTFS data available in a programmatic context for software developers. The need for the gtfsdb project comes from the fact that a lot of developers start out a GTFS-related effort by first building some amount of code to read GTFS data (whether that's an in-memory loader, a database loader, etc...); GTFSDB can hopefully reduce the need for such drudgery, and give developers a starting point beyond the first step of dealing with GTFS in .csv file format. |
27 | 24 |
|
28 |
| -(Slightly out-of-date version) available on pypi: https://pypi.python.org/pypi/gtfsdb |
| 25 | +Available on pypi: https://pypi.python.org/pypi/gtfsdb |
29 | 26 |
|
30 | 27 |
|
31 | 28 | Install from source via github (if you want the latest code) :
|
32 |
| -========================================== |
| 29 | +************************************************************** |
| 30 | + |
| 31 | +#. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version) |
| 32 | +#. `pip install zc.buildout` - https://pypi.org/project/zc.buildout |
| 33 | +#. (optinal step for **postgres users**: 'pip install psycopg2-binary') |
| 34 | +#. git clone https://github.com/OpenTransitTools/gtfsdb.git |
| 35 | +#. cd gtfsdb |
| 36 | +#. buildout install prod -- NOTE: if you're using postgres, do a 'buildout install prod postgresql' |
| 37 | +#. bin/gtfsdb-load --database_url <db url> <gtfs file | url> |
| 38 | +#. examples: |
33 | 39 |
|
34 |
| -1. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version) |
| 40 | + * bin/gtfsdb-load --database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip |
35 | 41 |
|
36 |
| -2. `pip install zc.buildout` - https://pypi.org/project/zc.buildout |
| 42 | + * bin/gtfsdb-load --database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip |
37 | 43 |
|
38 |
| -3. (optinal step for **postgres users**: 'pip install psycopg2-binary') |
| 44 | + * bin/gtfsdb-load --database_url postgresql://postgres@localhost:5432 --is_geospatial http://developer.trimet.org/schedule/gtfs.zip |
39 | 45 |
|
40 |
| -4. git clone https://github.com/OpenTransitTools/gtfsdb.git |
| 46 | + .. note:: adding the `is_geospatial` cmdline flag, when paired with a spatial-database ala PostGIS (e.g., is_spatial is meaningless with sqllite), will take longer to load...but will create geometry columns for both rendering and calculating nearest distances, etc... |
41 | 47 |
|
42 |
| -5. cd gtfsdb |
| 48 | +#. view db ( example: https://sqliteonline.com ) |
43 | 49 |
|
44 |
| -6. buildout install prod -- NOTE: if you're using postgres, do a 'buildout install prod postgresql' |
| 50 | +The best way to get gtfsbd up and running is via the 'zc.buildout' tool. Highly recommended to first install |
| 51 | +buildout (e.g., pip install zc.buildout) before doing much of anything else. |
45 | 52 |
|
46 |
| -7. bin/gtfsdb-load --database_url <db url> <gtfs file | url> |
| 53 | +Postgres users, gtfsdb requires the psycopg2-binary database driver. Installing that via `pip install psychopg2-binary` will relieve gtfsdb from re-installing locally as part of the build. And if after the fact, you see *exceptions* mentioning |
47 | 54 |
|
48 |
| - examples: |
| 55 | +.. note:: if you get the message "ImportError: No module named psycopg2", then 'pip install psychopg2-binary' should fix things. (Assumes you have postgres also installed on the machine you're trying to use the pg driver). |
49 | 56 |
|
50 |
| - - bin/gtfsdb-load --database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip |
51 |
| - - bin/gtfsdb-load --database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip |
52 |
| - - bin/gtfsdb-load --database_url postgresql://postgres@localhost:5432 --is_geospatial http://developer.trimet.org/schedule/gtfs.zip |
53 | 57 |
|
54 |
| - NOTE: adding the `is_geospatial` cmdline flag, when paired with a spatial-database ala PostGIS (e.g., is_spatial is meaningless with sqllite), will take longer to load...but will create geometry columns for both rendering and calculating nearest distances, etc... |
| 58 | +Usage with Docker: |
| 59 | +****************** |
55 | 60 |
|
56 |
| -8. view db ( example: https://sqliteonline.com ) |
| 61 | +#. Build the image with `docker build -t gtfsdb .` |
| 62 | +#. Run it with: |
57 | 63 |
|
58 |
| -The best way to get gtfsbd up and running is via the 'zc.buildout' tool. Highly recommended to first install |
59 |
| -buildout (e.g., pip install zc.buildout) before doing much of anything else. |
| 64 | + .. code-block:: bash |
60 | 65 |
|
61 |
| -Postgres users, gtfsdb requires the psycopg2-binary database driver. Installing that via `pip install psychopg2-binary` |
62 |
| -will relieve gtfsdb from re-installing locally as part of the build. And if after the fact, you see *exceptions* mentioning |
63 |
| -**"ImportError: No module named psycopg2"**, then 'pip install psychopg2-binary' should fix that up quick... |
| 66 | + docker run gtfsdb --database_url <db url> <gtfs file | url> |
64 | 67 |
|
| 68 | + .. note:: The entrypoint command is `bin/gtfsdb-load` so the arguments will be passed to it. |
65 | 69 |
|
66 |
| -Usage with Docker |
67 |
| -================= |
68 | 70 |
|
69 |
| -1. Build the image with :code:`docker build -t gtfsdb .`. |
70 |
| -2. Run it with |
71 |
| - :code:`docker run gtfsdb --database_url <db url> <gtfs file | url>`. |
72 |
| - The entrypoint command is :code:`bin/gtfsdb-load` |
73 |
| - so the arguments will be passed to it. |
| 71 | +Example Queries: |
| 72 | +**************** |
74 | 73 |
|
| 74 | +* get first stop time of each trip for route_id 1 |
75 | 75 |
|
76 |
| -Example Query: |
77 |
| -============== |
| 76 | + .. code-block:: sql |
78 | 77 |
|
79 |
| --- get first stop time of each trip for route_id 1 |
| 78 | + select * |
| 79 | + from trips t, stop_times st |
| 80 | + where t.route_id = '1' |
| 81 | + and t.trip_id = st.trip_id |
| 82 | + and st.stop_sequence = 1 |
80 | 83 |
|
81 |
| -select * |
82 |
| -from trips t, stop_times st |
83 |
| -where t.route_id = '1' |
84 |
| -and t.trip_id = st.trip_id |
85 |
| -and st.stop_sequence = 1 |
| 84 | +* get agency name and number of routes |
86 | 85 |
|
87 |
| --- get agency name and number of routes |
| 86 | + .. code-block:: sql |
88 | 87 |
|
89 |
| -select a.agency_name, a.agency_id, count(r.route_id) |
90 |
| -from routes r, agency a |
91 |
| -where r.agency_id = a.agency_id |
92 |
| -group by a.agency_id, a.agency_name |
93 |
| -order by 3 desc |
| 88 | + select a.agency_name, a.agency_id, count(r.route_id) |
| 89 | + from routes r, agency a |
| 90 | + where r.agency_id = a.agency_id |
| 91 | + group by a.agency_id, a.agency_name |
| 92 | + order by 3 desc |
0 commit comments