Пример #1
0
void test_outputs()
{
    const char* a1[] = {"osm2pgsql", "-O", "pgsql", "--style", "default.style", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options_t options = options_t(len(a1), const_cast<char **>(a1));
    std::shared_ptr<middle_t> mid = middle_t::create_middle(options.slim);
    std::vector<std::shared_ptr<output_t> > outs = output_t::create_outputs(mid.get(), options);
    output_t* out = outs.front().get();
    if(dynamic_cast<output_pgsql_t *>(out) == nullptr)
    {
        throw std::logic_error("Expected a pgsql output");
    }

    const char* a2[] = {"osm2pgsql", "-O", "gazetteer", "--style", "default.style", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options = options_t(len(a2), const_cast<char **>(a2));
    mid = middle_t::create_middle(options.slim);
    outs = output_t::create_outputs(mid.get(), options);
    out = outs.front().get();
    if(dynamic_cast<output_gazetteer_t *>(out) == nullptr)
    {
        throw std::logic_error("Expected a gazetteer output");
    }

    const char* a3[] = {"osm2pgsql", "-O", "null", "--style", "default.style", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options = options_t(len(a3), const_cast<char **>(a3));
    mid = middle_t::create_middle(options.slim);
    outs = output_t::create_outputs(mid.get(), options);
    out = outs.front().get();
    if(dynamic_cast<output_null_t *>(out) == nullptr)
    {
        throw std::logic_error("Expected a null output");
    }

    const char* a4[] = {"osm2pgsql", "-O", "keine_richtige_ausgabe", "--style", "default.style", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options = options_t(len(a4), const_cast<char **>(a4));
    mid = middle_t::create_middle(options.slim);
    try
    {
        outs = output_t::create_outputs(mid.get(), options);
        out = outs.front().get();
        throw std::logic_error("Expected 'not recognised'");
    }
    catch(const std::runtime_error& e)
    {
        if(!alg::icontains(e.what(), "not recognised"))
            throw std::logic_error((boost::format("Expected 'not recognised' but instead got '%2%'") % e.what()).str());
    }
}
Пример #2
0
void test_middles()
{
    const char* a1[] = {"osm2pgsql", "--slim", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options_t options = options_t(len(a1), const_cast<char **>(a1));
    std::shared_ptr<middle_t> mid = middle_t::create_middle(options.slim);
    if(dynamic_cast<middle_pgsql_t *>(mid.get()) == nullptr)
    {
        throw std::logic_error("Using slim mode we expected a pgsql middle");
    }

    const char* a2[] = {"osm2pgsql", "tests/liechtenstein-2013-08-03.osm.pbf"};
    options = options_t(len(a2), const_cast<char **>(a2));
    mid = middle_t::create_middle(options.slim);
    if(dynamic_cast<middle_ram_t *>(mid.get()) == nullptr)
    {
        throw std::logic_error("Using without slim mode we expected a ram middle");
    }
}
Пример #3
0
void parse_fail(const int argc, const char* argv[], const std::string& fail_message)
{
    try
    {
        options_t options = options_t(argc, const_cast<char **>(argv));
        throw std::logic_error((boost::format("Expected '%1%'") % fail_message).str());
    }
    catch(const std::runtime_error& e)
    {
        if(!alg::icontains(e.what(), fail_message))
            throw std::logic_error((boost::format("Expected '%1%' but instead got '%2%'") % fail_message % e.what()).str());
    }
}
Пример #4
0
zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_)
{
    scoped_lock_t locker(endpoints_sync);

    endpoints_t::iterator it = endpoints.find (addr_);
    if (it == endpoints.end ()) {
        errno = ECONNREFUSED;
        endpoint_t empty = {NULL, options_t()};
        return empty;
     }
     endpoint_t endpoint = it->second;

     //  Increment the command sequence number of the peer so that it won't
     //  get deallocated until "bind" command is issued by the caller.
     //  The subsequent 'bind' has to be called with inc_seqnum parameter
     //  set to false, so that the seqnum isn't incremented twice.
     endpoint.socket->inc_seqnum ();

     return endpoint;
}
Пример #5
0
std::string calc_var_content_string(const calc_var_t& var)
{
    auto func = tivars::TypeHandlerFuncGetter::getStringFromDataFunc((int)var.type);
    return func(data_t(var.data, var.data + var.size), options_t());
}
Пример #6
0
int main(int argc, char *argv[])
{
    fprintf(stderr, "osm2pgsql version %s (%zu bit id space)\n\n", VERSION, 8 * sizeof(osmid_t));
    try
    {
        //parse the args into the different options members
        options_t options = options_t(argc, argv);
        if(options.long_usage_bool)
            return 0;

        //setup the middle
        std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim);

        //setup the backend (output)
        std::vector<std::shared_ptr<output_t> > outputs = output_t::create_outputs(middle.get(), options);

        //let osmdata orchestrate between the middle and the outs
        osmdata_t osmdata(middle, outputs, options.projection);

        fprintf(stderr, "Using projection SRS %d (%s)\n",
                options.projection->target_srs(),
                options.projection->target_desc());

        //start it up
        time_t overall_start = time(nullptr);
        osmdata.start();

        /* Processing
         * In this phase the input file(s) are read and parsed, populating some of the
         * tables. Not all ways can be handled before relations are processed, so they're
         * set as pending, to be handled in the next stage.
         */
        parse_stats_t stats;
        //read in the input files one by one
        for (auto const filename : options.input_files) {
            //read the actual input
            fprintf(stderr, "\nReading in file: %s\n", filename.c_str());
            time_t start = time(nullptr);

            parse_osmium_t parser(options.bbox, options.append, &osmdata);
            parser.stream_file(filename, options.input_reader);

            stats.update(parser.stats());

            fprintf(stderr, "  parse time: %ds\n", (int)(time(nullptr) - start));
        }

        //show stats
        stats.print_summary();

        //Process pending ways, relations, cluster, and create indexes
        osmdata.stop();

        fprintf(stderr, "\nOsm2pgsql took %ds overall\n", (int)(time(nullptr) - overall_start));

        return 0;
    }//something went wrong along the way
    catch(const std::runtime_error& e)
    {
        fprintf(stderr, "Osm2pgsql failed due to ERROR: %s\n", e.what());
        exit(EXIT_FAILURE);
    }
}
Пример #7
0
void test_random_perms()
{

    for(int i = 0; i < 5; ++i)
    {
        options_t options;
        std::vector<std::string> args;
        args.push_back("osm2pgsql");

        //pick a projection
        options.projection.reset(reprojection::create_projection(get_random_proj(args)));

        //pick a style file
        std::string style = get_random_string(15);
        options.style = style.c_str();
        args.push_back("--style");
        args.push_back(style);

        add_arg_and_val_or_not("--cache", args, options.cache, rand() % 800);
        add_arg_and_val_or_not("--database", args, options.database_options.db.c_str(), get_random_string(6));
        if (options.database_options.username) {
            add_arg_and_val_or_not("--username", args, options.database_options.username->c_str(), get_random_string(6));
        }
        if (options.database_options.host) {
            add_arg_and_val_or_not("--host", args, options.database_options.host->c_str(), get_random_string(6));
        }
        //add_arg_and_val_or_not("--port", args, options.port, rand() % 9999);

        //--hstore-match-only
        //--hstore-column   Add an additional hstore (key/value) column containing all tags that start with the specified string, eg --hstore-column "name:" will produce an extra hstore column that contains all name:xx tags

        add_arg_or_not("--hstore-add-index", args, options.enable_hstore_index);

        //--tablespace-index    The name of the PostgreSQL tablespace where all indexes will be created. The following options allow more fine-grained control:
        //      --tablespace-main-data    tablespace for main tables
        //      --tablespace-main-index   tablespace for main table indexes
        //      --tablespace-slim-data    tablespace for slim mode tables
        //      --tablespace-slim-index   tablespace for slim mode indexes
        //                    (if unset, use db's default; -i is equivalent to setting
        //                    --tablespace-main-index and --tablespace-slim-index)

        add_arg_and_val_or_not("--number-processes", args, options.num_procs, rand() % 12);

        //add_arg_or_not("--disable-parallel-indexing", args, options.parallel_indexing);

        add_arg_or_not("--unlogged", args, options.unlogged);

        //--cache-strategy  Specifies the method used to cache nodes in ram. Available options are: dense chunk sparse optimized

        if (options.flat_node_file) {
            add_arg_and_val_or_not("--flat-nodes", args, options.flat_node_file->c_str(), get_random_string(15));
        }

        //--expire-tiles [min_zoom-]max_zoom    Create a tile expiry list.

        add_arg_and_val_or_not("--expire-output", args, options.expire_tiles_filename.c_str(), get_random_string(15));

        //--bbox        Apply a bounding box filter on the imported data Must be specified as: minlon,minlat,maxlon,maxlat e.g. --bbox -0.5,51.25,0.5,51.75

        add_arg_and_val_or_not("--prefix", args, options.prefix.c_str(), get_random_string(15));

        //--input-reader    Input frontend. auto, o5m, xml, pbf

        if (options.tag_transform_script) {
            add_arg_and_val_or_not("--tag-transform-script", args, options.tag_transform_script->c_str(), get_random_string(15));
        }
        add_arg_or_not("--extra-attributes", args, options.extra_attributes);
        add_arg_or_not("--multi-geometry", args, options.enable_multi);
        add_arg_or_not("--keep-coastlines", args, options.keep_coastlines);
        add_arg_or_not("--exclude-invalid-polygon", args, options.excludepoly);

        //add the input file
        args.push_back("tests/liechtenstein-2013-08-03.osm.pbf");

        const char** argv = new const char*[args.size() + 1];
        argv[args.size()] = nullptr;
        for(std::vector<std::string>::const_iterator arg = args.begin(); arg != args.end(); ++arg)
            argv[arg - args.begin()] = arg->c_str();
        options_t((int) args.size(), const_cast<char **>(argv));
        delete[] argv;
    }
}