GithubHelp home page GithubHelp logo

1maxnet1 / gtfsdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from opentransittools/gtfsdb

0.0 0.0 0.0 7.21 MB

GTFS ORM using SQLAlchemy

License: Mozilla Public License 2.0

Python 99.89% Dockerfile 0.11%

gtfsdb's Introduction

GTFSDB

Join the chat at https://gitter.im/OpenTransitTools/gtfsdb

Supported Databases

  • PostgreSQL (PostGIS for Geo tables) - preferred
  • Oracle - tested
  • MySQL - tested
  • SQLite - tested

GTFS (General Transit Feed Specification) Database

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.

Available on pypi: https://pypi.python.org/pypi/gtfsdb

Install from source via github (if you want the latest code) :

  1. Install Python 3.x https://www.python.org/downloads/ (code also runs on 2.7 if you are stuck on that version)

  2. pip install zc.buildout - https://pypi.org/project/zc.buildout

  3. (optinal step for postgres users: 'pip install psycopg2-binary')

  4. git clone https://github.com/OpenTransitTools/gtfsdb.git

  5. cd gtfsdb

  6. buildout install prod -- NOTE: if you're using postgres, do a 'buildout install prod postgresql'

  7. bin/gtfsdb-load --database_url <db url> <gtfs file | url>

  8. examples:

    • bin/gtfsdb-load --database_url sqlite:///gtfs.db gtfsdb/tests/large-sample-feed.zip

    • bin/gtfsdb-load --database_url sqlite:///gtfs.db http://developer.trimet.org/schedule/gtfs.zip

    • bin/gtfsdb-load --database_url postgresql://postgres@localhost:5432 --is_geospatial http://developer.trimet.org/schedule/gtfs.zip

      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...

  9. view db ( example: https://sqliteonline.com )

The best way to get gtfsbd up and running is via the 'zc.buildout' tool. Highly recommended to first install buildout (e.g., pip install zc.buildout) before doing much of anything else.

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

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).

Usage with Docker:

  1. Build the image with docker build -t gtfsdb .
  2. Run it with:
docker run gtfsdb --database_url <db url>  <gtfs file | url>

Note

The entrypoint command is bin/gtfsdb-load so the arguments will be passed to it.

Example Queries:

  • get first stop time of each trip for route_id 1

    select *
    from trips t, stop_times st
    where t.route_id = '1'
    and t.trip_id = st.trip_id
    and st.stop_sequence = 1
  • get agency name and number of routes

    select a.agency_name, a.agency_id, count(r.route_id)
    from routes r, agency a
    where r.agency_id = a.agency_id
    group by a.agency_id, a.agency_name
    order by 3 desc

gtfsdb's People

Contributors

atsu06 avatar bakucity avatar fpurcell avatar kardaj avatar kayjay89 avatar m0wer avatar mgilligan avatar nidusfr avatar tufftuff93 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.