# osmtogeojson

> convert OSM to geojson

Latest version **3.0.0-beta.5** (published 2022-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install osmtogeojson
pnpm add osmtogeojson
yarn add osmtogeojson
bun add osmtogeojson
```

Provides the command `osmtogeojson`.

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.0-beta.5 |
| Published | 2022-10-18 |
| First published | 2013-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=0.5 |
| Dependencies | 10 |
| Unpacked size | 408.8 KB |
| Known vulnerabilities | 0 (+16 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 750 |
| Author | Martin Raifer |
| Maintainers | tyr_asd |
| Keywords | openstreetmap, geojson |

## Links

- npm: https://www.npmjs.com/package/osmtogeojson
- Repository: https://github.com/tyrasd/osmtogeojson
- Homepage: https://github.com/tyrasd/osmtogeojson#readme
- Issues: https://github.com/tyrasd/osmtogeojson/issues
- npm.io page: https://npm.io/package/osmtogeojson

## Dependencies (10)

- [optimist](https://npm.io/package/optimist.md) ~0.3.5
- [JSONStream](https://npm.io/package/JSONStream.md) 0.8.0
- [htmlparser2](https://npm.io/package/htmlparser2.md) 3.5.1
- [tiny-osmpbf](https://npm.io/package/tiny-osmpbf.md) ^0.1.0
- [concat-stream](https://npm.io/package/concat-stream.md) 2.0.0
- [@types/geojson](https://npm.io/package/@types/geojson.md) ^7946.0
- [@xmldom/xmldom](https://npm.io/package/@xmldom/xmldom.md) 0.8.3
- [geojson-numeric](https://npm.io/package/geojson-numeric.md) 0.2.1
- [osm-polygon-features](https://npm.io/package/osm-polygon-features.md) ^0.9.1
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) 0.5.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.0-beta.5 (latest) — 2022-10-18
- 3.0.0-beta.4 — 2019-11-27
- 3.0.0-beta.3 — 2017-12-17
- 3.0.0-beta.2 — 2017-05-28
- 3.0.0-beta.1 — 2017-05-28
- 3.0.0-beta.0 — 2017-02-19
- 2.2.12 — 2016-08-27
- 2.2.11 — 2016-02-15
- 2.2.10 — 2016-02-15
- 2.2.9 — 2016-02-14
- 2.2.8 — 2016-02-13
- 2.2.7 — 2016-01-30
- 2.2.6 — 2016-01-12
- 2.2.5 — 2015-02-07
- 2.2.4 — 2015-01-30
- … 15 more at https://npm.io/package/osmtogeojson/versions

## README

osmtogeojson
============

Converts [OSM](https://www.openstreetmap.org/) [data](https://wiki.openstreetmap.org/wiki/OSM_XML) to [GeoJSON](https://geojson.org/). Try the [demo](https://tyrasd.github.io/osmtogeojson/)!

* stable
* real OSM [polygon detection](https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features)
* proper OSM multipolygon support
* full support for extended Overpass API [geometry modes](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Print_.28out.29)
* well [tested](https://github.com/tyrasd/osmtogeojson/tree/gh-pages/test/) and proven
* fast

This code is used in and maintained by the [overpass turbo](https://github.com/tyrasd/overpass-turbo) project.

[![Build Status](https://secure.travis-ci.org/tyrasd/osmtogeojson.png)](https://travis-ci.org/github/tyrasd/osmtogeojson)

Usage
-----

### command line tool
  
Installation:

      $ npm install -g osmtogeojson

Usage:

    $ osmtogeojson file.osm > file.geojson

Supported command line options are shown with:

    $ osmtogeojson --help

When working with extra large data files (≳ 100 MB) it is recommended to run the programm with a little extra memory to avoid *process out of memory* errors. The easiest way to do this is by running the command as `node <path-to-osmtogeojson>` and setting the `--max_old_space_size=…` parameter to the available memory size in MB (osmtogeojson typically needs about 4-5 times the input data size). On a Unix system, you can use the following command:

    $ node --max_old_space_size=8192 `which osmtogeojson` large.osm > large.geojson

### nodejs library

Installation:

    $ npm install osmtogeojson

Usage:

    var osmtogeojson = require('osmtogeojson');
    osmtogeojson(osm_data);

### browser library

    <script src='osmtogeojson.js'></script>

    osmtogeojson(osm_data);

API
---

### `osmtogeojson( data, options )`

Converts OSM data into GeoJSON.

* `data`: the OSM data. Either as a XML DOM or in [OSM JSON](https://overpass-api.de/output_formats.html#json).
* `options`: optional. The following options can be used:
  * `flatProperties`: If true, the resulting GeoJSON feature's properties will be a simple key-value list instead of a structured json object (with separate tags and metadata). default: false
  * `uninterestingTags`: Either a [blacklist](https://github.com/tyrasd/osmtogeojson/blob/2.0.0/index.js#L14-L24) of tag keys or a callback function. Will be used to decide if a feature is *interesting* enough for its own GeoJSON feature.
  * `polygonFeatures`: Either a [json object](https://github.com/tyrasd/osmtogeojson/blob/2.0.0/polygon_features.json) or callback function that is used to determine if a closed way should be treated as a Polygon or LineString. [read more](https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features)

The result is a javascript object of GeoJSON data:

GeoJSON
-------

The GeoJSON produced by this library will include exactly one GeoJSON-feature for each of the following OSM objects (that is everything that is also visible in overpass turbo's map view):

* all unconnected or [*interesting*](#api) tagged nodes (POIs)
* all ways (except [*uninteresting*](#api) multipolygon outlines)
* all multipolygons (simple multipolygons with exactly one closed outer way are present via their outer way)

All data is given as a FeatureCollection. Each Feature in the collection has an `id` property that is formed from the type and id of the original OSM object (e.g. `node/123`) and has the member `properties` containing the following data:

* `type`: the OSM data type
* `id`: the OSM id 
* `tags`: a collection of all tags
* `meta`: metainformaton about the feature (e.g. version, timestamp, user, etc.)
* `relations`: an array of relations the feature is member of. Each relation is encoded as an object literal containing the following properties: `role` (membership role), `rel` (the relation's id) and `reltags` (contains all tags of the relation)
* `tainted`: this flag is set when the feature's geometry is incomplete (e.g. missing nodes of a way or missing ways of a multipolygon)

If the [option](#api) `flatProperties` is set to true, the `properties` object will not contain any nested object literals, but directly provide a concise id, meta data and the tags of the respective OSM object.

---
_Source: https://npm.io/package/osmtogeojson · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
