forked from pgRouting/osm2pgrouting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosm2pgrouting.cpp
213 lines (169 loc) · 6.55 KB
/
osm2pgrouting.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***************************************************************************
* Copyright (C) 2008 by Daniel Wendt *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "stdafx.h"
#include "Configuration.h"
#include "ConfigurationParserCallback.h"
#include "OSMDocument.h"
#include "OSMDocumentParserCallback.h"
#include "Way.h"
#include "Node.h"
#include "Relation.h"
#include "Export2DB.h"
#include <unistd.h>
#include "prog_options.h"
//using namespace osm;
//using namespace xml;
//using namespace std;
int main(int argc, char* argv[])
{
try{
//..prog_options code begin..
//std::string file,cFile,host,user,db_port,dbname,passwd,prefixtables,suffixtables;
//bool skipnodes,clean,threads,multimodal,multilevel;
po::options_description od_desc("Allowed options");
get_option_description(od_desc);
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(od_desc).run(), vm);
if (vm.count("help")) {
std::cout << od_desc << "\n";
return 0;
}
try{
notify(vm);
}
catch(exception &ex){
std::cout << ex.what() << "\n";
std::cout << od_desc << "\n";
return 0;
}
auto ret_val = process_command_line(vm, od_desc);
if (ret_val != 2)
return ret_val; //there is an error
auto file ( vm["file"].as<string>() );
auto cFile ( vm["conf"].as<string>() );
auto host ( vm["host"].as<std::string>() );
auto user ( vm["user"].as<std::string>() );
auto db_port ( vm["db_port"].as<std::string>() );
auto dbname ( vm["dbname"].as<std::string>() );
auto passwd ( vm["passwd"].as<std::string>() );
auto prefixtables ( vm["prefixtables"].as<std::string>() );
auto suffixtables ( vm["suffixtables"].as<std::string>() );
auto skipnodes ( vm["skipnodes"].as<bool>() );
auto clean ( vm["clean"].as<bool>() );
/* variable to be used later
auto threads ( vm["threads"].as<bool>() );
auto multimodal ( vm["multimodal"].as<bool>() );
auto multilevel ( vm["multilevel"].as<bool>() );
*/
//!!prog_options code end!!
Export2DB test(vm);
if(test.connect()==1)
return 1;
xml::XMLParser parser;
std::cout << "Trying to load config file " << cFile.c_str() << endl;
Configuration* config = new Configuration();
ConfigurationParserCallback cCallback( *config );
std::cout << "Trying to parse config" << endl;
int ret = parser.Parse(cCallback, cFile.c_str());
if (ret!=0) {
cerr << "Failed to parse config file " << cFile.c_str() << endl;
return 1;
}
std::cout << "Trying to load data" << endl;
OSMDocument* document = new OSMDocument(*config);
OSMDocumentParserCallback callback(*document);
std::cout << "Trying to parse data" << endl;
ret = parser.Parse( callback, file.c_str() );
if( ret!=0 ) {
if( ret == 1 )
cerr << "Failed to open data file" << endl;
cerr << "Failed to parse data file " << file.c_str() << endl;
return 1;
}
std::cout << "Split ways" << endl;
document->SplitWays();
//############# Export2DB
{
if( clean )
{
std::cout << "Dropping tables..." << endl;
test.dropTables();
}
std::cout << "Creating tables..." << endl;
test.createTables();
std::cout << "Adding tag types and classes to database..." << endl;
test.exportTypesWithClasses(config->m_Types);
std::cout << "Adding relations to database..." << endl;
test.exportRelations(document->m_Relations, config);
// Optional user argument skipnodes will not add nodes to the database (saving a lot of time if not necessary)
if ( !skipnodes) {
std::cout << "Adding nodes to database..." << endl;
test.exportNodes(document->m_Nodes);
}
std::cout << "Adding ways to database..." << endl;
test.exportWays(document->m_SplittedWays, config);
//TODO: make some free memory, document will be not used anymore, so there will be more memory available to future DB operations.
std::cout << "Creating topology..." << endl;
test.createTopology();
}
//#############
/*
std::vector<Way*>& ways= document.m_Ways;
std::vector<Way*>::iterator it( ways.begin() );
std::vector<Way*>::iterator last( ways.end() );
while( it!=last )
{
Way* pWay = *it;
if( !pWay->name.empty() )
{
if( pWay->m_NodeRefs.empty() )
{
std::std::cout << pWay->name.c_str() << endl;
}
else
{
Node* n0 = pWay->m_NodeRefs.front();
Node* n1 = pWay->m_NodeRefs.back();
//if(n1->numsOfUse==1)
//std::cout << "way-id: " << pWay->id << " name: " << pWay->name <<endl;
//std::std::cout << n0->lon << " " << n0->lat << " " << n1->lon << " " << n1->lat << " " << pWay->name.c_str() << " highway: " << pWay->highway.c_str() << " Start numberOfUse: " << n0->numsOfUse << " End numberOfUse: " << n1->numsOfUse << " ID: " << n1->id << endl;
}
}
if( pWay->id == 20215432 ) // Pfaenderweg
{
std::cout << pWay->name << endl;
int a=4;
}
++it;
}
*/
std::cout << "#########################" << endl;
std::cout << "size of streets: " << document->m_Ways.size() << endl;
std::cout << "size of splitted ways : " << document->m_SplittedWays.size() << endl;
std::cout << "finished" << endl;
//string n;
//getline( cin, n );
return 0;
}
catch(exception &e){
std::cout<< e.what()<<endl;
return 1;
}
}