Skip to content

Commit fcb6f12

Browse files
committed
ASaving osmium stuff
1 parent c9858b7 commit fcb6f12

2 files changed

Lines changed: 50 additions & 19 deletions

File tree

getgraph/src/getgraph.cpp

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ class NodeCount : public osmium::handler::Handler {
157157
{
158158
}
159159

160+
NodeCount(std::map<int64_t, size_t> &node_count, std::string connInfo, const std::string &schema) :
161+
m_node_count(node_count),
162+
m_node_conn(connInfo),
163+
m_node_action(m_node_conn),
164+
m_node_stream(pqxx::stream_to::table(m_node_action, {schema, "osm_nodes"}, {"osm_id", "name", "osm_tags", "geom"})),
165+
m_way_conn(connInfo),
166+
m_way_action(m_way_conn),
167+
m_way_stream(pqxx::stream_to::table(m_way_action, {schema, "osm_ways"}, {"osm_id", "name", "osm_tags", "geom"}))
168+
{
169+
std::clog << __PRETTY_FUNCTION__ << "\n";
170+
}
171+
160172

161173
void node(const osmium::Node& node) {
162174
/*
@@ -286,7 +298,6 @@ class NodeCount : public osmium::handler::Handler {
286298
pqxx::connection m_way_conn;
287299
pqxx::work m_way_action;
288300
pqxx::stream_to m_way_stream;
289-
290301
};
291302

292303
class SplitWays : public osmium::handler::Handler {
@@ -502,28 +513,43 @@ int main(int argc, char *argv[]) {
502513
* start a transaction
503514
*/
504515
pqxx::work create_tables(dbconn);
505-
std::string sql = "DROP TABLE IF EXISTS new_osm_nodes";
516+
517+
auto osm(vm.count("osm"));
518+
std::clog << osm << "\n";
519+
auto osm_nodes_table = vm["osm_schema"].as<std::string>() + ".osm_nodes";
520+
auto osm_ways_table = vm["osm_schema"].as<std::string>() + ".osm_ways";
521+
522+
std::string sql = "DROP TABLE IF EXISTS " + osm_nodes_table;
506523
create_tables.exec(sql);
507-
sql = "DROP TABLE IF EXISTS new_osm_ways";
524+
sql = "DROP TABLE IF EXISTS " + osm_ways_table;
508525
create_tables.exec(sql);
526+
509527
sql = "DROP TABLE IF EXISTS edges";
510528
create_tables.exec(sql);
511529
sql = "DROP TABLE IF EXISTS vertices";
512530
create_tables.exec(sql);
513-
sql = "CREATE TABLE IF NOT EXISTS new_osm_nodes("
514-
"id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
515-
"osm_id BIGINT,"
516-
"name TEXT,"
517-
"osm_tags hstore,"
518-
"geom GEOMETRY(POINT, 4326));";
519-
create_tables.exec(sql);
520-
sql = "CREATE TABLE IF NOT EXISTS new_osm_ways("
521-
"id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
522-
"osm_id BIGINT,"
523-
"name TEXT,"
524-
"osm_tags hstore,"
525-
"geom GEOMETRY(LINESTRING, 4326));";
526-
create_tables.exec(sql);
531+
if (osm) {
532+
std::clog << "Creating 'osm' tables\n";
533+
sql = "CREATE SCHEMA IF NOT EXISTS " + vm["osm_schema"].as<std::string>();
534+
create_tables.exec(sql);
535+
std::clog << "Created 'osm' schema\n";
536+
sql = "CREATE TABLE IF NOT EXISTS " + osm_nodes_table + "("
537+
"id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
538+
"osm_id BIGINT,"
539+
"name TEXT,"
540+
"osm_tags hstore,"
541+
"geom GEOMETRY(POINT, 4326));";
542+
create_tables.exec(sql);
543+
std::clog << "Created '" + osm_nodes_table << "' table\n";
544+
sql = "CREATE TABLE IF NOT EXISTS " + osm_ways_table + "("
545+
"id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
546+
"osm_id BIGINT,"
547+
"name TEXT,"
548+
"osm_tags hstore,"
549+
"geom GEOMETRY(LINESTRING, 4326));";
550+
create_tables.exec(sql);
551+
std::clog << "Created '" + osm_ways_table << "' table\n";
552+
}
527553
sql = "CREATE TABLE IF NOT EXISTS edges("
528554
"id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,"
529555
"source BIGINT,"
@@ -574,7 +600,9 @@ int main(int argc, char *argv[]) {
574600
/*
575601
* Create the handler
576602
*/
577-
NodeCount node_count_handler(node_count, connection_str);
603+
NodeCount node_count_handler = osm? NodeCount(node_count, connection_str, vm["osm_schema"].as<std::string>()):
604+
605+
578606

579607
// Apply the handler to the reader
580608
std::clog << "Starting OSM node count processing..." << std::endl;

getgraph/src/options.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace po = boost::program_options;
3232

3333
void get_option_description(po::options_description &od_desc) {
3434
constexpr int CHUNK = 20000;
35+
const std::string OSM_SCHEMA = "osm";
3536

3637
/* po::options_description help_od_desc("Help"),
3738
required_od_desc("Required options"),
@@ -57,7 +58,9 @@ void get_option_description(po::options_description &od_desc) {
5758
#if 0
5859
("postgis", "Install postgis if not found.") // TODO(vicky) remove before realesing
5960
#endif
60-
("addnodes", "Import the osm_nodes, osm_ways & osm_relations tables.")
61+
("osm", "Import the osm_nodes, osm_ways & osm_relations tables.")
62+
("osm_schema", po::value<std::string>()->default_value(OSM_SCHEMA), "Schema for osm tables. Ignored when `osm` is not set")
63+
6164
("attributes", "Include attributes information.")
6265
("tags", "Include tag information.")
6366
("chunk", po::value<std::size_t>()->default_value(CHUNK), "Exporting chunk size.")

0 commit comments

Comments
 (0)