Home

Awesome

extract-gtfs-shapes

Command line tool to extract shapes from a GTFS dataset.

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Installation

npm install -g extract-gtfs-shapes

Usage

Usage:
    extract-gtfs-shapes <path-to-shapes-file> <output-directory>
Options:
    --concurrency    -c  How many files to write in parallel. Default: 32
    --quiet          -q  Don't log stats.
Examples:
    extract-gtfs-shapes -c 50 data/gtfs/shapes.txt shapes
    cat data/gtfs/shapes.txt | extract-gtfs-shapes - shapes
Notes:
    extract-gtfs-shapes needs the GTFS shapes.txt to be sorted by
    1. shape_id, alphanumerically
    2. shape_pt_sequence, numerically
    You can use Miller (https://miller.readthedocs.io/) and the
    Unix tool sponge to do this:
    mlr --csv sort -f shape_id -n shape_pt_sequence \
      shapes.txt | sponge shapes.txt

from JavaScript

Let's build a simple (and slower) clone of the the extract-gtfs-shapes CLI tool documented above:

const {writeFile} = require('fs/promises')
const extractGTFSShapes = require('extract-gtfs-shapes')

const processShape = async (shapeId, shape) => {
    await writeFile(shapeId + 'geo.json', shape)
}
await extractGTFSShapes('path/to/shapes.txt', processShape)

Contributing

If you have a question or need support using extract-gtfs-shapes, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.