osm-read - an openstreetmap XML and PBF parser for node.js and the browser
- Introduction
- Usage Examples
- Simple Usage Example
- Parse OSM XML from URL Example
- PBF random access parser
- Version Upgrade Guide
- TODOs
- License
- 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
Continuous Integration
Simple Usage Example
The following code is used to parse openstreetmap XML or PBF files in a SAX parser like callback way.
var parser = osmread; // you can pause the parserparser; // and resume it againparser;
Parse PBF in the browser
The browser bundle 'osm-read-pbf.js' provides a global variable 'pbfParser' with a 'parse' method.
Example, see also example/pbf.html:
As an alternative to passing an URL in "filePath", the option "buffer" can be used to pass an already loaded ArrayBuffer object:
var buf = ... // e.g. xhr.response pbfParser
A third alternative is to let the user choose a local file using the HTML5 File API, passing the file object as "file" option:
<input type="file" id="file" accept=".pbf">
<script>
document.getElementById("file").addEventListener("change", parse, false);
function parse(evt) {
var file = evt.target.files[0];
pbfParser.parse({
file: file,
...
See also example/file.html
Build
Build or update the browser bundle osm-read-pbf.js
with browserify:
$ npm run browserify
To install browserify (http://browserify.org/):
$ npm install -g browserify
Parse OSM XML from URL Example
Currently you can only parse OSM data in XML from URLs. Here's an example:
osmread;
PBF random access parser
The following code allows to create a random access openstreetmap PBF file parser:
osmread;
Don't forget to close the parser after usage!
Version Upgrade Guide
Sometimes APIs change... they break your code but things get easier for the rest of us. I'm sorry if a version upgrade gives you some extra hours. To makes things a little less painfull you can find migration instructions in the file ChangeLog.
TODOs
XML parser:
- parse timestamps
License
See file COPYING for details.
Contact
author: Markus Peröbner markus.peroebner@gmail.com