Skip to content

Commit

Permalink
+utility to count objects
Browse files Browse the repository at this point in the history
  • Loading branch information
woodpeck committed Jun 26, 2013
1 parent 84d0389 commit dd5bc3a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ LIB_XML2 = $(shell xml2-config --libs)
LDFLAGS = $(LIB_EXPAT) $(LIB_PBF)

PROGRAMS = \
count_addresses
count_addresses \
count

.PHONY: all clean

Expand All @@ -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)

82 changes: 82 additions & 0 deletions count.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Osmium-based tool that counts the number of nodes/ways/relations
in the input file.
*/

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

#include <limits>
#include <iostream>

#define OSMIUM_WITH_PBF_INPUT
#define OSMIUM_WITH_XML_INPUT

#include <osmium.hpp>

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<Osmium::OSM::Node const>& node)
{
nodes++;
}

void after_nodes()
{
std::cerr << "nodes: " << nodes << "\n";
}
void way(__attribute__((__unused__)) const shared_ptr<Osmium::OSM::Way const>& way)
{
ways++;
}

void after_ways()
{
std::cerr << "ways: " << ways << "\n";
}

void relation(__attribute__((__unused__)) const shared_ptr<Osmium::OSM::Relation const>& 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();
}

0 comments on commit dd5bc3a

Please sign in to comment.