2.0.1 • Published 2 years ago

extract-gtfs-pathways v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

extract-gtfs-pathways

Command line tool to extract pathways 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-pathways

Usage

Usage:
    extract-gtfs-pathways <path-to-pathways-file> <path-to-stops-file> <output-directory>
Options:
    --quiet          -q  Don't log the written files.
    --pathway-props -f  A JS function to determine additional pathway properties.
                           Example: pw => ({isWalking: pw.pathway_mode === '1'})
                           Note: The argument will be eval-ed!
    --node-props    -F  A JS function to determine additional node properties.
                           Example: n => ({isFoo: n.stop_id === 'foo'})
                           Note: The argument will be eval-ed!
Examples:
    unzip -j gtfs.zip -d data/gtfs
    mkdir extracted-pathways
    extract-gtfs-pathways data/gtfs/pathways.txt data/gtfs/stops.txt extracted-pathways
Notes:
    This tool will read a reduced form of stops.txt into memory.

    stops.txt needs to be sorted by
    1. parent_station: lexically ascending, empty first
    2. location_type: numerically descending, empty first
    You can use Miller (https://miller.readthedocs.io/) and the
    Unix tool sponge to do this:
    mlr --csv sort -f parent_station -nr location_type \
      stops.txt | sponge stops.txt

pro tip: customize color nodes & pathways

By default, extract-gtfs-pathways adds some style properties to the generated features, following the Mapbox GL JS naming scheme, e.g. line-color, line-width & circle-radius. If you open them with a tool that supports these style properties – e.g. view-geojson, it will be easier to tell the nodes & pathways apart.

You can use --pathway-props/-f and --node-props/-F to customize the pathways' and nodes' properties, respectively. As an example, let's define two functions that override some default properties:

const WALKWAY = '1'
const ESCALATOR = '4'
const pwOpacities = {[WALKWAY]: .3, [ESCALATOR]: 1}
const pathwayProps = (pw) => ({
	'line-opacity': pwOpacities[pw.pathway_mode] || .5,
	'line-width': 2,
})

const STOP = '0' // or empty
const ENTRANCE_EXIT = '2'
const BOARDING_AREA = '4'
const nodeColors = {
    [STOP]: '#ff0000', '': '#ff0000',
    [ENTRANCE_EXIT]: '#00ff00',
    [BOARDING_AREA]: '#0000ff',
}
const nodeProps = (n) => ({
	'circle-color': nodeColors[n.location_type] || '#444444',
})

We minify the functions and declare them as Bash variables:

pw_props='pw => ({"line-opacity": {"1": .3, "4": 1}[pw.pathway_mode] || .5, "line-width": 2})'
node_props='n => ({"circle-color": {"0": "#ff0000", "": "#ff0000", "2": "#00ff00", "4": "#0000ff"}[n.location_type] || "#444444"})'

Then, we can use them:

extract-gtfs-pathways --pathway-props $pw_props --node-props $node_props gtfs/pathways.txt gtfs/stops.txt out

Related

Contributing

If you have a question or need support using extract-gtfs-pathways, 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.