Skip to main content

General Transit Feed Specification (GTFS) as a Django app

Project description

multigtfs: GTFS as a Django app

https://travis-ci.org/tulsawebdevs/django-multi-gtfs.svg?branch=master

multigtfs is an Apache 2.0-licensed Django app that supports importing and exporting of GTFS feeds. All features of the June 20, 2012 reference are supported, including all changes up to February 17, 2014. It allows multiple feeds to be stored in the database at once.

It requires a spatial databases compatible with GeoDjango. PostgreSQL 9.x and PostGIS 2.x are recommended for development and production, since these support all the GeoDjango features. There are issues with GeoDjango in Django 1.4 (see issue 20036), so Django 1.5 or above is recommended.

Usage

Installation

  1. pip install multigtfs

  2. In your settings, add multigtfs to your INSTALLED APPS and ensure you have a spatial database configured.

  3. ./manage.py syncdb to install the tables, or ./manage.py migrate if you are using South

Management Commands

There are two management commands to get GTFS feeds in and out of the database:

./manage.py importgtfs [--name name_of_feed] path/to/gtfsfeed.zip
./manage.py exportgtfs [--name basename_of_file] <feed_id>

A third command will update cached geometries, used for making geo-queries at the shape, trip, or route level:

./manage.py refreshgeometries --all   # Refresh all geometries
./manage.py refreshgeometries 1 2 3   # Refresh just feeds 1, 2, and 3

Note: cached geometries are normally updated whenever the related shape points or stops are updated. This command is useful for refreshing geometries after manual changes or after a bug fix (like the v0.3.3 update).

In Code

multigtfs is composed of Django models that implement GTFS, plus helper methods for importing and exporting to the GTFS format. Where GTFS relates objects through IDs (such as Stop IDs for stops), multigtfs uses ForeignKeys.

multigtfs includes a Feed object, which is not part of GTFS. This is used to include several feeds in the same file without collisions. These can be feeds from different agencies, or different versions of a feed from the same agency. The object has a helper method, in_feed, that is sometimes useful in filtering objects by feed. At other times, it is easier to start at the feed and follow relations.

There isn’t separate documentation yet. Load the app in your Django project, play with the admin, and read the source code to learn more.

Sample Project

The examples/explore sample project demonstrates a simple read-only website for viewing one or more GTFS feeds. It include OpenLayers maps for viewing the routes, trips, and shapes. You an use it as is, or as a starting place for your own projects. See the project README for more information.

Project History

multigtfs was first developed for the Tulsa Web Devs’ project to get Tulsa’s buses into Google Maps. tulsa-transit-google is the Tulsa-specific portion, and multigtfs contains the parts useful for any GTFS effort. Tulsa’s bus schedule appeared on Google Maps in July 2013, after a two-year effort. The Tulsa Web Devs founded Code for Tulsa to collaborate on future civic tech projects.

Several features, including GeoDjango support and much faster feed imports, were generously sponsored by MRCagney.

Future

Upcoming features include:

  • Validating the feed against Google’s requirements

  • More documentation

See the issues list for more details.

Changelog

0.4.2 (2014-07-20)

  • importgtfs handles feeds with whitespace strings (issue #36)

  • Can update objects with JSON fields in admin (issue #37)

  • importgtfs can import an extracted GTFS feed (issue #30)

  • importgtfs defaults to a Feed name based on the agency name and start of service (issue #33)

0.4.1 (2014-07-11)

  • Import GTFS feeds using BOM (issue #31)

  • Export non-ASCII GTFS feeds in Python 2 (issue #34)

  • Various admin improvements (issue #29, issue #32)

0.4.0 (2014-06-21)

This release was generously sponsored by MRCagney.

  • Import and export are 17-21x faster. Very large feeds (~20MB) can now be imported and exported without running out of memory (4 GB of RAM recommended). When running management commands, increasing verbosity (‘-v 1’ or -v 2’) will print useful status messages.

  • Additional columns not in the current GTFS spec are now imported into ‘extra_data’, a new JSON field. The columns are noted in the Feed’s new JSON field, ‘meta’. These addition items appear in the example project, and are exported after standard columns in the exported feed.

  • Added Python 3 compatibility

  • Extend more fields for real-world data (Trip.short_name, Zone.zone_id, and Block.block_id)

  • On import, if two rows have duplicate unique ID (trip_id, stop_id, etc.), then only the first will be imported. A warning will printed to stderr. Previously, both may have been imported, with unknown consequences.

  • Dropped support for South 0.7.x (not Python 3 compatible)

  • Trips now have a single Service. Extra services will be detected by migration 0018, and will have to be manually removed.

0.3.3 (2014-03-28)

  • Add new optional fields (issue #23):
    • trip.wheelchair_accessible

    • trip.bikes_allowed

    • stop.wheelchair_boarding

  • Route.geometry does not include duplicate Trip.geometry lines (issue #24)

  • Fix order of points in Shape.geometry (issue #25)

  • Add management command ‘refreshgeometries’ to refresh cached geometries (useful if you were impacted by issues #24 or #25)

0.3.2 (2014-03-16)

This release was generously sponsored by MRCagney.

  • Fix migration 0007 for PostGIS (issue #22)

0.3.1 (2014-03-12)

This release was generously sponsored by MRCagney.

  • Add example project ‘explore’, which represents a feed as linked pages with OpenLayer maps.

  • Add cached geometry for Routes, Trips, and Shapes.

  • Extend fields for real-world data (FeedInfo.version, Route.short_name).

  • Drop support for Points as geography fields.

0.3.0 (2014-02-01)

This release was generously sponsored by MRCagney.

  • Convert to GeoDjango: Stops and ShapePoints use Points rather than lat/long, admin shows map of points, and new configuration settings to customize.

  • Import south in try/except blocks (so that South really is optional).

  • Django 1.5 or above is now required.

0.2.6 (2013-06-07)

  • Remove verify_exists from URLField, so it can be used in Django 1.5

0.2.5 (2013-02-13)

  • Human-friendly sorting for rest of GTFS output

0.2.4 (2013-02-06)

  • Added optional manual sorting of output, used on stop_times.txt

0.2.3 (2012-11-09)

  • Added South migrations for applying 0.2.2 changes

0.2.2 (2012-11-09)

  • Fixed Fare.transfers for unlimited rides (use None instead of -1)

  • First PyPi version

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multigtfs-0.4.2.tar.gz (93.2 kB view details)

Uploaded Source

Built Distribution

multigtfs-0.4.2-py2.py3-none-any.whl (136.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file multigtfs-0.4.2.tar.gz.

File metadata

  • Download URL: multigtfs-0.4.2.tar.gz
  • Upload date:
  • Size: 93.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for multigtfs-0.4.2.tar.gz
Algorithm Hash digest
SHA256 55d7f8959458bedbeff4de43d44d4c025c047879c4c11ad9d6a77665405ea6f1
MD5 261947c77c8d66c2d33fd3f9dfa5e0e1
BLAKE2b-256 9e0d3dd3dd4b407c887d03bdc4c9073ad26d94c2a30360b5bf3afad2a7aae0bb

See more details on using hashes here.

File details

Details for the file multigtfs-0.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for multigtfs-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2fdec048326d96f14495aeae6e4d3013c963d31e98ab4dc6c012881dd420df13
MD5 ba9cc8ffd25479de5a7f587e56044fc7
BLAKE2b-256 1bd2dfa9a323643610aa5683af083ffed89ecf598e04e74ad753826e76e5b495

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page