Skip to content

Commit

Permalink
noderef script
Browse files Browse the repository at this point in the history
  • Loading branch information
woodpeck committed Jan 29, 2015
1 parent f554151 commit 3136926
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ LIB_XML2 = $(shell xml2-config --libs)
LDFLAGS = $(LIB_EXPAT) $(LIB_PBF)

PROGRAMS = \
noderef \
count_addresses \
count \
osmgrep \
grep-user-from-history \
history-cleartext \
add_timestamp \
osmstats \
lastnode
Expand All @@ -48,12 +51,21 @@ all: $(PROGRAMS)
count_addresses: count_addresses.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

noderef: noderef.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

count: count.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

osmgrep: osmgrep.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

grep-user-from-history: grep-user-from-history.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

history-cleartext: history-cleartext.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

add_timestamp: add_timestamp.cpp
$(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2)

Expand Down
82 changes: 82 additions & 0 deletions noderef.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Osmium-based tool that counts how often nodes are referenced.
*/

/*
Written 2013 by Frederik Ramm <[email protected]>
Public Domain.
*/

#include <limits>
#include <iostream>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#define MAX_NODE_ID 4000000000

#include <osmium.hpp>

class RefHandler : public Osmium::Handler::Base {

unsigned char *ref;
uint64_t max_node_id;

public:

RefHandler()
{
ref = (unsigned char *) malloc(MAX_NODE_ID);
memset(ref, 0, MAX_NODE_ID);
max_node_id = 0;
}

void node(const shared_ptr<Osmium::OSM::Node const>& node)
{
max_node_id = node->id();
}

void way(const shared_ptr<Osmium::OSM::Way const>& way)
{
for (Osmium::OSM::WayNodeList::const_iterator i = way->nodes().begin(); i!= way->nodes().end(); i++)
{
if (ref[i->ref()] < 255) ref[i->ref()]++;
}
}

void after_ways()
{
uint64_t count[256];
for (int i=0; i<256; i++) count[i]=0;
for (uint64_t i = 0; i <= max_node_id; i++)
{
count[ref[i]]++;
}
for (int i=0; i<256; i++) printf("%d,%ld\n", i, count[i]);
throw Osmium::Handler::StopReading();
}

void relation(__attribute__((__unused__)) const shared_ptr<Osmium::OSM::Relation const>& relation)
{
}

};


int main(int argc, char *argv[])
{
if (argc != 2)
{
std::cerr << "usage: " << argv[0] << " osmfile" << std::endl;
exit(1);
}
Osmium::OSMFile infile(argv[1]);
RefHandler handler;
Osmium::Input::read(infile, handler);

google::protobuf::ShutdownProtobufLibrary();
}

0 comments on commit 3136926

Please sign in to comment.