Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
bool CommandCheckRefs::setup(const std::vector<std::string>& arguments) {
    po::options_description opts_cmd{"COMMAND OPTIONS"};
    opts_cmd.add_options()
    ("show-ids,i", "Show IDs of missing objects")
    ("check-relations,r", "Also check relations")
    ;

    po::options_description opts_common{add_common_options()};
    po::options_description opts_input{add_single_input_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);

    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);

    setup_common(vm, desc);
    setup_progress(vm);
    setup_input_file(vm);

    if (vm.count("show-ids")) {
        m_show_ids = true;
    }

    if (vm.count("check-relations")) {
        m_check_relations = true;
    }

    return true;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 7
0
int test_scan(struct gl843_device *dev)
{
	int ret;
	struct scan_setup ss = {};
	struct gl843_image *img = NULL;

	CHK(write_reg(dev, GL843_SCANRESET, 1));
	CHK(wait_until_home(dev));

	CHK(setup_static(dev));
	ss.source = LAMP_PLATEN;
	ss.fmt = PXFMT_RGB16;
	ss.dpi = 1200;
	ss.start_x = 128;
	ss.width = 10208;
	//ss.start_y = 236;
	ss.start_y = 5;
	ss.height = 1200;
	ss.use_backtracking = 1;

	CHK_MEM(img = create_image(ss.width, ss.height, ss.fmt));

	CHK(setup_common(dev, &ss));
	CHK(setup_horizontal(dev, &ss));
	CHK(setup_vertical(dev, &ss, 0));
	CHK(set_lamp(dev, ss.source, 10));
	CHK(write_reg(dev, GL843_MTRPWR, 1));
	CHK(scan_img(dev, img, 10000));

	write_pnm_image("test.pnm", img);

	CHK(wait_until_home(dev));
	CHK(write_reg(dev, GL843_MTRPWR, 0));

chk_mem_failed:
chk_failed:
	free(img);
	return ret;
}
Exemplo n.º 8
0
int do_warmup_scan(struct gl843_device *dev, float cal_y_pos)
{
	int ret;
	struct scan_setup ss = {};
	struct calibration_info *cal;
	int lamp_to = 4; // FIXME: Get user setting

	CHK(write_reg(dev, GL843_SCANRESET, 1));
	CHK(wait_until_home(dev));

	CHK(setup_static(dev));

	CHK(move_scanner_head(dev, cal_y_pos));
	CHK(wait_motor(dev));

	// FIXME: Get user setting
	ss.source = LAMP_PLATEN;
	ss.fmt = PXFMT_RGB16;
	ss.dpi = 1200;
	ss.start_x = 128;
	ss.width = 10208;
	ss.height = 16;

	CHK(setup_common(dev, &ss));
	CHK(setup_horizontal(dev, &ss));

	CHK_MEM(cal = create_calinfo(ss.source, cal_y_pos,
		ss.start_x, ss.width, ss.height, ss.dpi));

#if 0 
Old stuff
	enum gl843_lamp lamp = LAMP_PLATEN;
	int lamp_to = 4;
	int start_x = 128;
	int width = 10208;
	int height = 16;
	int dpi = 4800;
	CHK(setup_ccd_and_afe(dev,
			/* fmt */ PXFMT_RGB16,
			/* start_x */ start_x,
			/* width */ width * 4800 / dpi,
			/* dpi */ dpi,
			/* afe_dpi */ 1200,
			/* linesel */ 0,
		  	/* tgtime */ 0,
			/* lperiod */ 11640,
			/* expr,g,b */ 40000, 40000, 40000));
#endif

	CHK(select_shading(dev, SHADING_CORR_OFF));

	set_reg(dev, GL843_MTRREV, 0);
	set_reg(dev, GL843_NOTHOME, 0);
	set_reg(dev, GL843_CLRLNCNT, 1);
	set_reg(dev, GL843_MTRPWR, 0);
	set_reg(dev, GL843_AGOHOME, 0);
	CHK(flush_regs(dev));

	CHK(write_afe(dev, 4, 0));
	CHK(write_afe(dev, 1, 0x23));
	CHK(write_afe(dev, 2, 0x24));
	CHK(write_afe(dev, 3, 0x2f)); /* Can be 0x1f or 0x2f */

	CHK(set_lamp(dev, LAMP_OFF, 0));
	CHK(calc_afe_blacklevel(dev, cal, 75, 0));
	CHK(set_lamp(dev, ss.source, lamp_to));
	CHK(warm_up_lamp(dev, cal));
	CHK(calc_afe_gain(dev, cal));
	CHK(calc_shading(dev, cal));
	CHK(set_lamp(dev, ss.source, lamp_to));
	CHK(send_shading(dev, cal->sc, cal->sc_len, 0));
	CHK(select_shading(dev, SHADING_CORR_AREA));
	CHK(move_scanner_head(dev, -cal_y_pos));
	CHK(wait_until_home(dev));
	CHK(write_reg(dev, GL843_MTRPWR, 0));

	free(cal);

	ret = 0;
chk_failed:
	return ret;
chk_mem_failed:
	ret = LIBUSB_ERROR_NO_MEM;
	goto chk_failed;	
}
Exemplo n.º 9
0
/* Warm up the scanner lamp and calibrate the AFE gain and offsets.
 *
 * cal_y_pos: calibration y position, distance from home [mm].
 *
 * Note: it is assumed the scanner head is in the home position
 * when this function is called.
 */
int warm_up_scanner(struct gl843_device *dev,
		    enum gl843_lamp source,
		    int lamp_timeout,
		    float cal_y_pos)
{
	int ret;
	struct scan_setup ss = {};
	struct calibration_info *cal;

	DBG(DBG_msg, "Starting warmup.\n");

	/* Move head into position */

	CHK(move_scanner_head(dev, cal_y_pos));
	CHK(wait_motor(dev));

	/* Setup scan */

	ss.source = source;
	if (source == LAMP_PLATEN) {
		ss.fmt = PXFMT_RGB16;
		ss.dpi = 1200;
		ss.start_x = 128;
		ss.width = 10208;
		ss.start_y = 5; /* Dummy value */
		ss.height = 16;
		ss.overscan = 0;
	} else {
		DBG(DBG_error, "Only platen scanning is implemented right now.\n");
		return -1;
	}

	CHK_MEM(cal = create_calinfo(ss.source, cal_y_pos,
		ss.start_x, ss.width, ss.height, ss.dpi));

	CHK(setup_static(dev));
	CHK(setup_common(dev, &ss));
	CHK(setup_horizontal(dev, &ss));
	CHK(setup_vertical(dev, &ss, 1));
	CHK(select_shading(dev, SHADING_CORR_OFF));

	/* Scan with motor and lamp off and calculate AFE black level */

	CHK(write_reg(dev, GL843_AGOHOME, 0));
	CHK(write_reg(dev, GL843_MTRPWR, 0));
	CHK(set_lamp(dev, LAMP_OFF, 0));
	CHK(calc_afe_blacklevel(dev, cal, 75, 0)); /* 75 and 0 are CS4400F-specific */

	/* Turn on the lamp, do warm up scan, and calculate AFE gain */

	CHK(set_lamp(dev, source, lamp_timeout));
	CHK(warm_up_lamp(dev, cal));
	CHK(calc_afe_gain(dev, cal));

	/* Move home when finished */

	CHK(move_scanner_head(dev, -cal_y_pos));
	CHK(wait_motor(dev));
	CHK(write_reg(dev, GL843_MTRPWR, 0));

	free(cal);

	DBG(DBG_msg, "Done.\n");
		
	ret = 0;
chk_failed:
	return ret;
chk_mem_failed:
	ret = LIBUSB_ERROR_NO_MEM;
	goto chk_failed;	
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
bool CommandShow::setup(const std::vector<std::string>& arguments) {
    po::options_description opts_cmd{"COMMAND OPTIONS"};
    opts_cmd.add_options()
    ("format-debug,d", "Use debug format")
    ("format-opl,o", "Use OPL format")
    ("format-xml,x", "Use XML format")
#ifndef _MSC_VER
    ("no-pager", "Do not run pager program")
#endif
    ("object-type,t", po::value<std::vector<std::string>>(), "Read only objects of given type (node, way, relation, changeset)")
    ("output-format,f", po::value<std::string>(), "Format of output file")
    ;

    po::options_description opts_common{add_common_options()};
    po::options_description opts_input{add_single_input_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);

    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);

    setup_common(vm, desc);
    setup_object_type_nrwc(vm);
    setup_input_file(vm);

#ifndef _MSC_VER
    if (vm.count("no-pager")) {
        m_pager = "";
    } else {
        setup_pager_from_env();
    }
#endif

    if (vm.count("output-format") &&
        vm.count("format-debug") &&
        vm.count("format-opl") &&
        vm.count("format-xml")) {
        throw argument_error("You can only use at most one of the following options: -f/--output-format, -d/--format-debug, -o/--format-opl, and -x/--format-xml.");
    }

    if (vm.count("output-format")) {
        m_output_format = vm["output-format"].as<std::string>();
    } else if (vm.count("format-debug")) {
        m_output_format = "debug,color=true";
    } else if (vm.count("format-opl")) {
        m_output_format = "opl";
    } else if (vm.count("format-xml")) {
        m_output_format = "xml";
    } else {
        const char* output_format_from_env = ::getenv("OSMIUM_SHOW_FORMAT");
        if (output_format_from_env) {
            m_output_format = output_format_from_env;
        }
    }

    return true;
}