{"id":17371952,"url":"https://github.com/juliuste/osm-transit-lines","last_synced_at":"2025-04-08T03:34:45.593Z","repository":{"id":57316545,"uuid":"162327370","full_name":"juliuste/osm-transit-lines","owner":"juliuste","description":"Fetch public transit lines from OpenStreetMap for a given area (bounding box).","archived":false,"fork":false,"pushed_at":"2020-06-02T14:14:28.000Z","size":115,"stargazers_count":5,"open_issues_count":18,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T10:57:08.400Z","etag":null,"topics":["library","openstreetmap","public-transport"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliuste.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-18T18:03:46.000Z","updated_at":"2020-08-10T12:41:59.000Z","dependencies_parsed_at":"2022-08-25T21:11:05.074Z","dependency_job_id":null,"html_url":"https://github.com/juliuste/osm-transit-lines","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fosm-transit-lines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fosm-transit-lines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fosm-transit-lines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliuste%2Fosm-transit-lines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliuste","download_url":"https://codeload.github.com/juliuste/osm-transit-lines/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247772938,"owners_count":20993627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","openstreetmap","public-transport"],"created_at":"2024-10-16T01:15:44.400Z","updated_at":"2025-04-08T03:34:44.671Z","avatar_url":"https://github.com/juliuste.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# osm-transit-lines\n\nFetch public transit lines from OpenStreetMap for a given area (bounding box).\n\n[![npm version](https://img.shields.io/npm/v/osm-transit-lines.svg)](https://www.npmjs.com/package/osm-transit-lines)\n[![Build Status](https://travis-ci.org/juliuste/osm-transit-lines.svg?branch=master)](https://travis-ci.org/juliuste/osm-transit-lines)\n[![Greenkeeper badge](https://badges.greenkeeper.io/juliuste/osm-transit-lines.svg)](https://greenkeeper.io/)\n[![dependency status](https://img.shields.io/david/juliuste/osm-transit-lines.svg)](https://david-dm.org/juliuste/osm-transit-lines)\n[![license](https://img.shields.io/github/license/juliuste/osm-transit-lines.svg?style=flat)](license)\n[![chat on gitter](https://badges.gitter.im/juliuste.svg)](https://gitter.im/juliuste)\n\n## Installation\n\n```bash\nnpm install osm-transit-lines\n```\n\n## Usage\n\n```js\nconst osmTransitLines = require('osm-transit-lines')\n\n// bounding box for Berlin (🇪🇺)\nconst boundingBox = {\n\tsouth: 52.3418234221,\n\twest: 13.0882097323,\n\tnorth: 52.6697240587,\n\teast: 13.7606105539\n}\n\nconst options = {\n\tlogging: false, // logs current request count to stderr when enabled\n\twikidata: false // fetch claims for lines (not routes) that have a wikidata attribute into line.wikidataClaims\n}\n\nosmTransitLines(bbox, { wikidata: true }) // returns a Promise\n\t.then(console.log)\n\t.catch(console.error)\n```\n\nNote 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.\n\nThe method returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.\n\nNote that this module additionally alters the data to enhance quality in the following ways:\n- 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`)\n- 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.\n- Harmonizes the some attributes (`network`, `wikidata`, `colour`, `operator`, `ref`, `transitMode`) between lines and routes in the following ways:\n\t- Do all routes/line contain the same value *or null* for this attribute? -\u003e Copy the value to all routes/line (effectively adding information for those that had `null` before)\n\t- Do all routes contain the same value *or null*, but the line has a different value? -\u003e Copy the value to all routes (effectively adding information for those that had `null` before) *and overwrite the current value in the line*.\n\nExample output for Berlin:\n\n```js\n{\n\t\"colour\": \"#055A99\",\n\t\"id\": 58424,\n\t\"interval\": \"5\",\n\t\"name\": \"U-Bahnlinie U8\",\n\t\"network\": \"Verkehrsverbund Berlin-Brandenburg\",\n\t\"network:metro\": \"u-bahn\",\n\t\"operator\": \"Berliner Verkehrsbetriebe\",\n\t\"public_transport:version\": \"2\",\n\t\"ref\": \"U8\",\n\t\"route_master\": \"subway\",\n\t\"routes\": [\n\t\t{\n\t\t\t\"colour\": \"#055A99\",\n\t\t\t\"from\": \"S+U Hermannstraße\",\n\t\t\t\"id\": 2679013,\n\t\t\t\"interval\": \"5\",\n\t\t\t\"name\": \"U-Bahnlinie U8: S+U Hermannstraße =\u003e S+U Wittenau\",\n\t\t\t\"network\": \"Verkehrsverbund Berlin-Brandenburg\",\n\t\t\t\"network:metro\": \"u-bahn\",\n\t\t\t\"operator\": \"Berliner Verkehrsbetriebe\",\n\t\t\t\"public_transport:version\": \"2\",\n\t\t\t\"ref\": \"U8\",\n\t\t\t\"route\": \"subway\",\n\t\t\t\"stopLocations\": [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 4655299661,\n\t\t\t\t\t\"latitude\": 52.467777,\n\t\t\t\t\t\"longitude\": 13.4312136,\n\t\t\t\t\t\"type\": \"location\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 29494306,\n\t\t\t\t\t\"latitude\": 52.4729946,\n\t\t\t\t\t\"longitude\": 13.4284168,\n\t\t\t\t\t\"type\": \"location\"\n\t\t\t\t}\n\t\t\t\t// …\n\t\t\t],\n\t\t\t\"to\": \"S+U Wittenau\",\n\t\t\t\"transitMode\": \"subway\",\n\t\t\t\"type\": \"route\"\n\t\t},\n\t\t{\n\t\t\t\"colour\": \"#055A99\",\n\t\t\t\"from\": \"S+U Wittenau\",\n\t\t\t\"id\": 2679014,\n\t\t\t\"interval\": \"5\",\n\t\t\t\"name\": \"U-Bahnlinie U8: S+U Wittenau =\u003e S+U Hermannstraße\",\n\t\t\t\"network\": \"Verkehrsverbund Berlin-Brandenburg\",\n\t\t\t\"network:metro\": \"u-bahn\",\n\t\t\t\"operator\": \"Berliner Verkehrsbetriebe\",\n\t\t\t\"public_transport:version\": \"2\",\n\t\t\t\"ref\": \"U8\",\n\t\t\t\"route\": \"subway\",\n\t\t\t\"stopLocations\": [\n\t\t\t\t{\n\t\t\t\t\t\"id\": 4655218849,\n\t\t\t\t\t\"latitude\": 52.5879234,\n\t\t\t\t\t\"longitude\": 13.3258231,\n\t\t\t\t\t\"type\": \"location\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"id\": 4655264250,\n\t\t\t\t\t\"latitude\": 52.5784067,\n\t\t\t\t\t\"longitude\": 13.3334638,\n\t\t\t\t\t\"type\": \"location\"\n\t\t\t\t}\n\t\t\t\t// …\n\t\t\t],\n\t\t\t\"to\": \"S+U Hermannstraße\",\n\t\t\t\"transitMode\": \"subway\",\n\t\t\t\"type\": \"route\",\n\t\t\t\"wikidata\": \"Q99729\"\n\t\t}\n\t],\n\t\"transitMode\": \"subway\",\n\t\"type\": \"line\",\n\t\"wikidata\": \"Q99729\",\n\t\"wikidataClaims\": {\n\t\t\"P154\": [\"Berlin U8.svg\"],\n\t\t\"P373\": [\"U-Bahnlinie U8 (Berlin)\"],\n\t\t\"P465\": [\"00609E\"] // line color\n\t\t// …\n\t},\n\t\"wikipedia\": \"de:U-Bahn-Linie 8 (Berlin)\"\n}\n```\n\n## Contributing\n\nIf you found a bug or want to propose a feature, feel free to visit [the issues page](https://github.com/juliuste/osm-transit-lines/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fosm-transit-lines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliuste%2Fosm-transit-lines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliuste%2Fosm-transit-lines/lists"}