npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

extract-gtfs-pathways

v2.0.2

Published

Command-line tool to extract pathways from a GTFS dataset.

Downloads

19

Readme

extract-gtfs-pathways

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

with Docker

You can use the docker.io/derhuerst/extract-gtfs-pathways Docker image.

Remember to mount (using -v) the directory you're passing as <output-directory> (see above), otherwise the file will be created within the Docker container's virtual file system (and removed after the extraction has finished).

unzip -j gtfs.zip -d gtfs # directory with GTFS input
mkdir extracted-pathways # output directory
docker run -it --rm \
    -v $PWD/gtfs:/gtfs \
    -v $PWD/extracted-pathways:/extracted-pathways
    docker.io/derhuerst/extract-gtfs-pathways /gtfs/pathways.txt /gtfs/stops.txt /extracted-pathways

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.