GithubHelp home page GithubHelp logo

nvdnkpr / osm-read Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marook/osm-read

0.0 3.0 0.0 218 KB

an openstreetmap XML data parser for node.js

License: GNU General Public License v3.0

osm-read's Introduction

osm-read - an openstreetmap XML and PBF parser for node.js

1) Introduction
2) Usage Examples
2.1) Simple Usage Example
2.2) Parse OSM XML from URL Example
2.3) PBF random access parser
3) TODOs
4) License
5) Contact

------------------------------------------------------------------------
Introduction

osm-read parses openstreetmap XML and PBF files as described in
http://wiki.openstreetmap.org/wiki/OSM_XML and
http://wiki.openstreetmap.org/wiki/PBF_Format


------------------------------------------------------------------------
Simple Usage Example

The following code is used to parse openstreetmap XML or PBF files in a
SAX parser like callback way.

osmread.parse({
    filePath: 'path/to/osm.xml',
    endDocument: function(){
        console.log('document end');
    },
    bounds: function(bounds){
        console.log('bounds: ' + JSON.stringify(bounds));
    },
    node: function(node){
        console.log('node: ' + JSON.stringify(node));
    },
    way: function(way){
        console.log('way: ' + JSON.stringify(way));
    },
    error: function(msg){
        console.log('error: ' + msg);
    }
});


------------------------------------------------------------------------
Parse OSM XML from URL Example

Currently you can only parse OSM data in XML from URLs. Here's an example:

osmread.parse({
    url: 'http://overpass-api.de/api/interpreter?data=node(51.93315273540566%2C7.567176818847656%2C52.000418429293326%2C7.687854766845703)%5Bhighway%3Dtraffic_signals%5D%3Bout%3B',
    format: 'xml',
    endDocument: function(){
        console.log('document end');
    },
    bounds: function(bounds){
        console.log('bounds: ' + JSON.stringify(bounds));
    },
    node: function(node){
        console.log('node: ' + JSON.stringify(node));
    },
    way: function(way){
        console.log('way: ' + JSON.stringify(way));
    },
    error: function(msg){
        console.log('error: ' + msg);
    }
});


------------------------------------------------------------------------
PBF random access parser

The following code allows to create a random access openstreetmap PBF
file parser:

osmread.createPbfParser({
    filePath: 'path/to/osm.pbf',
    callback: function(err, parser){
        var headers;

        if(err){
            // TODO handle error
        }

        headers = parser.findFileBlocksByBlobType('OSMHeader');

        parser.readBlock(headers[0], function(err, block){
            console.log('header block');
            console.log(block);

            parser.close(function(err){
                if(err){
                    // TODO handle error
                }
            });
        });
    });
});

Don't forget to close the parse after usage!


------------------------------------------------------------------------
TODOs

* parse timestamps


------------------------------------------------------------------------
License

See file COPYING for details.


------------------------------------------------------------------------
Contact

* author: Markus Pielmeier <[email protected]>

osm-read's People

Contributors

marook avatar ubergesundheit avatar

Watchers

 avatar  avatar  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.