diff --git a/Makefile b/Makefile index c49d19a..c7ba5d2 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,8 @@ LIB_XML2 = $(shell xml2-config --libs) LDFLAGS = $(LIB_EXPAT) $(LIB_PBF) PROGRAMS = \ - count_addresses + count_addresses \ + count .PHONY: all clean @@ -43,6 +44,9 @@ all: $(PROGRAMS) count_addresses: count_addresses.cpp $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2) +count: count.cpp + $(CXX) $(CXXFLAGS) $(CXXFLAGS_LIBXML2) -o $@ $< $(LDFLAGS) $(LIB_XML2) + clean: rm -f *.o core $(PROGRAMS) diff --git a/count.cpp b/count.cpp new file mode 100644 index 0000000..69266a6 --- /dev/null +++ b/count.cpp @@ -0,0 +1,82 @@ +/* + Osmium-based tool that counts the number of nodes/ways/relations + in the input file. +*/ + +/* + +Written 2013 by Frederik Ramm + +Public Domain. + +*/ + +#include +#include + +#define OSMIUM_WITH_PBF_INPUT +#define OSMIUM_WITH_XML_INPUT + +#include + +class CountHandler : public Osmium::Handler::Base { + + uint64_t nodes; + uint64_t ways; + uint64_t rels; + +public: + + CountHandler() + { + nodes = 0; + ways = 0; + rels = 0; + } + + void node(__attribute__((__unused__)) const shared_ptr& node) + { + nodes++; + } + + void after_nodes() + { + std::cerr << "nodes: " << nodes << "\n"; + } + void way(__attribute__((__unused__)) const shared_ptr& way) + { + ways++; + } + + void after_ways() + { + std::cerr << "ways: " << ways << "\n"; + } + + void relation(__attribute__((__unused__)) const shared_ptr& relation) + { + rels++; + } + + void after_relations() + { + std::cerr << "relations: " << rels << "\n"; + } + +}; + + +int main(int argc, char *argv[]) +{ + if (argc != 2) + { + std::cerr << "usage: " << argv[0] << " osmfile" << std::endl; + exit(1); + } + Osmium::OSMFile infile(argv[1]); + CountHandler handler; + Osmium::Input::read(infile, handler); + + google::protobuf::ShutdownProtobufLibrary(); +} +