Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/osm-flatten-relation
Resolve an OpenStreetMap relation recursively.
https://github.com/derhuerst/osm-flatten-relation
openstreetmap osm
Last synced: 4 days ago
JSON representation
Resolve an OpenStreetMap relation recursively.
- Host: GitHub
- URL: https://github.com/derhuerst/osm-flatten-relation
- Owner: derhuerst
- License: isc
- Created: 2016-05-14T14:02:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-30T17:03:32.000Z (over 1 year ago)
- Last Synced: 2024-12-21T21:37:26.149Z (21 days ago)
- Topics: openstreetmap, osm
- Language: JavaScript
- Homepage: https://github.com/derhuerst/osm-flatten-relation
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# osm-flatten-relation
**Resolve an [OpenStreetMap](http://www.openstreetmap.org) relation recursively.**
[![npm version](https://img.shields.io/npm/v/osm-flatten-relation.svg)](https://www.npmjs.com/package/osm-flatten-relation)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/osm-flatten-relation.svg)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)## Installing
```
npm install osm-flatten-relation
```## Usage
From the command line:
```
osm-flatten-relation 2679163 >nodes.ndjson
```As a JavaScript library:
```js
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](https://nodejs.org/api/stream.html#stream_class_stream_readable) of a [relation](http://wiki.openstreetmap.org/wiki/Elements#Relation)'s [ways](http://wiki.openstreetmap.org/wiki/Elements#Way) and [nodes](http://wiki.openstreetmap.org/wiki/Elements#Node). 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.
### Example
To get all nodes of [*U-Bahnlinie U6: Alt-Mariendorf => Alt-Tegel*](http://www.openstreetmap.org/relation/2679163) with a `concurrency` of `5` requests:
```js
import {flattenOsmRelation as flatten} from 'osm-flatten-relation'flatten(2679163, 5)
.on('data', console.log)
.once('erorr', (err) => {
console.log(err)
process.exit(1)
})
``````js
{id: 3043920508, latitude: 52.439691, longitude: 13.3877031}
{id: 31034998, latitude: 52.4537104, longitude: 13.3843233}
// …
{id: 1688279730, latitude: 52.439011, longitude: 13.3878563}
```## Contributing
If you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/derhuerst/osm-flatten-relation/issues).