Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/planetsplitter.c
Parent Directory
|
Revision Log
Revision 84 -
(show annotations)
(download)
(as text)
Sun Jan 25 12:09:15 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 9984 byte(s)
Sun Jan 25 12:09:15 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 9984 byte(s)
Change the segment->way so that it contains the index of the way, not the id.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.19 2009-01-25 12:09:15 amb Exp $ |
3 | |
4 | OSM planet file splitter. |
5 | ******************/ /****************** |
6 | Written by Andrew M. Bishop |
7 | |
8 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | It may be distributed under the GNU Public License, version 2, or |
10 | any higher version. See section COPYING of the GNU Public license |
11 | for conditions under which this file may be redistributed. |
12 | ***************************************/ |
13 | |
14 | |
15 | #include <stdio.h> |
16 | #include <stdlib.h> |
17 | #include <string.h> |
18 | |
19 | #include "nodes.h" |
20 | #include "segments.h" |
21 | #include "ways.h" |
22 | #include "profiles.h" |
23 | #include "functions.h" |
24 | |
25 | |
26 | int main(int argc,char** argv) |
27 | { |
28 | NodesMem *OSMNodesMem; |
29 | SegmentsMem *OSMSegmentsMem; |
30 | WaysMem *OSMWaysMem; |
31 | NodesMem *SuperNodesMem,*SuperNodesMem2; |
32 | SegmentsMem *SuperSegmentsMem,*SuperSegmentsMem2; |
33 | WaysMem *SuperWaysMem,*SuperWaysMem2; |
34 | Nodes *OSMNodes; |
35 | Segments *OSMSegments; |
36 | Ways *OSMWays; |
37 | Nodes *SuperNodes,*SuperNodes2; |
38 | Segments *SuperSegments,*SuperSegments2; |
39 | Ways *SuperWays,*SuperWays2; |
40 | int iteration=0,quit=0; |
41 | int help_profile=0,skip_parsing=0,max_iterations=5; |
42 | Profile profile; |
43 | int i; |
44 | |
45 | /* Fill in the default profile. */ |
46 | |
47 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
48 | |
49 | profile.allow=Allow_ALL; |
50 | |
51 | for(i=1;i<Way_Unknown;i++) |
52 | profile.highways[i]=1; |
53 | |
54 | for(i=1;i<Way_Unknown;i++) |
55 | profile.speed[i]=0; /* Not used by planetsplitter */ |
56 | |
57 | profile.oneway=1; /* Not used by planetsplitter */ |
58 | |
59 | /* Parse the command line arguments */ |
60 | |
61 | while(--argc>=1) |
62 | { |
63 | if(!strcmp(argv[argc],"-help")) |
64 | goto usage; |
65 | if(!strcmp(argv[argc],"-help-profile")) |
66 | help_profile=1; |
67 | else if(!strcmp(argv[argc],"-skip-parsing")) |
68 | skip_parsing=1; |
69 | else if(!strncmp(argv[argc],"-max-iterations=",16)) |
70 | max_iterations=atoi(&argv[argc][16]); |
71 | else if(!strncmp(argv[argc],"-transport=",11)) |
72 | { |
73 | profile.transport=TransportType(&argv[argc][11]); |
74 | profile.allow=1<<(profile.transport-1); |
75 | } |
76 | else if(!strncmp(argv[argc],"-not-highway=",13)) |
77 | { |
78 | Highway highway=HighwayType(&argv[argc][13]); |
79 | profile.highways[highway]=0; |
80 | } |
81 | else |
82 | { |
83 | usage: |
84 | |
85 | fprintf(stderr,"Usage: planetsplitter\n" |
86 | " [-help] [-help-profile]\n" |
87 | " [-skip-parsing]\n" |
88 | " [-max-iterations=<number>]\n" |
89 | " [-transport=<transport>]\n" |
90 | " [-not-highway=<highway> ...]\n" |
91 | "\n" |
92 | "<transport> defaults to all but can be set to:\n" |
93 | "%s" |
94 | "\n" |
95 | "<highway> can be selected from:\n" |
96 | "%s", |
97 | TransportList(),HighwayList()); |
98 | |
99 | return(1); |
100 | } |
101 | } |
102 | |
103 | if(help_profile) |
104 | { |
105 | PrintProfile(&profile); |
106 | |
107 | return(0); |
108 | } |
109 | |
110 | /* Parse the file (or not) */ |
111 | |
112 | if(!skip_parsing) |
113 | { |
114 | /* Create new variables */ |
115 | |
116 | OSMNodesMem=NewNodeList(); |
117 | OSMSegmentsMem=NewSegmentList(); |
118 | OSMWaysMem=NewWayList(); |
119 | |
120 | /* Parse the file */ |
121 | |
122 | printf("\nParsing OSM Data\n================\n\n"); fflush(stdout); |
123 | |
124 | ParseXML(stdin,OSMNodesMem,OSMSegmentsMem,OSMWaysMem,&profile); |
125 | |
126 | printf("\nProcessing OSM Data\n===================\n\n"); fflush(stdout); |
127 | |
128 | /* Sort the variables */ |
129 | |
130 | printf("Sorting All Nodes"); fflush(stdout); |
131 | SortNodeList(OSMNodesMem); |
132 | printf("\rSorted All Nodes \n"); fflush(stdout); |
133 | |
134 | printf("Sorting Segments"); fflush(stdout); |
135 | SortSegmentList(OSMSegmentsMem); |
136 | printf("\rSorted Segments \n"); fflush(stdout); |
137 | |
138 | printf("Sorting Ways"); fflush(stdout); |
139 | SortWayList(OSMWaysMem); |
140 | printf("\rSorted Ways \n"); fflush(stdout); |
141 | |
142 | /* Write out all the nodes */ |
143 | |
144 | printf("Saving All Nodes"); fflush(stdout); |
145 | OSMNodes=SaveNodeList(OSMNodesMem,"data/all-nodes.mem"); |
146 | printf("\rSaved All Nodes: %d\n",OSMNodes->number); fflush(stdout); |
147 | |
148 | /* Write out the ways */ |
149 | |
150 | printf("Saving Ways"); fflush(stdout); |
151 | OSMWays=SaveWayList(OSMWaysMem,"data/ways.mem"); |
152 | printf("\rSaved Ways: %d\n",OSMWays->number); fflush(stdout); |
153 | |
154 | /* Remove bad segments */ |
155 | |
156 | RemoveBadSegments(OSMSegmentsMem); |
157 | |
158 | printf("Sorting Segments"); fflush(stdout); |
159 | SortSegmentList(OSMSegmentsMem); |
160 | printf("\rSorted Segments \n"); fflush(stdout); |
161 | |
162 | /* Fix the segment lengths */ |
163 | |
164 | FixupSegmentLengths(OSMSegmentsMem,OSMNodes,OSMWays); |
165 | |
166 | /* Link the ways to the segments */ |
167 | |
168 | LinkSegmentToWay(OSMSegmentsMem,OSMWays); |
169 | |
170 | /* Write out the segments */ |
171 | |
172 | printf("Saving Segments"); fflush(stdout); |
173 | OSMSegments=SaveSegmentList(OSMSegmentsMem,"data/segments.mem"); |
174 | printf("\rSaved Segments: %d\n",OSMSegments->number); fflush(stdout); |
175 | |
176 | /* Remove non-way nodes */ |
177 | |
178 | OSMNodesMem=OnlyHighwayNodes(OSMNodes,OSMSegments); |
179 | |
180 | UnMapFile(OSMNodes); |
181 | |
182 | /* Sort the nodes */ |
183 | |
184 | printf("Sorting Way Nodes"); fflush(stdout); |
185 | SortNodeList(OSMNodesMem); |
186 | printf("\rSorted Way Nodes \n"); fflush(stdout); |
187 | |
188 | /* Write out the nodes */ |
189 | |
190 | printf("Saving Way Nodes"); fflush(stdout); |
191 | OSMNodes=SaveNodeList(OSMNodesMem,"data/nodes.mem"); |
192 | printf("\rSaved Way Nodes: %d\n",OSMNodes->number); fflush(stdout); |
193 | } |
194 | else |
195 | { |
196 | /* Load in the data */ |
197 | |
198 | OSMNodes=LoadNodeList("data/nodes.mem"); |
199 | OSMSegments=LoadSegmentList("data/segments.mem"); |
200 | OSMWays=LoadWayList("data/ways.mem"); |
201 | } |
202 | |
203 | printf("\nProcessing Super-Data\n=====================\n\n"); fflush(stdout); |
204 | |
205 | /* Select the super-nodes */ |
206 | |
207 | SuperNodesMem=ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays); |
208 | |
209 | /* Sort the super-nodes */ |
210 | |
211 | printf("Sorting Super-Nodes"); fflush(stdout); |
212 | SortNodeList(SuperNodesMem); |
213 | printf("\rSorted Super-Nodes \n"); fflush(stdout); |
214 | |
215 | /* Write out the super-nodes */ |
216 | |
217 | printf("Saving Super-Nodes"); fflush(stdout); |
218 | SuperNodes=SaveNodeList(SuperNodesMem,"data/super-nodes.mem"); |
219 | printf("\rSaved Super-Nodes: %d\n",SuperNodes->number); fflush(stdout); |
220 | |
221 | /* Select the super-segments */ |
222 | |
223 | SuperSegmentsMem=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays,SuperNodes); |
224 | |
225 | /* Sort the super-segments */ |
226 | |
227 | printf("Sorting Super-Segments"); fflush(stdout); |
228 | SortSegmentList(SuperSegmentsMem); |
229 | printf("\rSorted Super-Segments \n"); fflush(stdout); |
230 | |
231 | /* Select the super-ways */ |
232 | |
233 | SuperWaysMem=CreateSuperWays(OSMWays,SuperSegmentsMem); |
234 | |
235 | /* Write out the super-segments */ |
236 | |
237 | printf("Saving Super-Segments"); fflush(stdout); |
238 | SuperSegments=SaveSegmentList(SuperSegmentsMem,"data/super-segments.mem"); |
239 | printf("\rSaved Super-Segments: %d\n",SuperSegments->number); fflush(stdout); |
240 | |
241 | /* Sort the super-ways */ |
242 | |
243 | printf("Sorting Super-Ways"); fflush(stdout); |
244 | SortWayList(SuperWaysMem); |
245 | printf("\rSorted Super-Ways \n"); fflush(stdout); |
246 | |
247 | /* Write out the super-ways */ |
248 | |
249 | printf("Saving Super-Ways"); fflush(stdout); |
250 | SuperWays=SaveWayList(SuperWaysMem,"data/super-ways.mem"); |
251 | printf("\rSaved Super-Ways: %d\n",SuperWays->number); fflush(stdout); |
252 | |
253 | /* Repeated iteration on Super-Nodes, Super-Segments and Super-Ways */ |
254 | |
255 | UnMapFile(SuperNodes); |
256 | UnMapFile(SuperSegments); |
257 | UnMapFile(SuperWays); |
258 | |
259 | do |
260 | { |
261 | iteration++; |
262 | |
263 | if(iteration>max_iterations) |
264 | break; |
265 | |
266 | /* Load the previous iteration */ |
267 | |
268 | SuperNodes=LoadNodeList("data/super-nodes.mem"); |
269 | SuperWays=LoadWayList("data/super-ways.mem"); |
270 | SuperSegments=LoadSegmentList("data/super-segments.mem"); |
271 | |
272 | printf("\nProcessing Super-Data (iteration %d)\n===================================%s\n\n",iteration,iteration>10?"=":""); fflush(stdout); |
273 | |
274 | /* Select the super-nodes */ |
275 | |
276 | SuperNodesMem2=ChooseSuperNodes(SuperNodes,SuperSegments,SuperWays); |
277 | |
278 | /* Sort the super-nodes */ |
279 | |
280 | printf("Sorting Super-Nodes"); fflush(stdout); |
281 | SortNodeList(SuperNodesMem2); |
282 | printf("\rSorted Super-Nodes \n"); fflush(stdout); |
283 | |
284 | /* Write out the super-nodes */ |
285 | |
286 | printf("Saving Super-Nodes"); fflush(stdout); |
287 | SuperNodes2=SaveNodeList(SuperNodesMem2,"data/super-nodes2.mem"); |
288 | printf("\rSaved Super-Nodes: %d\n",SuperNodes2->number); fflush(stdout); |
289 | |
290 | /* Select the super-segments */ |
291 | |
292 | SuperSegmentsMem2=CreateSuperSegments(SuperNodes,SuperSegments,SuperWays,SuperNodes2); |
293 | |
294 | /* Sort the super-segments */ |
295 | |
296 | printf("Sorting Super-Segments"); fflush(stdout); |
297 | SortSegmentList(SuperSegmentsMem2); |
298 | printf("\rSorted Super-Segments \n"); fflush(stdout); |
299 | |
300 | /* Select the super-ways */ |
301 | |
302 | SuperWaysMem2=CreateSuperWays(SuperWays,SuperSegmentsMem2); |
303 | |
304 | /* Write out the super-segments */ |
305 | |
306 | printf("Saving Super-Segments"); fflush(stdout); |
307 | SuperSegments2=SaveSegmentList(SuperSegmentsMem2,"data/super-segments2.mem"); |
308 | printf("\rSaved Super-Segments: %d\n",SuperSegments2->number); fflush(stdout); |
309 | |
310 | /* Sort the super-ways */ |
311 | |
312 | printf("Sorting Super-Ways"); fflush(stdout); |
313 | SortWayList(SuperWaysMem2); |
314 | printf("\rSorted Super-Ways \n"); fflush(stdout); |
315 | |
316 | /* Write out the super-ways */ |
317 | |
318 | printf("Saving Super-Ways"); fflush(stdout); |
319 | SuperWays2=SaveWayList(SuperWaysMem2,"data/super-ways2.mem"); |
320 | printf("\rSaved Super-Ways: %d\n",SuperWays2->number); fflush(stdout); |
321 | |
322 | /* Decide when to quit */ |
323 | |
324 | quit=0; |
325 | if(SuperNodes2->number>(0.999*SuperNodes->number)) quit=1; |
326 | if(SuperSegments2->number>(0.999*SuperSegments->number)) quit=1; |
327 | |
328 | /* Unmap the data and Rename the files */ |
329 | |
330 | UnMapFile(SuperNodes); |
331 | UnMapFile(SuperSegments); |
332 | UnMapFile(SuperWays); |
333 | |
334 | UnMapFile(SuperNodes2); |
335 | UnMapFile(SuperSegments2); |
336 | UnMapFile(SuperWays2); |
337 | |
338 | rename("data/super-nodes2.mem","data/super-nodes.mem"); |
339 | rename("data/super-segments2.mem","data/super-segments.mem"); |
340 | rename("data/super-ways2.mem","data/super-ways.mem"); |
341 | } |
342 | while(!quit); |
343 | |
344 | UnMapFile(OSMNodes); |
345 | UnMapFile(OSMSegments); |
346 | UnMapFile(OSMWays); |
347 | |
348 | return(0); |
349 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |