Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created November 5, 2013 15:01
Show Gist options
  • Save tmcw/7320338 to your computer and use it in GitHub Desktop.
Save tmcw/7320338 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <getopt.h>
#include <osmium/io/any_input.hpp>
#include <osmium/io/any_output.hpp>
#include <sstream>
void print_help() {
std::cout << "name_count INFILE\n\n" \
<< "Outputs a name frequency table.";
}
class MyCountHandler : public osmium::handler::Handler<MyCountHandler> {
public:
MyCountHandler(const std::string& fieldname) {
}
void way(const osmium::Way& way) {
const char* highway = way.tags().get_value_by_key("highway");
const char* name = way.tags().get_value_by_key("name");
if (highway && name) {
std::cout << std::string(name) << std::endl;
}
}
};
int main(int argc, char* argv[]) {
std::string input_filename;
std::string output_filename("ogr_out");
int remaining_args = argc - optind;
if (remaining_args == 1) {
input_filename = argv[optind];
} else {
input_filename = "-";
}
osmium::io::Reader reader(input_filename);
osmium::io::Header header = reader.open();
MyCountHandler count_handler("name");
reader.apply(count_handler);
google::protobuf::ShutdownProtobufLibrary();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment