bool CommandCat::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("object-type,t", po::value<std::vector<std::string>>(), "Read only objects of given type (node, way, relation, changeset)") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_multiple_inputs_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filenames", po::value<std::vector<std::string>>(), "Input files") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filenames", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_input_files(vm); setup_output_file(vm); return true; }
bool CommandRenumber::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Allowed options"); cmdline.add_options() ("index-directory,i", po::value<std::string>(), "Index directory") ; add_common_options(cmdline); add_single_input_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); setup_common(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("index-directory")) { m_index_directory = vm["index-directory"].as<std::string>(); } return true; }
bool CommandRenumber::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("index-directory,i", po::value<std::string>(), "Index directory") ("object-type,t", po::value<std::vector<std::string>>(), "Renumber only objects of given type (node, way, relation)") ("show-index", po::value<std::string>(), "Show contents of index file") ("start-id,s", po::value<std::string>(), "Comma separated list of first node, way, and relation id to use (default: 1,1,1)") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "Input file") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); if (vm.count("index-directory")) { m_index_directory = vm["index-directory"].as<std::string>(); } if (vm.count("show-index")) { show_index(vm["show-index"].as<std::string>()); return false; } setup_common(vm, desc); setup_progress(vm); setup_object_type_nwr(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("start-id")) { set_start_ids(vm["start-id"].as<std::string>()); } return true; }
bool CommandSort::setup(const std::vector<std::string>& arguments) { po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_multiple_inputs_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filenames", po::value<std::vector<std::string>>(), "OSM input files") ("strategy,s", po::value<std::string>(), "Strategy (default: simple)") ; po::options_description desc; desc.add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filenames", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_progress(vm); setup_input_files(vm); setup_output_file(vm); if (vm.count("input-filenames")) { m_filenames = vm["input-filenames"].as<std::vector<std::string>>(); } if (vm.count("strategy")) { m_strategy = vm["strategy"].as<std::string>(); if (m_strategy != "simple" && m_strategy != "multipass") { throw argument_error{"Unknown strategy: " + m_strategy}; } } return true; }
bool CommandMergeChanges::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Available options"); cmdline.add_options() ("simplify,s", "Simplify change") ; add_common_options(cmdline); add_multiple_inputs_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filenames", po::value<std::vector<std::string>>(), "Input files") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filenames", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << "Usage: osmium merge-changes [OPTIONS] OSM-CHANGE-FILE...\n\n"; std::cout << cmdline << "\n"; exit(0); } setup_common(vm); setup_input_files(vm); setup_output_file(vm); if (vm.count("simplify")) { m_simplify_change = true; } return true; }
bool CommandGetParents::setup(const std::vector<std::string>& arguments) { po::options_description opts_cmd{"COMMAND OPTIONS"}; opts_cmd.add_options() ("default-type", po::value<std::string>()->default_value("node"), "Default item type") ("id-file,i", po::value<std::vector<std::string>>(), "Read OSM IDs from text file") ("id-osm-file,I", po::value<std::vector<std::string>>(), "Read OSM IDs from OSM file") ("add-self,s", "Add objects with specified IDs themselves") ("verbose-ids", "Print all requested IDs") ; po::options_description opts_common{add_common_options()}; po::options_description opts_input{add_single_input_options()}; po::options_description opts_output{add_output_options()}; po::options_description hidden; hidden.add_options() ("input-filename", po::value<std::string>(), "OSM input file") ("ids", po::value<std::vector<std::string>>(), "OSM IDs") ; po::options_description desc; desc.add(opts_cmd).add(opts_common).add(opts_input).add(opts_output); po::options_description parsed_options; parsed_options.add(desc).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); positional.add("ids", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(parsed_options).positional(positional).run(), vm); po::notify(vm); setup_common(vm, desc); setup_progress(vm); setup_input_file(vm); setup_output_file(vm); if (vm.count("add-self")) { m_add_self = true; } if (vm.count("default-type")) { m_default_item_type = parse_item_type(vm["default-type"].as<std::string>()); } if (vm.count("verbose-ids")) { m_vout.verbose(true); m_verbose_ids = true; } if (vm.count("id-file")) { for (const std::string& filename : vm["id-file"].as<std::vector<std::string>>()) { if (filename == "-") { if (m_input_filename.empty() || m_input_filename == "-") { throw argument_error{"Can not read OSM input and IDs both from STDIN."}; } m_vout << "Reading IDs from STDIN...\n"; read_id_file(std::cin, m_ids, m_default_item_type); } else { std::ifstream id_file{filename}; if (!id_file.is_open()) { throw argument_error{"Could not open file '" + filename + "'"}; } m_vout << "Reading ID file...\n"; read_id_file(id_file, m_ids, m_default_item_type); } } } if (vm.count("id-osm-file")) { for (const std::string& filename : vm["id-osm-file"].as<std::vector<std::string>>()) { m_vout << "Reading OSM ID file...\n"; read_id_osm_file(filename, m_ids); } } if (vm.count("ids")) { std::string sids; for (const auto& s : vm["ids"].as<std::vector<std::string>>()) { sids += s + " "; } for (const auto& s : osmium::split_string(sids, "\t ;,/|", true)) { parse_and_add_id(s, m_ids, m_default_item_type); } } if (no_ids(m_ids)) { throw argument_error{"Please specify IDs to look for on command line or with option --id-file/-i or --id-osm-file/-I."}; } return true; }
bool CommandAddRefs::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Available options"); cmdline.add_options() ("id-file,i", po::value<std::string>(), "Read OSM IDs from given file") ("source,s", po::value<std::string>(), "Source file supplying the referenced objects") ("source-format", po::value<std::string>(), "Format of source file") ; add_common_options(cmdline); add_multiple_inputs_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filenames", po::value<std::vector<std::string>>(), "OSM input files") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filenames", -1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << "Usage: osmium add-refs [OPTIONS] -s OSM-DATA-FILE OSM-DATA-FILE...\n" << " osmium add-refs [OPTIONS] -s OSM-DATA-FILE -i ID-FILE\n\n"; std::cout << cmdline << "\n"; exit(0); } setup_common(vm); setup_input_files(vm, true); setup_output_file(vm); if (vm.count("id-file")) { std::string filename = vm["id-file"].as<std::string>(); std::ifstream id_file{filename}; if (!id_file.is_open()) { throw argument_error("Could not open file '" + filename + "'"); } for (std::string line; std::getline(id_file, line); ) { if (line.empty() || line[0] == '#') { continue; } auto pos = line.find(' '); if (pos != std::string::npos) { line = line.erase(pos); } parse_and_add_id(line); } } if (vm.count("source")) { m_source_filename = vm["source"].as<std::string>(); } if (vm.count("source-format")) { m_source_format = vm["source-format"].as<std::string>(); } m_source_file = osmium::io::File{m_source_filename, m_source_format}; return true; }
bool CommandTimeFilter::setup(const std::vector<std::string>& arguments) { po::options_description cmdline("Available options"); add_common_options(cmdline); add_single_input_options(cmdline); add_output_options(cmdline); po::options_description hidden("Hidden options"); hidden.add_options() ("input-filename", po::value<std::string>(), "OSM input file") ("time-from", po::value<std::string>(), "Start of time range") ("time-to", po::value<std::string>(), "End of time range") ; po::options_description desc("Allowed options"); desc.add(cmdline).add(hidden); po::positional_options_description positional; positional.add("input-filename", 1); positional.add("time-from", 1); positional.add("time-to", 1); po::variables_map vm; po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << "Usage: osmium time-filter [OPTIONS] OSM-HISTORY-FILE [TIME]\n" << " osmium time-filter [OPTIONS] OSM-HISTORY-FILE FROM-TIME TO-TIME\n\n"; std::cout << cmdline << "\n"; exit(0); } setup_common(vm); setup_input_file(vm); setup_output_file(vm); m_from = osmium::Timestamp(time(0)); m_to = m_from; if (vm.count("time-from")) { auto ts = vm["time-from"].as<std::string>(); try { m_from = osmium::Timestamp(ts); } catch (std::invalid_argument&) { throw argument_error("Wrong format for (first) timestamp (use YYYY-MM-DDThh:mm:ssZ)."); } m_to = m_from; } if (vm.count("time-to")) { auto ts = vm["time-to"].as<std::string>(); try { m_to = osmium::Timestamp(ts); } catch (std::invalid_argument&) { throw argument_error("Wrong format for second timestamp (use YYYY-MM-DDThh:mm:ssZ)."); } } if (m_from > m_to) { throw argument_error("Second timestamp is before first one."); } if (m_from == m_to) { // point in time if (m_output_file.has_multiple_object_versions()) { std::cerr << "Warning! You are writing to a file marked as having multiple object versions,\n"; std::cerr << "but there will be only a single version of each object.\n"; } } else { // time range if (!m_output_file.has_multiple_object_versions()) { std::cerr << "Warning! You are writing to a file marked as having a single object version,\n"; std::cerr << "but there might be multiple versions of each object.\n"; } } return true; }