Skip to content

Commit ec2a37d

Browse files
committed
Revert "first attempt at adding pgrouting output format"
This reverts commit 0e2966d.
1 parent 7c14e73 commit ec2a37d

File tree

3 files changed

+26
-75
lines changed

3 files changed

+26
-75
lines changed

main.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ main(int argc, char** argv)
170170
("help,h", "produce help message")
171171
("version,v", "show version")
172172
("in-format", po::value<string>(&informat)->default_value("auto"), "input data format:\n auto: \tguess from file extension. If no input file is given, read from stdin\n bz2: \tbzip2 compressed file\n stdin: \tstandart input\n osm: \tuncompressed XML file")
173-
("out-format", po::value<string>(&outformat)->default_value("csv"), "output data format:\n csv: \tnodes and edges as csv files\n pg: \tpostgres/postgis database. The database MUST be a postgis geographical database\n pgr: \tpostgres postgis database with edges formatted for pgrouting package. uses same pg options\n")
173+
("out-format", po::value<string>(&outformat)->default_value("csv"), "output data format:\n csv: \tnodes and edges as csv files\n pg: \tpostgres/postgis database. The database MUST be a postgis geographical database")
174174
;
175175

176176
string pg_conn, pg_nodes, pg_edges;
@@ -289,8 +289,8 @@ main(int argc, char** argv)
289289

290290
//===================== STEP 2 ==========================//
291291
Writer * writer;
292-
if(outformat == "pg" || outformat == "pgr")
293-
writer = new PqWriter(pg_conn, pg_nodes, pg_edges, outformat);
292+
if(outformat == "pg")
293+
writer = new PqWriter(pg_conn, pg_nodes, pg_edges);
294294
else if (outformat == "csv")
295295
writer = new CSVWriter(csv_nodes, csv_edges);
296296
cout << "Step 2: building edges and saving them" << endl;

pqwriter.cc

+22-70
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
using boost::lexical_cast;
2323

24-
PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table, const std::string & edges_table, bool drop_table, const std::string & format) :
24+
PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table, const std::string & edges_table, bool drop_table) :
2525
nodes_table(nodes_table),
2626
edges_table(edges_table),
2727
drop_table(drop_table)
@@ -55,23 +55,14 @@ PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table
5555
std::cerr << "Unable to drop table " << nodes_table << PQerrorMessage(conn) << std::endl;
5656
}
5757
PQclear(res);
58-
5958
res = PQexec(conn, ("CREATE TABLE " + nodes_table + " (ID bigint, lon double precision, lat double precision)").c_str());
6059
if (PQresultStatus(res) != PGRES_COMMAND_OK)
6160
{
6261
std::cerr << "Unable to create table " << nodes_table << PQerrorMessage(conn) << std::endl;
6362
}
6463
PQclear(res);
6564

66-
if(format == "pg")
67-
{
68-
res = PQexec(conn, ("CREATE TABLE " + edges_table + " (ID integer, source bigint, target bigint, length double precision, car smallint, car_rev smallint, bike smallint, bike_rev smallint, foot smallint)").c_str());
69-
}
70-
else if(format == "pgr")
71-
{
72-
res = PQexec(conn, ("CREATE TABLE " + edges_table + " (ID integer, source bigint, x1 float, y1 float, target bigint, x2 float, y2 float, length double precision, to_cost double precision, reverse_cost double precision, rule text, car smallint, car_rev smallint, bike smallint, bike_rev smallint, foot smallint)").c_str());
73-
}
74-
65+
res = PQexec(conn, ("CREATE TABLE " + edges_table + " (ID integer, source bigint, target bigint, length double precision, car smallint, car_rev smallint, bike smallint, bike_rev smallint, foot smallint)").c_str());
7566
if (PQresultStatus(res) != PGRES_COMMAND_OK)
7667
{
7768
std::cerr << "Unable to create table " << edges_table << PQerrorMessage(conn) << std::endl;
@@ -85,33 +76,19 @@ PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table
8576
}
8677
PQclear(res);
8778

88-
res = PQexec(conn, ("SELECT AddGeometryColumn('" + edges_table + "','the_geom',4326,'LINESTRING',2)").c_str());
79+
res = PQexec(conn, ("SELECT AddGeometryColumn('" + edges_table + "','the_geom',4326,'LINESTRING',2)").c_str());
8980
if (PQresultStatus(res) != PGRES_TUPLES_OK)
9081
{
9182
std::cerr << "Unable to add a geometry column on table " << edges_table << PQerrorMessage(conn) << std::endl;
9283
}
9384
PQclear(res);
9485
}
9586

96-
if(format == "pg")
97-
{
98-
res = PQprepare(conn,
87+
res = PQprepare(conn,
9988
"add_edge",
100-
("INSERT INTO " + edges_table +
101-
" VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)").c_str() ,
89+
("INSERT INTO " + edges_table + " VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)").c_str() ,
10290
0,
10391
NULL);
104-
}
105-
else if(format == "pgr")
106-
{
107-
res = PQprepare(conn,
108-
"add_edge",
109-
("INSERT INTO " + edges_table + " (ID, source, x1, y1, target, x2, y2, length, reverse_cost, car,
110-
car_rev, bike, bike_rev, foot) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)").c_str() ,
111-
0,
112-
NULL);
113-
}
114-
11592
if (PQresultStatus(res) != PGRES_COMMAND_OK)
11693
{
11794
std::cerr << "Unable to prepare SQL query for adding edges in table " << edges_table << PQerrorMessage(conn) << std::endl;
@@ -137,6 +114,9 @@ PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table
137114
}
138115
PQclear(res);
139116

117+
118+
119+
140120
}
141121

142122
int PqWriter::save_nodes(const NodeMapType & nodes)
@@ -184,48 +164,20 @@ void PqWriter::save_edge(int edge_id,
184164

185165
PGresult * res;
186166
std::string tmp_geom = "SRID=4326;LINESTRING(" + geom + ")";
187-
188-
if(format == "pg")
189-
{
190-
const char * params[10] = {
191-
lexical_cast<std::string>(edge_id).c_str(),
192-
lexical_cast<std::string>(source).c_str(),
193-
lexical_cast<std::string>(target).c_str(),
194-
lexical_cast<std::string>(length).c_str(),
195-
lexical_cast<std::string>(car).c_str(),
196-
lexical_cast<std::string>(car_d).c_str(),
197-
lexical_cast<std::string>(bike).c_str(),
198-
lexical_cast<std::string>(bike_d).c_str(),
199-
lexical_cast<std::string>(foot).c_str(),
200-
tmp_geom.c_str()
201-
};
202-
203-
res = PQexecPrepared(conn, "add_edge", 10, params, NULL, NULL, 0);
204-
}
205-
else if(format == "pgr")
206-
{
207-
const char * params[14] = {
208-
lexical_cast<std::string>(edge_id).c_str(),
209-
lexical_cast<std::string>(source).c_str(),
210-
lexical_cast<std::string>(source.lon).c_str(),
211-
lexical_cast<std::string>(source.lat).c_str(),
212-
lexical_cast<std::string>(target).c_str(),
213-
lexical_cast<std::string>(target.lon).c_str(),
214-
lexical_cast<std::string>(target.lat).c_str(),
215-
lexical_cast<std::string>(length).c_str(),
216-
lexical_cast<std::string>(length).c_str(),
217-
lexical_cast<std::string>(car).c_str(),
218-
lexical_cast<std::string>(car_d).c_str(),
219-
lexical_cast<std::string>(bike).c_str(),
220-
lexical_cast<std::string>(bike_d).c_str(),
221-
lexical_cast<std::string>(foot).c_str(),
222-
tmp_geom.c_str()
223-
};
224-
225-
res = PQexecPrepared(conn, "add_edge", 14, params, NULL, NULL, 0);
226-
}
227-
228-
167+
const char * params[10] = {
168+
lexical_cast<std::string>(edge_id).c_str(),
169+
lexical_cast<std::string>(source).c_str(),
170+
lexical_cast<std::string>(target).c_str(),
171+
lexical_cast<std::string>(length).c_str(),
172+
lexical_cast<std::string>(car).c_str(),
173+
lexical_cast<std::string>(car_d).c_str(),
174+
lexical_cast<std::string>(bike).c_str(),
175+
lexical_cast<std::string>(bike_d).c_str(),
176+
lexical_cast<std::string>(foot).c_str(),
177+
tmp_geom.c_str()
178+
};
179+
180+
res = PQexecPrepared(conn, "add_edge", 10, params, NULL, NULL, 0);
229181
if (PQresultStatus(res) != PGRES_COMMAND_OK)
230182
{
231183
std::cerr << "Unable to add edge in table " << edges_table << PQerrorMessage(conn) << std::endl;

pqwriter.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class PqWriter : public Writer
2727
PGconn *conn;
2828
std::string nodes_table;
2929
std::string edges_table;
30-
std::string format;
3130
bool drop_table;
3231
public:
3332

34-
PqWriter(const std::string & conn_str, const std::string & nodes_table, const std::string & edges_table, bool drop_table = true, std::string & format);
33+
PqWriter(const std::string & conn_str, const std::string & nodes_table, const std::string & edges_table, bool drop_table = true);
3534

3635
int save_nodes(const NodeMapType & nodes);
3736

0 commit comments

Comments
 (0)