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
--
Jochen Topf jochen at remote.orghttp://www.remote.org/jochen/ +49-721-388298