osm2obj

Streaming parser from OSM XML to OSM objects

Implements a Node Transform Stream. Takes a readable stream of OSM XML and outputs a stream of objects compatible with Overpass OSM JSON. Also reads OsmChange XML and outputs the same format but with an additional property action which is one of create, modify, delete. Uses sax-js to work in both node and the browser.

opts.strict - Be a jerk about XML (default false). In strict mode will throw an error if:

XML is badly formatted

Case of element names differs from spec

Root node is not one of osm, osmChange, diffResult

An action element (create, modify, delete) appears when the root is not osmChange

Any element in the XML which is not one of create, modify, delete, node, way, relation, changeset, bounds, nd, tag, member

Any attribute that is not a valid OSM XML attribute will be ignored (see WHITELISTS). tag, member, or nd elements without the required attributes will throw an error. The readable side of the stream is in objectMode.

Parses OsmChange XML. Output objects will have property action which is one of create, modify, delete.

If a <delete> block in osmChange XML has an if-unused attribute, then each object within the block will have a prop ifUnused=true. The value of the attribute is ignored, as per the OSM API 0.6 spec.

stream.parse(str)

Parse str and return the result. Will throw any error.

Contribute

PRs welcome. Please follow JS Standard Style. Right now this could do with some tests. If you are feeling ambitious, this could be sped up by using node-expat on node. The interface is similar to sax-js and it should be possible to wrap this to use sax-js on the browser and node-expat on the server using the browserify browser field