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-transit-lines

v0.2.0

Published

Fetch public transit lines from OpenStreetMap for a given area (bounding box).

Downloads

18

Readme

osm-transit-lines

Fetch public transit lines from OpenStreetMap for a given area (bounding box).

npm version Build Status Greenkeeper badge dependency status license chat on gitter

Installation

npm install osm-transit-lines

Usage

const osmTransitLines = require('osm-transit-lines')

// bounding box for Berlin (🇪🇺)
const boundingBox = {
	south: 52.3418234221,
	west: 13.0882097323,
	north: 52.6697240587,
	east: 13.7606105539
}

const options = {
	logging: false, // logs current request count to stderr when enabled
	wikidata: false // fetch claims for lines (not routes) that have a wikidata attribute into line.wikidataClaims
}

osmTransitLines(bbox, { wikidata: true }) // returns a Promise
	.then(console.log)
	.catch(console.error)

Note that - depending on your bounding box - the request might take quite long, even some minutes. You should save/cache the result of this query for some time and refresh the data after some interval you deep appropriate (depending on how fast people might change line information on OSM 😜). Also, the request body is handled in-memory at the time, so the process might get killed if you query a giant bounding box and don't have enough memory.

The method returns a Promise that will resolve in a list of lines (that match route_master relations in OSM) which in turn contain a list of routes (corresponding to normal route relations in OSM) which in turn contain stopLocations, a list of coordinates representing the route's stops. All attributes except for id, type, stopLocations and routes are copied from OSM.

Note that this module additionally alters the data to enhance quality in the following ways:

  • Creates an additional attribute transitMode which contains the route_master or route mode from OpenStreetMap (they represent the same data type but have different attribute names depending on if they're part of a route or a route_master)
  • Creates additional lines from route relations that don't have a route_master parent relation and inserts the same route as the only entry in that line's routes attribute.
  • Harmonizes the some attributes (network, wikidata, colour, operator, ref, transitMode) between lines and routes in the following ways:
    • Do all routes/line contain the same value or null for this attribute? -> Copy the value to all routes/line (effectively adding information for those that had null before)
    • Do all routes contain the same value or null, but the line has a different value? -> Copy the value to all routes (effectively adding information for those that had null before) and overwrite the current value in the line.

Example output for Berlin:

{
	"colour": "#055A99",
	"id": 58424,
	"interval": "5",
	"name": "U-Bahnlinie U8",
	"network": "Verkehrsverbund Berlin-Brandenburg",
	"network:metro": "u-bahn",
	"operator": "Berliner Verkehrsbetriebe",
	"public_transport:version": "2",
	"ref": "U8",
	"route_master": "subway",
	"routes": [
		{
			"colour": "#055A99",
			"from": "S+U Hermannstraße",
			"id": 2679013,
			"interval": "5",
			"name": "U-Bahnlinie U8: S+U Hermannstraße => S+U Wittenau",
			"network": "Verkehrsverbund Berlin-Brandenburg",
			"network:metro": "u-bahn",
			"operator": "Berliner Verkehrsbetriebe",
			"public_transport:version": "2",
			"ref": "U8",
			"route": "subway",
			"stopLocations": [
				{
					"id": 4655299661,
					"latitude": 52.467777,
					"longitude": 13.4312136,
					"type": "location"
				},
				{
					"id": 29494306,
					"latitude": 52.4729946,
					"longitude": 13.4284168,
					"type": "location"
				}
				// …
			],
			"to": "S+U Wittenau",
			"transitMode": "subway",
			"type": "route"
		},
		{
			"colour": "#055A99",
			"from": "S+U Wittenau",
			"id": 2679014,
			"interval": "5",
			"name": "U-Bahnlinie U8: S+U Wittenau => S+U Hermannstraße",
			"network": "Verkehrsverbund Berlin-Brandenburg",
			"network:metro": "u-bahn",
			"operator": "Berliner Verkehrsbetriebe",
			"public_transport:version": "2",
			"ref": "U8",
			"route": "subway",
			"stopLocations": [
				{
					"id": 4655218849,
					"latitude": 52.5879234,
					"longitude": 13.3258231,
					"type": "location"
				},
				{
					"id": 4655264250,
					"latitude": 52.5784067,
					"longitude": 13.3334638,
					"type": "location"
				}
				// …
			],
			"to": "S+U Hermannstraße",
			"transitMode": "subway",
			"type": "route",
			"wikidata": "Q99729"
		}
	],
	"transitMode": "subway",
	"type": "line",
	"wikidata": "Q99729",
	"wikidataClaims": {
		"P154": ["Berlin U8.svg"],
		"P373": ["U-Bahnlinie U8 (Berlin)"],
		"P465": ["00609E"] // line color
		// …
	},
	"wikipedia": "de:U-Bahn-Linie 8 (Berlin)"
}

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.