Giter Site home page Giter Site logo

murznn / osm2geojson-lite Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tibetty/osm2geojson-lite

0.0 0.0 0.0 3.65 MB

a lightweight yet faster osm (either in xml or in json formats) to geojson convertor - 4x faster than xmldom + osmtogeojson in most situations - implemented in pure JavaScript without any 3rd party dependency

JavaScript 56.66% Makefile 0.13% HTML 9.29% TypeScript 33.92%

osm2geojson-lite's Introduction

osm2geojson-lite

A lightweight (not as lightweight as xml2geojson though) yet faster convertor for OSM data whatever in XML or JSON formats to GeoJSON - much faster (the more complex the data source is, the more performance advantages it posesses) than osmtogeojson in most situations - implemented in pure JavaScript without any 3rd party dependency.

History

An internal function inside query-geo-boundary โ†’ stripped out to handle OSM XML only xml2geojson-lite โ†’ this library that supports both OSM XML and OSM/Overpass JSON

Usage

As a Node.JS Library

Installation:

$ npm install osm2geojson-lite

Usage:

    const osm2geojson = require('osm2geojson-lite');
    let geojson = osm2geojson(osm, opts);

In the Browser

    <script src='your/path/to/osm2geojson-lite.js'/>
    let geojson = osm2geojson(osm, opts);

API

osm2geojson(osm, opts)

Converts OSM data (XML/JSON) to GeoJSON.

  • osm: the OSM XML data in String, or OSM/Overpass JSON as object or in String
  • opts?: optional, the options object, right now supports below properties/fields:
    • completeFeature/allFeatures: the default value is false. When it's set to true, the returned geojson will include all elements that meet the specified conditions in FeatureCollection format; otherwise, only the bare geometry of the first relation element will be returned.
    • renderTagged: the default value is false. When it's set to true, the returned geojson will include all elements with tags (i.e., tagged) until suppressWay changes its behavior a bit; otherwise only the unreferenced ones get returned.
    • suppressWay/excludeWay: the default value is true. When it's set to true, the returned FeatureCollection will exclude all referenced ways even though they are tagged; otherwise the features of those ways will be included in the resulted result as well.

Performance

  1. Workloads include the boundary XML and JSON of 4 administrive areas (zhucheng, hebei, tokyodo, usa)
  2. Call each conversion for 100 rounds to mitigate the impacts of GC and other factors
  3. For each script, run as many as times seperately and then calculate the average cost time (ACT for short)
  4. The # listed in the table below are coarse lowest values of dividing the ACT of osmtogeojson by the one of this library
$ cd bench
$ node o2gl-bench.js
$ node otg-bench.js

1. XML
-----------------------------------------------------
|  zhucheng  |   hebei    |  tokyodo   |    usa     |
+------------+------------+------------+------------+
|  >2.5x     |  >4.0x     |  >3.0x     |  >3.0x     |
-----------------------------------------------------
2. Overpass JSON
-----------------------------------------------------
|  zhucheng  |   hebei    |  tokyodo   |    usa     |
+------------+------------+------------+------------+
|  >2.5x     |  >11.0x    |  >7.0x     |  >5.0x     |
-----------------------------------------------------

Correctness

You can copy the converted results to geojsonlint for the correctness validation. Up until now, osm2geojson-lite behaves pretty well with all the samples (also quite representative) in the data subfolers under test and bench directories, which also outperforms osmtogeojson.

The client side example shipped along with this package, index.html will automatically call geojsonlint validation service directly after each conversion, you can wait for a while to see the validation result after click the conversion button.

Node.JS version

ES5/ES6 features

Dependencies

  • No 3rd party dependency

License

Written in 2018 by tibetty [email protected]

osm2geojson-lite's People

Contributors

tibetty avatar dingyuanhong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.