Resolve an OpenStreetMap relation recursively.
npm install osm-flatten-relation
From the command line:
osm-flatten-relation 2679163 >nodes.ndjson
As a JavaScript library:
import {flattenOsmRelation as flatten} from 'osm-flatten-relation'
flatten(relation, concurrency = 4, retries = 3)
.on('stats', (stats) => console.log(stats))
.on('relation', (relation) => console.log('relation', relation.id))
.on('way', (way) => console.log('way', way.id))
.on('node', (node) => console.log('node', node.id))
// .on('data', console.log)
.on('error', console.error)
flatten
returns a readable stream of a relation's ways and nodes. It will also emit the events relation
, way
and node
whenever it fetched data.
Note: With concurrency > 1
, nodes will not be emitted in breadth-first order anymore.
To get all nodes of U-Bahnlinie U6: Alt-Mariendorf => Alt-Tegel with a concurrency
of 5
requests:
import {flattenOsmRelation as flatten} from 'osm-flatten-relation'
flatten(2679163, 5)
.on('data', console.log)
.once('erorr', (err) => {
console.log(err)
process.exit(1)
})
{id: 3043920508, latitude: 52.439691, longitude: 13.3877031}
{id: 31034998, latitude: 52.4537104, longitude: 13.3843233}
// …
{id: 1688279730, latitude: 52.439011, longitude: 13.3878563}
If you have a question, found a bug or want to propose a feature, have a look at the issues page.