Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
node-osmium area test
var osmium = require('osmium');
var bboxPolygon = require('turf-bbox-polygon');
var path = process.argv[2];
var reader = new osmium.BasicReader(path);
var handler = new osmium.Handler();
var locHandler = new osmium.LocationHandler();
var header = reader.header();
var bound = header.bounds[0],
extent = [bound.left(),bound.bottom(),bound.right(),bound.top()],
extentPolygon = bboxPolygon(extent);
var nodes = 0;
var ways = 0;
var areas = 0;
handler.on('node', function(node) {
++nodes;
});
handler.on('way', function(way) {
++ways;
});
handler.on('area', function(area) {
console.log(area.id);
++areas;
});
var mp = new osmium.MultipolygonCollector();
mp.read_relations(reader);
reader.close();
reader = new osmium.BasicReader(path);
osmium.apply(reader, locHandler, handler, mp.handler(handler));
reader.close();
console.log(bound);
console.log(nodes + ' nodes');
console.log(ways + ' ways');
console.log(areas + ' areas');
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.4.0 (21648 thorn-02.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<bounds minlat="57.7308400" minlon="11.9401000" maxlat="57.7310900" maxlon="11.9403500"/>
<node id="3657685589" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7309159" lon="11.9401610"/>
<node id="3657685590" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7309174" lon="11.9401131"/>
<node id="3657685591" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7308752" lon="11.9401083"/>
<node id="3657685592" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7310211" lon="11.9401725"/>
<node id="3657685593" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7310229" lon="11.9401191"/>
<node id="3657685594" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7309826" lon="11.9401144"/>
<node id="3657685595" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7311238" lon="11.9401885"/>
<node id="3657685596" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7311256" lon="11.9401356"/>
<node id="3657685597" visible="true" version="1" changeset="32732911" timestamp="2015-07-19T13:36:29Z" user="nachoman" uid="553649" lat="57.7310886" lon="11.9401312"/>
<node id="1470684943" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7308701" lon="11.9402657"/>
<node id="1470684877" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7308987" lon="11.9402689"/>
<node id="1470684895" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7308971" lon="11.9403184"/>
<node id="1470684800" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7309755" lon="11.9403273"/>
<node id="1470684853" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7309775" lon="11.9402816"/>
<node id="1470684803" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7309809" lon="11.9401683"/>
<node id="1470684956" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7310032" lon="11.9402843"/>
<node id="1470684831" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7310016" lon="11.9403345"/>
<node id="1470684839" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7310815" lon="11.9403429"/>
<node id="1470684925" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7310832" lon="11.9402994"/>
<node id="1470684929" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7310869" lon="11.9401801"/>
<node id="1470684782" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7311088" lon="11.9403023"/>
<node id="1470684910" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7311073" lon="11.9403494"/>
<node id="1470684938" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7311864" lon="11.9403582"/>
<node id="1470684815" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7311868" lon="11.9403133"/>
<node id="1470684826" visible="true" version="2" changeset="32732911" timestamp="2015-07-19T13:36:30Z" user="nachoman" uid="553649" lat="57.7311909" lon="11.9401967"/>
<way id="133612899" visible="true" version="5" changeset="34298362" timestamp="2015-09-28T08:29:54Z" user="liedman" uid="553049">
<nd ref="1470684803"/>
<nd ref="3657685589"/>
<nd ref="3657685590"/>
<nd ref="3657685591"/>
<nd ref="1470684943"/>
<nd ref="1470684877"/>
<nd ref="1470684895"/>
<nd ref="1470684800"/>
<nd ref="1470684853"/>
<nd ref="1470684803"/>
<tag k="addr:city" v="Gothenburg"/>
<tag k="addr:country" v="SE"/>
<tag k="addr:housenumber" v="2"/>
<tag k="addr:postcode" v="41719"/>
<tag k="addr:street" v="Växthusvägen"/>
<tag k="building" v="residential"/>
<tag k="building:levels" v="2"/>
<tag k="height" v="6"/>
<tag k="source" v="Bing"/>
</way>
<way id="133612890" visible="true" version="5" changeset="34298362" timestamp="2015-09-28T08:30:00Z" user="liedman" uid="553049">
<nd ref="1470684929"/>
<nd ref="3657685597"/>
<nd ref="3657685596"/>
<nd ref="3657685595"/>
<nd ref="1470684826"/>
<nd ref="1470684815"/>
<nd ref="1470684938"/>
<nd ref="1470684910"/>
<nd ref="1470684782"/>
<nd ref="1470684925"/>
<nd ref="1470684929"/>
<tag k="addr:city" v="Gothenburg"/>
<tag k="addr:country" v="SE"/>
<tag k="addr:housenumber" v="6"/>
<tag k="addr:postcode" v="41719"/>
<tag k="addr:street" v="Växthusvägen"/>
<tag k="building" v="residential"/>
<tag k="building:levels" v="2"/>
<tag k="height" v="6"/>
<tag k="source" v="Bing"/>
</way>
<way id="133612900" visible="true" version="5" changeset="34298362" timestamp="2015-09-28T08:29:58Z" user="liedman" uid="553049">
<nd ref="1470684853"/>
<nd ref="1470684956"/>
<nd ref="1470684831"/>
<nd ref="1470684839"/>
<nd ref="1470684925"/>
<nd ref="1470684929"/>
<nd ref="3657685592"/>
<nd ref="3657685593"/>
<nd ref="3657685594"/>
<nd ref="1470684803"/>
<nd ref="1470684853"/>
<tag k="addr:city" v="Gothenburg"/>
<tag k="addr:country" v="SE"/>
<tag k="addr:housenumber" v="4"/>
<tag k="addr:postcode" v="41719"/>
<tag k="addr:street" v="Växthusvägen"/>
<tag k="building" v="residential"/>
<tag k="building:levels" v="2"/>
<tag k="height" v="6"/>
<tag k="source" v="Bing"/>
</way>
</osm>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment