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

osm-public-transport-export

v1.0.1

Published

OSM Public Transport Export

Downloads

5

Readme

OSM Public Transport Downloader

Node.js library to download public transport data from OpenStreetMaps using Overpass and output it into an extended GeoJSON file.

Motivation

This project is part of a set of tools to provide travel data in countries where public transport works on demand and neither bus stops nor timetables exist. Check out https://github.com/trufi-app to see more of our work.

Why GeoJSON

GeoJSON is a great format to encode geographical data and has a big ecosystem with lots of great tools. GitHub for instance has built-in support for visualizing the contents of a .geojson file. And in essence that is exactly what data from OSM is: Geographical data that was annotated with public transport information. GeoJSON was not made to store all of this information though. That's why we extended standard GeoJSON and output complementary data where it makes sense. The exported data can then be converted into a public transport format of choice in a second step. Use geojson-to-gtfs to convert it into Google's de facto standard for public transit feeds.

Usage

// Cochabamba, Bolivia
const bounds = {
    south: -17.57727,  // minimum latitude
    west:  -66.376555, // minimum longitude
    north: -17.276198, // maximum latitude
    east:  -65.96397,  // maximum longitude
};

// Work with returned data
osmToGeojson({ bounds }).then(data => {
    data.geojson // GeoJSON FeatureCollection
    data.stops   // Dictionary that maps OSM node IDs to stop names
    data.log     // Log messages as string
});

// Write data to file system
osmToGeojson({
    bounds,
    outputDir: __dirname + '/out'
}).then(() => {
    // routes.geojson, stops.json, log.txt
});

Examples

The example scripts can be run to export routes data for several city and feature some localization options. There are shortcuts to start the export:

| City | Command | | ---- | ------- | | All cities | npm start | | Cochabamba | npm run bolivia:cochabamba | | La Paz | npm run bolivia:lapaz | | Santa Cruz | npm run bolivia:santacruz | | Accra | npm run ghana:accra |

The GeoJSON file will be written to examples/out/<city>/routes.geojson. You can visualize the data with several tools such as geojson.io.

example

Note: Sometimes the server can reject with too many requests. That's why we recommend to run them one by one.

Options

  • bounds (object, default null) — Defines the OSM bounding box to pull public transport data from. Expects keys south, west, north, east with number type values.
  • outputDir (string, default null) — When set, writes geojson data, stops and logs into files at the provided location.
  • assumeFirstWayIsStart (bool, default false) — When true, assumes that ways that build a street are in order and the first way is the start of the route.
  • geojsonFilename (string, default: 'routes.geojson') — Filename for GeoJSON route data when outputDir is given.
  • logFilename (string, default: 'log.txt') — Filename for error log when outputDir is given.
  • stopsFilename (string default: 'stops.json') — Filename for stops data when outputDir is given.
  • stopNameSeparator (string, default: ' and ') — Separator that is used when concatenating street names.
  • stopNameFallback (string, default: 'Unnamed Street') — When no street names can be used for a stop, this name is used instead.
  • formatStopName (function, default: join with stopNameSeparator, use stopNameFallback if empty) — Map names of OSM ways into a stop label
  • mapProperties (function, default: pass through OSM relation tags) — Maps OSM relation tags into GeoJSON Feature properties.

Stops data

For each node that is used in one or more routes, a stop name is generated by concatenating the names of all streets together that run through it. Use the stopName* settings to change the strings used in the default behaviour. If you need more control, override the formatStopName function. The options will be available using this.

Error log

The returned log data contains queries that lead to route errors. You can use overpass-turbo to run the query and inspect the issue.