21
21
22
22
using boost::lexical_cast;
23
23
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) :
25
25
nodes_table(nodes_table),
26
26
edges_table(edges_table),
27
27
drop_table(drop_table)
@@ -55,23 +55,14 @@ PqWriter::PqWriter(const std::string & conn_str, const std::string & nodes_table
55
55
std::cerr << " Unable to drop table " << nodes_table << PQerrorMessage (conn) << std::endl;
56
56
}
57
57
PQclear (res);
58
-
59
58
res = PQexec (conn, (" CREATE TABLE " + nodes_table + " (ID bigint, lon double precision, lat double precision)" ).c_str ());
60
59
if (PQresultStatus (res) != PGRES_COMMAND_OK)
61
60
{
62
61
std::cerr << " Unable to create table " << nodes_table << PQerrorMessage (conn) << std::endl;
63
62
}
64
63
PQclear (res);
65
64
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 ());
75
66
if (PQresultStatus (res) != PGRES_COMMAND_OK)
76
67
{
77
68
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
85
76
}
86
77
PQclear (res);
87
78
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 ());
89
80
if (PQresultStatus (res) != PGRES_TUPLES_OK)
90
81
{
91
82
std::cerr << " Unable to add a geometry column on table " << edges_table << PQerrorMessage (conn) << std::endl;
92
83
}
93
84
PQclear (res);
94
85
}
95
86
96
- if (format == " pg" )
97
- {
98
- res = PQprepare (conn,
87
+ res = PQprepare (conn,
99
88
" 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 () ,
102
90
0 ,
103
91
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
-
115
92
if (PQresultStatus (res) != PGRES_COMMAND_OK)
116
93
{
117
94
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
137
114
}
138
115
PQclear (res);
139
116
117
+
118
+
119
+
140
120
}
141
121
142
122
int PqWriter::save_nodes (const NodeMapType & nodes)
@@ -184,48 +164,20 @@ void PqWriter::save_edge(int edge_id,
184
164
185
165
PGresult * res;
186
166
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 );
229
181
if (PQresultStatus (res) != PGRES_COMMAND_OK)
230
182
{
231
183
std::cerr << " Unable to add edge in table " << edges_table << PQerrorMessage (conn) << std::endl;
0 commit comments