From 3136926b9012209d73d1a80fbae1a27c59084c2d Mon Sep 17 00:00:00 2001 From: Frederik Ramm Date: Thu, 29 Jan 2015 02:28:15 +0100 Subject: [PATCH] noderef script --- Makefile | 12 ++++++++ noderef.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 noderef.cpp diff --git a/Makefile b/Makefile index 7603699..acd372d 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) diff --git a/noderef.cpp b/noderef.cpp new file mode 100644 index 0000000..b4e1cd3 --- /dev/null +++ b/noderef.cpp @@ -0,0 +1,82 @@ +/* + Osmium-based tool that counts how often nodes are referenced. +*/ + +/* + +Written 2013 by Frederik Ramm + +Public Domain. + +*/ + +#include +#include + +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + +#define MAX_NODE_ID 4000000000 + +#include + +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& node) + { + max_node_id = node->id(); + } + + void way(const shared_ptr& 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& 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(); +} +