[OSM-dev] osmium / osmjs -- node in way

Jochen Topf jochen at remote.org
Mon Aug 29 04:53:06 BST 2011

On Sun, Aug 28, 2011 at 03:41:58PM -0600, Martijn van Exel wrote:
> If I wanted to give the percentage of nodes that are part of a way for
> some OSM data, would there be a straightforward way to do that using
> osmjs?

Something like this should work (haven't tested it):

var nodes = Hash.new;
Osmium.Callbacks.node = function() {
    nodes[this.id] = 0;
Osmium.Callbacks.way = function() {
    for (var i=0; i < this.nodes.length; i++) {
        nodes[this.nodes[i]] = 1;
Osmium.Callbacks.end = function() {
    var count_all = // count elements in hash nodes
    var count_1 =   // count elements with value 1 in hash nodes
    print(count_1 / count_all);

This will create a hash with all nodes in it, so it will probably not work
on the whole planet file, because you'll not have enough RAM. If you do this
in C++, you can have a bitfield and will only need 1 bit for each node.

Jochen Topf  jochen at remote.org  http://www.remote.org/jochen/  +49-721-388298

More information about the dev mailing list