Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyrasd/osmtogeojson
convert osm to geojson
https://github.com/tyrasd/osmtogeojson
geojson javascript openstreetmap openstreetmap-data overpass-turbo
Last synced: 30 days ago
JSON representation
convert osm to geojson
- Host: GitHub
- URL: https://github.com/tyrasd/osmtogeojson
- Owner: tyrasd
- License: mit
- Created: 2013-10-03T11:41:07.000Z (about 11 years ago)
- Default Branch: gh-pages
- Last Pushed: 2023-12-05T18:35:54.000Z (11 months ago)
- Last Synced: 2024-04-15T14:25:33.179Z (7 months ago)
- Topics: geojson, javascript, openstreetmap, openstreetmap-data, overpass-turbo
- Language: JavaScript
- Homepage: http://tyrasd.github.io/osmtogeojson/
- Size: 548 KB
- Stars: 667
- Watchers: 28
- Forks: 107
- Open Issues: 54
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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
* fastThis 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 ` 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
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.