コード例 #1
0
ファイル: main.cpp プロジェクト: gravitystorm/osmi-addresses
int main(int argc, char* argv[]) {

	if (argc < 2 || argc > 3) {
		std::cerr << "Usage: " << argv[0] << " INFILE [OUTFILE]" << std::endl;
		exit(1);
	}

	std::string input_filename(argv[1]);
	std::string output_filename;
	if (argc != 3) {
		output_filename = std::string("out.sqlite");
	} else {
		output_filename = std::string(argv[2]);
	}

	{
	// from http://stackoverflow.com/questions/1647557/ifstream-how-to-tell-if-specified-file-doesnt-exist/3071528#3071528
	struct stat file_info;
	if (stat(output_filename.c_str(), &file_info) == 0) {
		std::cerr << "ERROR: Output file '" << output_filename << "' exists. Aborting..." << std::endl;
		exit(1);
	}
	}

	std::set<osmium::unsigned_object_id_type> addr_interpolation_node_set;
	name2highways_type name2highway;

	index_pos_type index_pos;
	index_neg_type index_neg;
	location_handler_type location_handler(index_pos, index_neg);
	//location_handler.ignore_errors();

	MemHelper mem_helper;
	//mem_helper.start();
	{
	osmium::io::Reader reader(input_filename);

	FirstHandler first_handler(addr_interpolation_node_set, name2highway);

	osmium::apply(reader, location_handler, first_handler);
	reader.close();
	}
	//mem_helper.stop();

	osmium::io::Reader reader2(input_filename);
	SecondHandler second_handler(output_filename, addr_interpolation_node_set, name2highway);
	osmium::apply(reader2, location_handler, second_handler);
	reader2.close();

	google::protobuf::ShutdownProtobufLibrary();

	std::cout << std::endl;
	mem_helper.print_max();

	std::cout << "\nsoftware finished properly\n" << std::endl;
	return 0;
}
コード例 #2
0
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " INFILE\n";
        exit(1);
    }

    std::string output_format("SQLite");
    std::string input_filename(argv[1]);
    std::string output_filename("multipolygon.db");

    OGRDataSource* data_source = initialize_database(output_format, output_filename);

    osmium::area::ProblemReporterOGR problem_reporter(data_source);
    osmium::area::Assembler::config_type assembler_config(&problem_reporter);
    assembler_config.enable_debug_output();
    osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);

    std::cerr << "Pass 1...\n";
    osmium::io::Reader reader1(input_filename);
    collector.read_relations(reader1);
    reader1.close();
    std::cerr << "Pass 1 done\n";

    index_type index_pos;
    index_type index_neg;
    location_handler_type location_handler(index_pos, index_neg);
    location_handler.ignore_errors();

    TestHandler test_handler(data_source);

    std::cerr << "Pass 2...\n";
    osmium::io::Reader reader2(input_filename);
    osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
        osmium::apply(area_buffer, test_handler);
    }));
    reader2.close();
    std::cerr << "Pass 2 done\n";

    OGRDataSource::DestroyDataSource(data_source);
    OGRCleanupAll();
}
コード例 #3
0
int main(int argc, char* argv[]) {
    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " INFILE\n";
        exit(1);
    }

    std::string output_format("SQLite");
    std::string input_filename(argv[1]);
    std::string output_filename("testdata-overview.db");
    ::unlink(output_filename.c_str());

    osmium::io::Reader reader(input_filename);

    index_type index;
    location_handler_type location_handler(index);
    location_handler.ignore_errors();

    TestOverviewHandler handler(output_format, output_filename);

    osmium::apply(reader, location_handler, handler);
    reader.close();
}
コード例 #4
0
int main(int argc, char* argv[]) {
    static struct option long_options[] = {
        {"help",         no_argument, 0, 'h'},
        {"dump-wkt",     no_argument, 0, 'w'},
        {"dump-objects", no_argument, 0, 'o'},
        {0, 0, 0, 0}
    };

    osmium::handler::DynamicHandler handler;

    while (true) {
        int c = getopt_long(argc, argv, "hwo", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
            case 'h':
                print_help();
                exit(0);
            case 'w':
                handler.set<WKTDump>(std::cout);
                break;
            case 'o':
                handler.set<osmium::handler::Dump>(std::cout);
                break;
            default:
                exit(1);
        }
    }

    int remaining_args = argc - optind;
    if (remaining_args != 1) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSMFILE\n";
        exit(1);
    }

    osmium::io::File infile(argv[optind]);

    osmium::area::Assembler::config_type assembler_config;
    osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);

    std::cout << "Pass 1...\n";
    osmium::io::Reader reader1(infile, osmium::osm_entity_bits::relation);
    collector.read_relations(reader1);
    reader1.close();
    std::cout << "Pass 1 done\n";

    std::cout << "Memory:\n";
    collector.used_memory();

    index_pos_type index_pos;
    index_neg_type index_neg;
    location_handler_type location_handler(index_pos, index_neg);
    location_handler.ignore_errors(); // XXX

    std::cout << "Pass 2...\n";
    osmium::io::Reader reader2(infile);
    osmium::apply(reader2, location_handler, collector.handler([&handler](osmium::memory::Buffer&& buffer) {
        osmium::apply(buffer, handler);
    }));
    reader2.close();
    std::cout << "Pass 2 done\n";

    std::cout << "Memory:\n";
    collector.used_memory();

    std::vector<const osmium::Relation*> incomplete_relations = collector.get_incomplete_relations();
    if (!incomplete_relations.empty()) {
        std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
        for (const auto* relation : incomplete_relations) {
            std::cerr << " " << relation->id();
        }
        std::cerr << "\n";
    }
}
コード例 #5
0
ファイル: osmium_toogr2_exp.cpp プロジェクト: ipaddr/omim
int main(int argc, char* argv[]) {
    static struct option long_options[] = {
        {"help",   no_argument, 0, 'h'},
        {"format", required_argument, 0, 'f'},
        {0, 0, 0, 0}
    };

    std::string output_format("SQLite");

    while (true) {
        int c = getopt_long(argc, argv, "hf:", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
        case 'h':
            print_help();
            exit(0);
        case 'f':
            output_format = optarg;
            break;
        default:
            exit(1);
        }
    }

    std::string input_filename;
    std::string output_filename("ogr_out");
    int remaining_args = argc - optind;
    if (remaining_args > 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
        exit(1);
    } else if (remaining_args == 2) {
        input_filename =  argv[optind];
        output_filename = argv[optind+1];
    } else if (remaining_args == 1) {
        input_filename =  argv[optind];
    } else {
        input_filename = "-";
    }

    index_type index_pos;
    location_handler_type location_handler(index_pos);
    osmium::experimental::FlexReader<location_handler_type> exr(input_filename, location_handler, osmium::osm_entity_bits::object);

    MyOGRHandler ogr_handler(output_format, output_filename);

    while (auto buffer = exr.read()) {
        osmium::apply(buffer, ogr_handler);
    }

    exr.close();

    std::vector<const osmium::Relation*> incomplete_relations = exr.collector().get_incomplete_relations();
    if (!incomplete_relations.empty()) {
        std::cerr << "Warning! Some member ways missing for these multipolygon relations:";
        for (const auto* relation : incomplete_relations) {
            std::cerr << " " << relation->id();
        }
        std::cerr << "\n";
    }

    google::protobuf::ShutdownProtobufLibrary();
}
コード例 #6
0
ファイル: osmium_toogr.cpp プロジェクト: 7890/osrm-backend
int main(int argc, char* argv[]) {
    const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();

    static struct option long_options[] = {
        {"help",                 no_argument, 0, 'h'},
        {"format",               required_argument, 0, 'f'},
        {"location_store",       required_argument, 0, 'l'},
        {"list_location_stores", no_argument, 0, 'L'},
        {0, 0, 0, 0}
    };

    std::string output_format { "SQLite" };
    std::string location_store { "sparse_mem_array" };

    while (true) {
        int c = getopt_long(argc, argv, "hf:l:L", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
            case 'h':
                print_help();
                exit(0);
            case 'f':
                output_format = optarg;
                break;
            case 'l':
                location_store = optarg;
                break;
            case 'L':
                std::cout << "Available map types:\n";
                for (const auto& map_type : map_factory.map_types()) {
                    std::cout << "  " << map_type << "\n";
                }
                exit(0);
            default:
                exit(1);
        }
    }

    std::string input_filename;
    std::string output_filename("ogr_out");
    int remaining_args = argc - optind;
    if (remaining_args > 2) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] [INFILE [OUTFILE]]" << std::endl;
        exit(1);
    } else if (remaining_args == 2) {
        input_filename =  argv[optind];
        output_filename = argv[optind+1];
    } else if (remaining_args == 1) {
        input_filename =  argv[optind];
    } else {
        input_filename = "-";
    }

    osmium::io::Reader reader(input_filename);

    std::unique_ptr<index_pos_type> index_pos = map_factory.create_map(location_store);
    index_neg_type index_neg;
    location_handler_type location_handler(*index_pos, index_neg);
    location_handler.ignore_errors();

    MyOGRHandler ogr_handler(output_format, output_filename);

    osmium::apply(reader, location_handler, ogr_handler);
    reader.close();

    int locations_fd = open("locations.dump", O_WRONLY | O_CREAT, 0644);
    if (locations_fd < 0) {
        throw std::system_error(errno, std::system_category(), "Open failed");
    }
    index_pos->dump_as_list(locations_fd);
    close(locations_fd);
}
コード例 #7
0
int main(int argc, char* argv[]) {
    const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();

    static struct option long_options[] = {
        {"help",                       no_argument, 0, 'h'},
        {"location_store",       required_argument, 0, 'l'},
        {"list_location_stores",       no_argument, 0, 'L'},
        {"nodes",                required_argument, 0, 'n'},
        {"zoom",                 required_argument, 0, 'z'},
        {0, 0, 0, 0}
    };

    std::string input_filename = "-";
    std::string location_store = "sparse_file_array,locations.dump";
    std::string locations_dump_file;
    bool nodes_dense = false;
    int zoom = 15;

    while (true) {
        int c = getopt_long(argc, argv, "hl:Ln:z", long_options, 0);
        if (c == -1) {
            break;
        }

        switch (c) {
            case 'h':
                print_help();
                exit(0);
            case 'l':
                location_store = optarg;
                break;
            case 'L':
                std::cout << "Available map types:\n";
                for (const auto& map_type : map_factory.map_types()) {
                    std::cout << "  " << map_type << "\n";
                }
                exit(0);
            case 'n':
                if (!strcmp(optarg, "sparse")) {
                    nodes_dense = false;
                } else if (!strcmp(optarg, "dense")) {
                    nodes_dense = true;
                } else {
                    std::cerr << "Set --nodes, -n to 'sparse' or 'dense'\n";
                    exit(1);
                }
                break;
            case 'z':
                zoom = atoi(optarg);
                break;
            default:
                exit(1);
        }
    }

    if (location_store.empty()) {
        location_store = nodes_dense ? "dense" : "sparse";
        location_store.append("_file_array,locations.dump");
    }

    std::cerr << "Using the '" << location_store << "' location store. Use -l or -n to change this.\n";

    int remaining_args = argc - optind;
    if (remaining_args > 1) {
        std::cerr << "Usage: " << argv[0] << " [OPTIONS] OSM-CHANGE-FILE\n";
        exit(1);
    } else if (remaining_args == 1) {
        input_filename = argv[optind];
        std::cerr << "Reading from '" << input_filename << "'...\n";
    } else {
        input_filename = "-";
        std::cerr << "Reading from STDIN...\n";
    }

    osmium::io::File input_file(input_filename);
    osmium::io::Reader reader(input_file);

    std::unique_ptr<index_type> old_index = map_factory.create_map(location_store);
    std::unique_ptr<index_type> tmp_index = map_factory.create_map("sparse_mem_array");
    location_handler_type location_handler(*tmp_index);
    location_handler.ignore_errors();

    TileDiffHandler tile_diff_handler(zoom, *old_index, *tmp_index);

    osmium::apply(reader, location_handler, tile_diff_handler);
    reader.close();

    tile_diff_handler.dump_tiles();
}
コード例 #8
0
ファイル: main.cpp プロジェクト: osmcode/osmium-contrib
OGREnvelope extract(
        Options& options,
        osmium::geom::OGRFactory<osmium::geom::Projection>& factory,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> begin,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> relations,
        osmium::memory::Buffer::t_iterator<osmium::OSMObject> end,
        osmium::Timestamp point_in_time) {

    options.vout << "Working on " << point_in_time << "...\n";
    options.vout << "  Filtering data...\n";

    // nodes and ways
    using diff_iterator = osmium::DiffIterator<osmium::memory::Buffer::t_iterator<osmium::OSMObject>>;
    osmium::memory::Buffer fbuffer{initial_buffer_size, osmium::memory::Buffer::auto_grow::yes};
    {
        const diff_iterator dbegin{begin, relations};
        const diff_iterator dend{relations, relations};

        std::for_each(dbegin, dend, [point_in_time, &fbuffer](const osmium::DiffObject& d) {
            if (d.is_visible_at(point_in_time)) {
                fbuffer.add_item(d.curr());
                fbuffer.commit();
            }
        });
    }
    options.vout << "  Done. Filtered data needs "
                 << (fbuffer.committed() / (1024 * 1024))
                 << " MBytes.\n";

    // relations
    osmium::memory::Buffer rbuffer(initial_buffer_size, osmium::memory::Buffer::auto_grow::yes);
    {
        const diff_iterator dbegin{relations, end};
        const diff_iterator dend{end, end};

        std::for_each(dbegin, dend, [point_in_time, &rbuffer](const osmium::DiffObject& d) {
            if (d.is_visible_at(point_in_time)) {
                rbuffer.add_item(d.curr());
                rbuffer.commit();
            }
        });
    }

    osmium::area::AssemblerLegacy::config_type assembler_config;
    osmium::area::MultipolygonManagerLegacy<osmium::area::AssemblerLegacy> mp_manager{assembler_config};

    options.vout << "  Reading relations...\n";
    osmium::apply(rbuffer, mp_manager);
    mp_manager.prepare_for_lookup();

    index_type index_pos;
    location_handler_type location_handler(index_pos);
    location_handler.ignore_errors();

    options.vout << "  Creating geometries...\n";
    const std::string date = point_in_time.to_iso().substr(0, 10);

    std::vector<std::string> datasource_options;
    std::string datasource_name{options.output_directory + "/" + date};
    if (options.output_format == "GeoJSON") {
        datasource_name += ".json";
    } else if (options.output_format == "SQLite") {
        datasource_name += ".db";
        datasource_options.push_back("SPATIALITE=TRUE");
        CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
        CPLSetConfigOption("OGR_SQLITE_CACHE", "512");
    }

    gdalcpp::Dataset dataset{options.output_format, datasource_name, gdalcpp::SRS{factory.proj_string()}, datasource_options};

#ifdef HANDLER
    HANDLER geom_handler{factory, dataset, date};
#else
    BuildingsHandler geom_handler{factory, dataset, date};
#endif
    osmium::apply(fbuffer.begin(),
                  fbuffer.end(),
                  location_handler,
                  geom_handler,
                  mp_manager.handler([&geom_handler](const osmium::memory::Buffer& buffer) {
        osmium::apply(buffer, geom_handler);
    }));

    return geom_handler.envelope();
}