Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/planetsplitter.c
Parent Directory
|
Revision Log
Revision 358 -
(hide annotations)
(download)
(as text)
Fri Apr 9 15:15:02 2010 UTC (15 years ago) by amb
File MIME type: text/x-csrc
File size: 11522 byte(s)
Fri Apr 9 15:15:02 2010 UTC (15 years ago) by amb
File MIME type: text/x-csrc
File size: 11522 byte(s)
Add an option '--sort-ram-size' to specify the RAM to use for sorting - defaults to 256MB if not using slim mode.
1 | amb | 2 | /*************************************** |
2 | amb | 358 | $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.71 2010-04-09 15:15:02 amb Exp $ |
3 | amb | 2 | |
4 | OSM planet file splitter. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 2 | ******************/ /****************** |
8 | amb | 326 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | amb | 2 | |
10 | amb | 151 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by | ||
12 | the Free Software Foundation, either version 3 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, | ||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | GNU Affero General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU Affero General Public License | ||
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | amb | 2 | ***************************************/ |
23 | |||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | amb | 60 | #include <string.h> |
28 | amb | 330 | #include <errno.h> |
29 | amb | 2 | |
30 | amb | 199 | #include "typesx.h" |
31 | amb | 96 | #include "types.h" |
32 | amb | 199 | #include "functionsx.h" |
33 | amb | 109 | #include "functions.h" |
34 | #include "nodesx.h" | ||
35 | #include "segmentsx.h" | ||
36 | #include "waysx.h" | ||
37 | #include "superx.h" | ||
38 | amb | 82 | #include "profiles.h" |
39 | amb | 228 | #include "ways.h" |
40 | amb | 2 | |
41 | |||
42 | amb | 284 | /* Variables */ |
43 | |||
44 | amb | 249 | /*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/ |
45 | int option_slim=0; | ||
46 | |||
47 | amb | 256 | /*+ The name of the temporary directory. +*/ |
48 | amb | 284 | char *option_tmpdirname=NULL; |
49 | amb | 249 | |
50 | amb | 358 | /*+ The amount of RAM to use for filesorting. +*/ |
51 | size_t option_filesort_ramsize=0; | ||
52 | amb | 284 | |
53 | amb | 358 | |
54 | amb | 342 | /* Local functions */ |
55 | |||
56 | static void print_usage(int detail); | ||
57 | |||
58 | |||
59 | /*++++++++++++++++++++++++++++++++++++++ | ||
60 | The main program for the router. | ||
61 | ++++++++++++++++++++++++++++++++++++++*/ | ||
62 | |||
63 | amb | 2 | int main(int argc,char** argv) |
64 | { | ||
65 | amb | 327 | NodesX *Nodes; |
66 | amb | 256 | SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL; |
67 | amb | 327 | WaysX *Ways; |
68 | int iteration=0,quit=0; | ||
69 | int max_iterations=10; | ||
70 | char *dirname=NULL,*prefix=NULL; | ||
71 | int option_parse_only=0,option_process_only=0; | ||
72 | int option_filenames=0; | ||
73 | Profile profile={0}; | ||
74 | int arg,i; | ||
75 | amb | 26 | |
76 | amb | 82 | /* Fill in the default profile. */ |
77 | amb | 31 | |
78 | amb | 82 | profile.transport=Transport_None; /* Not used by planetsplitter */ |
79 | amb | 75 | |
80 | amb | 307 | profile.allow=0; |
81 | amb | 75 | |
82 | amb | 300 | for(i=1;i<Way_Count;i++) |
83 | amb | 166 | profile.highway[i]=1; |
84 | amb | 82 | |
85 | amb | 298 | for(i=1;i<Property_Count;i++) |
86 | profile.props_yes[i]=1; | ||
87 | |||
88 | amb | 82 | profile.oneway=1; /* Not used by planetsplitter */ |
89 | |||
90 | /* Parse the command line arguments */ | ||
91 | |||
92 | amb | 327 | for(arg=1;arg<argc;arg++) |
93 | amb | 60 | { |
94 | amb | 327 | if(!strcmp(argv[arg],"--help")) |
95 | amb | 342 | print_usage(1); |
96 | amb | 327 | else if(!strcmp(argv[arg],"--slim")) |
97 | amb | 249 | option_slim=1; |
98 | amb | 358 | else if(!strncmp(argv[arg],"--sort-ram-size=",16)) |
99 | option_filesort_ramsize=atoi(&argv[arg][16]); | ||
100 | amb | 327 | else if(!strncmp(argv[arg],"--dir=",6)) |
101 | dirname=&argv[arg][6]; | ||
102 | else if(!strncmp(argv[arg],"--tmpdir=",9)) | ||
103 | option_tmpdirname=&argv[arg][9]; | ||
104 | else if(!strncmp(argv[arg],"--prefix=",9)) | ||
105 | prefix=&argv[arg][9]; | ||
106 | else if(!strcmp(argv[arg],"--parse-only")) | ||
107 | amb | 326 | option_parse_only=1; |
108 | amb | 327 | else if(!strcmp(argv[arg],"--process-only")) |
109 | amb | 326 | option_process_only=1; |
110 | amb | 327 | else if(!strncmp(argv[arg],"--max-iterations=",17)) |
111 | max_iterations=atoi(&argv[arg][17]); | ||
112 | else if(!strncmp(argv[arg],"--transport=",12)) | ||
113 | amb | 82 | { |
114 | amb | 327 | Transport transport=TransportType(&argv[arg][12]); |
115 | amb | 307 | if(transport==Transport_None) |
116 | amb | 342 | print_usage(0); |
117 | amb | 307 | profile.allow|=ALLOWED(transport); |
118 | amb | 82 | } |
119 | amb | 327 | else if(!strncmp(argv[arg],"--not-highway=",14)) |
120 | amb | 75 | { |
121 | amb | 327 | Highway highway=HighwayType(&argv[arg][14]); |
122 | amb | 300 | if(highway==Way_Count) |
123 | amb | 342 | print_usage(0); |
124 | amb | 166 | profile.highway[highway]=0; |
125 | amb | 75 | } |
126 | amb | 327 | else if(!strncmp(argv[arg],"--not-property=",15)) |
127 | amb | 298 | { |
128 | amb | 327 | Property property=PropertyType(&argv[arg][15]); |
129 | amb | 298 | if(property==Property_Count) |
130 | amb | 342 | print_usage(0); |
131 | amb | 298 | profile.props_yes[property]=0; |
132 | } | ||
133 | amb | 327 | else if(argv[arg][0]=='-' && argv[arg][1]=='-') |
134 | amb | 342 | print_usage(0); |
135 | amb | 327 | else |
136 | option_filenames++; | ||
137 | amb | 60 | } |
138 | amb | 26 | |
139 | amb | 326 | if(option_parse_only && option_process_only) |
140 | amb | 342 | print_usage(0); |
141 | amb | 326 | |
142 | amb | 327 | if(option_filenames && option_process_only) |
143 | amb | 342 | print_usage(0); |
144 | amb | 327 | |
145 | amb | 358 | if(!option_filesort_ramsize) |
146 | { | ||
147 | if(option_slim) | ||
148 | option_filesort_ramsize=64*1024*1024; | ||
149 | else | ||
150 | option_filesort_ramsize=256*1024*1024; | ||
151 | } | ||
152 | else | ||
153 | option_filesort_ramsize*=1024*1024; | ||
154 | |||
155 | amb | 284 | if(!option_tmpdirname) |
156 | amb | 252 | { |
157 | if(!dirname) | ||
158 | amb | 284 | option_tmpdirname="."; |
159 | amb | 252 | else |
160 | amb | 284 | option_tmpdirname=dirname; |
161 | amb | 252 | } |
162 | |||
163 | amb | 307 | if(!profile.allow) |
164 | profile.allow=Allow_ALL; | ||
165 | |||
166 | amb | 275 | /* Create new node, segment and way variables */ |
167 | amb | 82 | |
168 | amb | 326 | Nodes=NewNodeList(option_parse_only||option_process_only); |
169 | amb | 275 | |
170 | amb | 326 | Segments=NewSegmentList(option_parse_only||option_process_only); |
171 | amb | 275 | |
172 | amb | 326 | Ways=NewWayList(option_parse_only||option_process_only); |
173 | amb | 26 | |
174 | amb | 89 | /* Parse the file */ |
175 | amb | 2 | |
176 | amb | 327 | if(option_filenames) |
177 | amb | 326 | { |
178 | amb | 327 | for(arg=1;arg<argc;arg++) |
179 | { | ||
180 | FILE *file; | ||
181 | |||
182 | if(argv[arg][0]=='-' && argv[arg][1]=='-') | ||
183 | continue; | ||
184 | |||
185 | file=fopen(argv[arg],"rb"); | ||
186 | |||
187 | if(!file) | ||
188 | { | ||
189 | amb | 330 | fprintf(stderr,"Cannot open file '%s' for reading [%s].\n",argv[arg],strerror(errno)); |
190 | amb | 327 | exit(EXIT_FAILURE); |
191 | } | ||
192 | |||
193 | printf("\nParse OSM Data [%s]\n==============\n\n",argv[arg]); | ||
194 | fflush(stdout); | ||
195 | |||
196 | amb | 347 | ParseOSM(file,Nodes,Segments,Ways,&profile); |
197 | amb | 327 | |
198 | fclose(file); | ||
199 | } | ||
200 | } | ||
201 | else if(!option_process_only) | ||
202 | { | ||
203 | amb | 326 | printf("\nParse OSM Data\n==============\n\n"); |
204 | fflush(stdout); | ||
205 | amb | 2 | |
206 | amb | 347 | ParseOSM(stdin,Nodes,Segments,Ways,&profile); |
207 | amb | 326 | } |
208 | amb | 80 | |
209 | amb | 326 | if(option_parse_only) |
210 | { | ||
211 | FreeNodeList(Nodes,1); | ||
212 | FreeSegmentList(Segments,1); | ||
213 | FreeWayList(Ways,1); | ||
214 | |||
215 | return(0); | ||
216 | } | ||
217 | |||
218 | amb | 229 | /* Process the data */ |
219 | |||
220 | printf("\nProcess OSM Data\n================\n\n"); | ||
221 | amb | 227 | fflush(stdout); |
222 | amb | 8 | |
223 | amb | 275 | /* Sort the nodes, segments and ways */ |
224 | amb | 263 | |
225 | SortNodeList(Nodes); | ||
226 | |||
227 | amb | 275 | SortSegmentList(Segments); |
228 | amb | 80 | |
229 | amb | 256 | SortWayList(Ways); |
230 | amb | 87 | |
231 | amb | 279 | /* Remove bad segments (must be after sorting the nodes and segments) */ |
232 | amb | 247 | |
233 | amb | 256 | RemoveBadSegments(Nodes,Segments); |
234 | amb | 87 | |
235 | amb | 247 | /* Remove non-highway nodes (must be after removing the bad segments) */ |
236 | amb | 66 | |
237 | amb | 256 | RemoveNonHighwayNodes(Nodes,Segments); |
238 | amb | 247 | |
239 | amb | 279 | /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */ |
240 | amb | 247 | |
241 | amb | 279 | UpdateSegments(Segments,Nodes,Ways); |
242 | amb | 66 | |
243 | |||
244 | amb | 258 | /* Repeated iteration on Super-Nodes and Super-Segments */ |
245 | amb | 58 | |
246 | do | ||
247 | { | ||
248 | amb | 229 | printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":""); |
249 | amb | 227 | fflush(stdout); |
250 | amb | 80 | |
251 | amb | 90 | if(iteration==0) |
252 | { | ||
253 | /* Select the super-nodes */ | ||
254 | amb | 58 | |
255 | amb | 256 | ChooseSuperNodes(Nodes,Segments,Ways); |
256 | amb | 58 | |
257 | amb | 90 | /* Select the super-segments */ |
258 | amb | 58 | |
259 | amb | 256 | SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration); |
260 | amb | 90 | } |
261 | else | ||
262 | { | ||
263 | amb | 97 | SegmentsX *SuperSegments2; |
264 | amb | 58 | |
265 | amb | 90 | /* Select the super-nodes */ |
266 | |||
267 | amb | 256 | ChooseSuperNodes(Nodes,SuperSegments,Ways); |
268 | amb | 90 | |
269 | /* Select the super-segments */ | ||
270 | |||
271 | amb | 256 | SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration); |
272 | amb | 90 | |
273 | amb | 282 | if(SuperSegments->xnumber==SuperSegments2->xnumber) |
274 | amb | 104 | quit=1; |
275 | |||
276 | amb | 326 | FreeSegmentList(SuperSegments,0); |
277 | amb | 90 | |
278 | amb | 97 | SuperSegments=SuperSegments2; |
279 | amb | 90 | } |
280 | |||
281 | amb | 275 | /* Sort the super-segments */ |
282 | amb | 58 | |
283 | amb | 275 | SortSegmentList(SuperSegments); |
284 | amb | 58 | |
285 | amb | 229 | /* Remove duplicated super-segments */ |
286 | |||
287 | amb | 279 | DeduplicateSegments(SuperSegments,Nodes,Ways); |
288 | amb | 229 | |
289 | amb | 89 | iteration++; |
290 | amb | 58 | |
291 | amb | 89 | if(iteration>max_iterations) |
292 | quit=1; | ||
293 | } | ||
294 | while(!quit); | ||
295 | amb | 58 | |
296 | amb | 229 | /* Combine the super-segments */ |
297 | |||
298 | printf("\nCombine Segments and Super-Segments\n===================================\n\n"); | ||
299 | amb | 227 | fflush(stdout); |
300 | amb | 58 | |
301 | amb | 104 | /* Merge the super-segments */ |
302 | |||
303 | amb | 256 | MergedSegments=MergeSuperSegments(Segments,SuperSegments); |
304 | amb | 104 | |
305 | amb | 326 | FreeSegmentList(Segments,0); |
306 | amb | 256 | |
307 | amb | 326 | FreeSegmentList(SuperSegments,0); |
308 | amb | 58 | |
309 | amb | 256 | Segments=MergedSegments; |
310 | amb | 90 | |
311 | amb | 275 | /* Rotate segments so that node1<node2 */ |
312 | amb | 256 | |
313 | amb | 275 | RotateSegments(Segments); |
314 | amb | 256 | |
315 | amb | 275 | /* Sort the segments */ |
316 | amb | 258 | |
317 | amb | 275 | SortSegmentList(Segments); |
318 | amb | 258 | |
319 | amb | 275 | /* Remove duplicated segments */ |
320 | |||
321 | amb | 279 | DeduplicateSegments(Segments,Nodes,Ways); |
322 | amb | 275 | |
323 | amb | 229 | /* Cross reference the nodes and segments */ |
324 | amb | 90 | |
325 | amb | 229 | printf("\nCross-Reference Nodes and Segments\n==================================\n\n"); |
326 | fflush(stdout); | ||
327 | amb | 90 | |
328 | amb | 212 | /* Sort the node list geographically */ |
329 | amb | 209 | |
330 | amb | 256 | SortNodeListGeographically(Nodes); |
331 | amb | 212 | |
332 | /* Create the real segments and nodes */ | ||
333 | |||
334 | amb | 256 | CreateRealNodes(Nodes,iteration); |
335 | amb | 212 | |
336 | amb | 256 | CreateRealSegments(Segments,Ways); |
337 | amb | 209 | |
338 | amb | 104 | /* Fix the segment and node indexes */ |
339 | |||
340 | amb | 256 | IndexNodes(Nodes,Segments); |
341 | amb | 104 | |
342 | amb | 256 | IndexSegments(Segments,Nodes); |
343 | amb | 104 | |
344 | amb | 229 | /* Output the results */ |
345 | |||
346 | printf("\nWrite Out Database Files\n========================\n\n"); | ||
347 | fflush(stdout); | ||
348 | |||
349 | amb | 89 | /* Write out the nodes */ |
350 | amb | 58 | |
351 | amb | 256 | SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem")); |
352 | amb | 95 | |
353 | amb | 326 | FreeNodeList(Nodes,0); |
354 | amb | 226 | |
355 | amb | 89 | /* Write out the segments */ |
356 | amb | 58 | |
357 | amb | 256 | SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem")); |
358 | amb | 58 | |
359 | amb | 326 | FreeSegmentList(Segments,0); |
360 | amb | 226 | |
361 | amb | 89 | /* Write out the ways */ |
362 | amb | 58 | |
363 | amb | 307 | SaveWayList(Ways,FileName(dirname,prefix,"ways.mem"),&profile); |
364 | amb | 58 | |
365 | amb | 326 | FreeWayList(Ways,0); |
366 | amb | 226 | |
367 | amb | 2 | return(0); |
368 | } | ||
369 | amb | 342 | |
370 | |||
371 | /*++++++++++++++++++++++++++++++++++++++ | ||
372 | Print out the usage information. | ||
373 | |||
374 | int detail The level of detail to use - 0 = low, 1 = high. | ||
375 | ++++++++++++++++++++++++++++++++++++++*/ | ||
376 | |||
377 | static void print_usage(int detail) | ||
378 | { | ||
379 | fprintf(stderr, | ||
380 | "Usage: planetsplitter [--help]\n" | ||
381 | " [--dir=<dirname>] [--prefix=<name>]\n" | ||
382 | amb | 358 | " [--slim] [--sort-ram-size=<size>]\n" |
383 | " [--tmpdir=<dirname>]\n" | ||
384 | amb | 342 | " [--parse-only | --process-only]\n" |
385 | " [--max-iterations=<number>]\n" | ||
386 | " [--transport=<transport> ...]\n" | ||
387 | " [--not-highway=<highway> ...]\n" | ||
388 | " [--not-property=<property> ...]\n" | ||
389 | " [<filename.osm> ...]\n"); | ||
390 | |||
391 | if(detail) | ||
392 | fprintf(stderr, | ||
393 | "\n" | ||
394 | "--help Prints this information.\n" | ||
395 | "\n" | ||
396 | "--dir=<dirname> The directory containing the routing database.\n" | ||
397 | "--prefix=<name> The filename prefix for the routing database.\n" | ||
398 | "\n" | ||
399 | "--slim Use less RAM and more temporary files.\n" | ||
400 | amb | 358 | "--sort-ram-size=<size> The amount of RAM (in MB) to use for data sorting\n" |
401 | " (defaults to 64MB with '--slim' or 256MB otherwise.)\n" | ||
402 | amb | 342 | "--tmpdir=<dirname> The directory name for temporary files.\n" |
403 | amb | 358 | " (defaults to the '--dir' option directory.)\n" |
404 | amb | 342 | "\n" |
405 | "--parse-only Parse the input OSM files and store the results.\n" | ||
406 | "--process-only Process the stored results from previous option.\n" | ||
407 | "\n" | ||
408 | "--max-iterations=<number> The number of iterations for finding super-nodes.\n" | ||
409 | "\n" | ||
410 | "--transport=<transport> Store only data usable by the selected transports.\n" | ||
411 | "--not-highway=<highway> Ignore highways of the selected types.\n" | ||
412 | "--not-property=<property> Ignore highway properties of the selected types.\n" | ||
413 | "\n" | ||
414 | amb | 358 | "<filename.osm> ... The name(s) of the file(s) to process (by default\n" |
415 | " data is read from standard input).\n" | ||
416 | amb | 342 | "\n" |
417 | "<transport> defaults to all but can be set to:\n" | ||
418 | "%s" | ||
419 | "\n" | ||
420 | "<highway> can be selected from:\n" | ||
421 | "%s" | ||
422 | "\n" | ||
423 | "<property> can be selected from:\n" | ||
424 | "%s", | ||
425 | TransportList(),HighwayList(),PropertyList()); | ||
426 | |||
427 | exit(!detail); | ||
428 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |