Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Streaming parser from OSM XML to OSM JSON objects
Implements a Node Transport 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.
npm install osm2json
var fs = require('fs')
var Osm2Json = require('../lib/osm2json')
var rs = fs.createReadableStream(__dirname + './test.osm')
rs.pipe(new Osm2Json()).pipe(process.stdout)
// node
{
type: 'node',
id: 1,
version: 0,
timestamp: '2013-09-05T19:38:11.187Z',
uid: 1,
user: 'gregor',
lat: 0,
lon: 0,
tags: { null: 'island' }
}
// way
{
type: 'way',
id: 3,
version: 3,
timestamp: '2013-09-05T19:38:11Z',
changeset: 49,
nodes: [ 19, 20, 21, 22, 26, 27 ],
tags: { name: 'York St' }
}
// relation
{
type: 'relation',
id: 1,
members: [
{
type: 'relation',
ref: 1745069,
role: ''
},
{
type: 'relation',
ref: 172789,
role: ''
}
],
tags: {
from: 'Konrad-Adenauer-Platz',
name: 'VRS 636'
}
}
var Osm2Json = require('osm2json')
Create a transform stream with:
opts.coerceIds
- coerce id-type fields (id, uid, version, changeset, ref
) to Number
(default true
) - useful for osm-p2p-db where ids can be strings.opts.bounds
- Also parse bounds (default true
)opts.types
- An array of element types you are interested in, e.g. opts.types = ['node']
(default ['node', 'way', 'relation', 'changeset']
)opts.strict
- Be a jerk about XML (default false
). In strict mode will throw an error if:
osm
, osmChange
create, modify, delete
) appears when the root is not osmChange
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
, of nd
elements without the required attributes will throw an error. The readable side of the stream is in objectMode
.
Parse str
and return the result. Will throw any error.
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
MIT (c) 2016, Digital Democracy.
FAQs
Converts an OSM XML file to OSM JSON objects as a transform stream
The npm package osm2json receives a total of 10 weekly downloads. As such, osm2json popularity was classified as not popular.
We found that osm2json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.