1 | /***************************************************************************
|
---|
2 | * Copyright (C) 2008 by Daniel Wendt *
|
---|
3 | * gentoo.murray@gmail.com *
|
---|
4 | * *
|
---|
5 | * This program is free software; you can redistribute it and/or modify *
|
---|
6 | * it under the terms of the GNU General Public License as published by *
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
8 | * (at your option) any later version. *
|
---|
9 | * *
|
---|
10 | * This program is distributed in the hope that it will be useful, *
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
13 | * GNU General Public License for more details. *
|
---|
14 | * *
|
---|
15 | * You should have received a copy of the GNU General Public License *
|
---|
16 | * along with this program; if not, write to the *
|
---|
17 | * Free Software Foundation, Inc., *
|
---|
18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
---|
19 | ***************************************************************************/
|
---|
20 |
|
---|
21 | #include "stdafx.h"
|
---|
22 | #include "OSMDocument.h"
|
---|
23 | #include "OSMDocumentParserCallback.h"
|
---|
24 | #include "Way.h"
|
---|
25 | #include "Node.h"
|
---|
26 | #include "Export2DB.h"
|
---|
27 |
|
---|
28 | using namespace osm;
|
---|
29 | using namespace xml;
|
---|
30 | using namespace std;
|
---|
31 |
|
---|
32 | void _error()
|
---|
33 | {
|
---|
34 | cout << "following params are required: " << endl;
|
---|
35 | cout << "-file <file> -- name of your osm xml file" << endl;
|
---|
36 | cout << "-dbname <dbname> -- name of your database" << endl;
|
---|
37 | cout << "-user <user> -- name of the user, which have write access to the database" << endl;
|
---|
38 | cout << "optional:" << endl;
|
---|
39 | cout << "-host <host> -- host of your postgresql database (default: 127.0.0.1)" << endl;
|
---|
40 | cout << "-port <port> -- port of your database (default: 5432)" << endl;
|
---|
41 | cout << "-passwd <passwd> -- password for database access" << endl;
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | int main(int argc, char* argv[])
|
---|
46 | {
|
---|
47 | std::string file;
|
---|
48 | std::string host="127.0.0.1";
|
---|
49 | std::string user;
|
---|
50 | std::string port="5432";
|
---|
51 | std::string dbname;
|
---|
52 | std::string passwd;
|
---|
53 | if(argc >=7 && argc <=13)
|
---|
54 | {
|
---|
55 | int i=1;
|
---|
56 | while( i<argc)
|
---|
57 | {
|
---|
58 |
|
---|
59 | if(strcmp(argv[i],"-file")==0)
|
---|
60 | {
|
---|
61 | i++;
|
---|
62 | file = argv[i];
|
---|
63 | }
|
---|
64 |
|
---|
65 | else if(strcmp(argv[i],"-host")==0)
|
---|
66 | {
|
---|
67 | i++;
|
---|
68 | host = argv[i];
|
---|
69 | }
|
---|
70 | else if(strcmp(argv[i],"-dbname")==0)
|
---|
71 | {
|
---|
72 | i++;
|
---|
73 | dbname = argv[i];
|
---|
74 | }
|
---|
75 | else if(strcmp(argv[i],"-user")==0)
|
---|
76 | {
|
---|
77 | i++;
|
---|
78 | user = argv[i];
|
---|
79 | }
|
---|
80 | else if(strcmp(argv[i],"-port")==0)
|
---|
81 | {
|
---|
82 | i++;
|
---|
83 | port = argv[i];
|
---|
84 | }
|
---|
85 | else if(strcmp(argv[i],"-passwd")==0)
|
---|
86 | {
|
---|
87 | i++;
|
---|
88 | passwd = argv[i];
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | cout << "unknown paramer: " << argv[i] << endl;
|
---|
93 | _error();
|
---|
94 | return 1;
|
---|
95 | }
|
---|
96 |
|
---|
97 | i++;
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|
101 | else
|
---|
102 | {
|
---|
103 | _error();
|
---|
104 | return 1;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if(file.empty() || dbname.empty() || user.empty())
|
---|
108 | {
|
---|
109 | _error();
|
---|
110 | return 1;
|
---|
111 | }
|
---|
112 |
|
---|
113 | Export2DB test(host, user, dbname, port, passwd);
|
---|
114 | if(test.connect()==1)
|
---|
115 | return 1;
|
---|
116 |
|
---|
117 | //std::string fileName = "../data/oldenburg.osm";
|
---|
118 | OSMDocument document;
|
---|
119 | OSMDocumentParserCallback callback( document );
|
---|
120 |
|
---|
121 | XMLParser parser;
|
---|
122 | int ret = parser.Parse( callback, file.c_str() );
|
---|
123 | if( ret!=0 ) return 1;
|
---|
124 |
|
---|
125 | document.SplitWays();
|
---|
126 | //############# Export2DB
|
---|
127 | {
|
---|
128 |
|
---|
129 | test.createTables();
|
---|
130 | std::map<long long, Node*>& nodes= document.m_Nodes;
|
---|
131 | std::map<long long, Node*>::iterator it(nodes.begin());
|
---|
132 | std::map<long long, Node*>::iterator last(nodes.end());
|
---|
133 |
|
---|
134 | while(it!=last)
|
---|
135 | {
|
---|
136 | Node* node = (*it++).second;
|
---|
137 | test.exportNode(node->id,node->lon, node->lat, node->numsOfUse);
|
---|
138 | }
|
---|
139 |
|
---|
140 | std::vector<Way*>& ways= document.m_SplittedWays;
|
---|
141 | std::vector<Way*>::iterator it_way( ways.begin() );
|
---|
142 | std::vector<Way*>::iterator last_way( ways.end() );
|
---|
143 | while( it_way!=last_way )
|
---|
144 | {
|
---|
145 | Way* pWay = *it_way++;
|
---|
146 | test.exportWay(pWay);
|
---|
147 | }
|
---|
148 | cout << "create topology" << endl;
|
---|
149 | test.createTopology();
|
---|
150 | }
|
---|
151 |
|
---|
152 | //#############
|
---|
153 |
|
---|
154 | /*
|
---|
155 | std::vector<Way*>& ways= document.m_Ways;
|
---|
156 | std::vector<Way*>::iterator it( ways.begin() );
|
---|
157 | std::vector<Way*>::iterator last( ways.end() );
|
---|
158 | while( it!=last )
|
---|
159 | {
|
---|
160 | Way* pWay = *it;
|
---|
161 |
|
---|
162 | if( !pWay->name.empty() )
|
---|
163 | {
|
---|
164 | if( pWay->m_NodeRefs.empty() )
|
---|
165 | {
|
---|
166 | std::cout << pWay->name.c_str() << endl;
|
---|
167 | }
|
---|
168 | else
|
---|
169 | {
|
---|
170 | Node* n0 = pWay->m_NodeRefs.front();
|
---|
171 | Node* n1 = pWay->m_NodeRefs.back();
|
---|
172 | //if(n1->numsOfUse==1)
|
---|
173 | //cout << "way-id: " << pWay->id << " name: " << pWay->name <<endl;
|
---|
174 | //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;
|
---|
175 | }
|
---|
176 | }
|
---|
177 | if( pWay->id == 20215432 ) // Pfaenderweg
|
---|
178 | {
|
---|
179 | cout << pWay->name << endl;
|
---|
180 | int a=4;
|
---|
181 | }
|
---|
182 | ++it;
|
---|
183 | }
|
---|
184 | */
|
---|
185 |
|
---|
186 | cout << "#########################" << endl;
|
---|
187 |
|
---|
188 | cout << "size of streets: " << document.m_Ways.size() << endl;
|
---|
189 | cout << "size of splitted ways : " << document.m_SplittedWays.size() << endl;
|
---|
190 |
|
---|
191 | cout << "finished" << endl;
|
---|
192 |
|
---|
193 | //string n;
|
---|
194 | //getline( cin, n );
|
---|
195 | return 0;
|
---|
196 | }
|
---|
197 |
|
---|