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 1412 -
(hide annotations)
(download)
(as text)
Sat Jun 22 18:43:50 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 20660 byte(s)
Sat Jun 22 18:43:50 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 20660 byte(s)
Create simple OpenFile() and CloseFile() functions for those files which are used by the parsers (they just call open() and close() internally).
1 | amb | 2 | /*************************************** |
2 | OSM planet file splitter. | ||
3 | amb | 151 | |
4 | Part of the Routino routing software. | ||
5 | amb | 2 | ******************/ /****************** |
6 | amb | 1268 | This file Copyright 2008-2013 Andrew M. Bishop |
7 | amb | 2 | |
8 | amb | 151 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | amb | 2 | ***************************************/ |
21 | |||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | amb | 1192 | #include <unistd.h> |
26 | amb | 60 | #include <string.h> |
27 | amb | 330 | #include <errno.h> |
28 | amb | 2 | |
29 | amb | 449 | #include "types.h" |
30 | #include "ways.h" | ||
31 | |||
32 | amb | 199 | #include "typesx.h" |
33 | amb | 109 | #include "nodesx.h" |
34 | #include "segmentsx.h" | ||
35 | #include "waysx.h" | ||
36 | amb | 498 | #include "relationsx.h" |
37 | amb | 109 | #include "superx.h" |
38 | amb | 949 | #include "prunex.h" |
39 | amb | 449 | |
40 | #include "files.h" | ||
41 | amb | 519 | #include "logging.h" |
42 | amb | 1319 | #include "errorlogx.h" |
43 | amb | 449 | #include "functions.h" |
44 | amb | 940 | #include "osmparser.h" |
45 | amb | 395 | #include "tagging.h" |
46 | amb | 1194 | #include "uncompress.h" |
47 | amb | 2 | |
48 | |||
49 | amb | 395 | /* Global variables */ |
50 | amb | 284 | |
51 | amb | 256 | /*+ The name of the temporary directory. +*/ |
52 | amb | 284 | char *option_tmpdirname=NULL; |
53 | amb | 249 | |
54 | amb | 358 | /*+ The amount of RAM to use for filesorting. +*/ |
55 | size_t option_filesort_ramsize=0; | ||
56 | amb | 284 | |
57 | amb | 991 | /*+ The number of threads to use for filesorting. +*/ |
58 | int option_filesort_threads=1; | ||
59 | amb | 358 | |
60 | amb | 991 | |
61 | amb | 342 | /* Local functions */ |
62 | |||
63 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err); |
64 | amb | 342 | |
65 | |||
66 | /*++++++++++++++++++++++++++++++++++++++ | ||
67 | amb | 395 | The main program for the planetsplitter. |
68 | amb | 342 | ++++++++++++++++++++++++++++++++++++++*/ |
69 | |||
70 | amb | 2 | int main(int argc,char** argv) |
71 | { | ||
72 | amb | 1314 | NodesX *OSMNodes; |
73 | SegmentsX *OSMSegments,*SuperSegments=NULL,*MergedSegments=NULL; | ||
74 | WaysX *OSMWays; | ||
75 | RelationsX *OSMRelations; | ||
76 | amb | 498 | int iteration=0,quit=0; |
77 | amb | 861 | int max_iterations=5; |
78 | amb | 804 | char *dirname=NULL,*prefix=NULL,*tagging=NULL,*errorlog=NULL; |
79 | amb | 1140 | int option_parse_only=0,option_process_only=0; |
80 | amb | 1171 | int option_append=0,option_keep=0,option_changes=0; |
81 | amb | 498 | int option_filenames=0; |
82 | amb | 975 | int option_prune_isolated=500,option_prune_short=5,option_prune_straight=3; |
83 | amb | 498 | int arg; |
84 | amb | 26 | |
85 | amb | 1398 | printf_program_start(); |
86 | amb | 982 | |
87 | amb | 82 | /* Parse the command line arguments */ |
88 | |||
89 | amb | 327 | for(arg=1;arg<argc;arg++) |
90 | amb | 60 | { |
91 | amb | 327 | if(!strcmp(argv[arg],"--help")) |
92 | amb | 490 | print_usage(1,NULL,NULL); |
93 | amb | 1202 | else if(!strncmp(argv[arg],"--dir=",6)) |
94 | dirname=&argv[arg][6]; | ||
95 | else if(!strncmp(argv[arg],"--prefix=",9)) | ||
96 | prefix=&argv[arg][9]; | ||
97 | amb | 358 | else if(!strncmp(argv[arg],"--sort-ram-size=",16)) |
98 | option_filesort_ramsize=atoi(&argv[arg][16]); | ||
99 | amb | 991 | #if defined(USE_PTHREADS) && USE_PTHREADS |
100 | else if(!strncmp(argv[arg],"--sort-threads=",15)) | ||
101 | option_filesort_threads=atoi(&argv[arg][15]); | ||
102 | #endif | ||
103 | amb | 327 | else if(!strncmp(argv[arg],"--tmpdir=",9)) |
104 | option_tmpdirname=&argv[arg][9]; | ||
105 | amb | 1202 | else if(!strncmp(argv[arg],"--tagging=",10)) |
106 | tagging=&argv[arg][10]; | ||
107 | else if(!strcmp(argv[arg],"--loggable")) | ||
108 | option_loggable=1; | ||
109 | else if(!strcmp(argv[arg],"--logtime")) | ||
110 | option_logtime=1; | ||
111 | else if(!strcmp(argv[arg],"--errorlog")) | ||
112 | errorlog="error.log"; | ||
113 | else if(!strncmp(argv[arg],"--errorlog=",11)) | ||
114 | errorlog=&argv[arg][11]; | ||
115 | amb | 327 | else if(!strcmp(argv[arg],"--parse-only")) |
116 | amb | 326 | option_parse_only=1; |
117 | amb | 327 | else if(!strcmp(argv[arg],"--process-only")) |
118 | amb | 326 | option_process_only=1; |
119 | amb | 1120 | else if(!strcmp(argv[arg],"--append")) |
120 | option_append=1; | ||
121 | amb | 1167 | else if(!strcmp(argv[arg],"--keep")) |
122 | option_keep=1; | ||
123 | amb | 1140 | else if(!strcmp(argv[arg],"--changes")) |
124 | option_changes=1; | ||
125 | amb | 327 | else if(!strncmp(argv[arg],"--max-iterations=",17)) |
126 | max_iterations=atoi(&argv[arg][17]); | ||
127 | amb | 953 | else if(!strncmp(argv[arg],"--prune",7)) |
128 | { | ||
129 | amb | 975 | if(!strcmp(&argv[arg][7],"-none")) |
130 | option_prune_isolated=option_prune_short=option_prune_straight=0; | ||
131 | amb | 953 | else if(!strncmp(&argv[arg][7],"-isolated=",10)) |
132 | amb | 975 | option_prune_isolated=atoi(&argv[arg][17]); |
133 | amb | 964 | else if(!strncmp(&argv[arg][7],"-short=",7)) |
134 | amb | 975 | option_prune_short=atoi(&argv[arg][14]); |
135 | amb | 966 | else if(!strncmp(&argv[arg][7],"-straight=",10)) |
136 | amb | 975 | option_prune_straight=atoi(&argv[arg][17]); |
137 | amb | 953 | else |
138 | print_usage(0,argv[arg],NULL); | ||
139 | } | ||
140 | amb | 327 | else if(argv[arg][0]=='-' && argv[arg][1]=='-') |
141 | amb | 490 | print_usage(0,argv[arg],NULL); |
142 | amb | 327 | else |
143 | option_filenames++; | ||
144 | amb | 60 | } |
145 | amb | 26 | |
146 | amb | 395 | /* Check the specified command line options */ |
147 | |||
148 | amb | 326 | if(option_parse_only && option_process_only) |
149 | amb | 490 | print_usage(0,NULL,"Cannot use '--parse-only' and '--process-only' at the same time."); |
150 | amb | 326 | |
151 | amb | 1120 | if(option_append && option_process_only) |
152 | print_usage(0,NULL,"Cannot use '--append' and '--process-only' at the same time."); | ||
153 | |||
154 | amb | 327 | if(option_filenames && option_process_only) |
155 | amb | 490 | print_usage(0,NULL,"Cannot use '--process-only' and filenames at the same time."); |
156 | amb | 327 | |
157 | amb | 1224 | if(!option_filenames && !option_process_only) |
158 | print_usage(0,NULL,"File names must be specified unless using '--process-only'"); | ||
159 | |||
160 | amb | 358 | if(!option_filesort_ramsize) |
161 | { | ||
162 | amb | 452 | #if SLIM |
163 | amb | 940 | option_filesort_ramsize=64*1024*1024; |
164 | amb | 452 | #else |
165 | amb | 940 | option_filesort_ramsize=256*1024*1024; |
166 | amb | 452 | #endif |
167 | amb | 358 | } |
168 | else | ||
169 | option_filesort_ramsize*=1024*1024; | ||
170 | |||
171 | amb | 284 | if(!option_tmpdirname) |
172 | amb | 252 | { |
173 | if(!dirname) | ||
174 | amb | 284 | option_tmpdirname="."; |
175 | amb | 252 | else |
176 | amb | 284 | option_tmpdirname=dirname; |
177 | amb | 252 | } |
178 | |||
179 | amb | 989 | if(!option_process_only) |
180 | amb | 395 | { |
181 | amb | 989 | if(tagging) |
182 | amb | 481 | { |
183 | amb | 989 | if(!ExistsFile(tagging)) |
184 | { | ||
185 | fprintf(stderr,"Error: The '--tagging' option specifies a file that does not exist.\n"); | ||
186 | amb | 1359 | exit(EXIT_FAILURE); |
187 | amb | 989 | } |
188 | amb | 481 | } |
189 | else | ||
190 | { | ||
191 | amb | 989 | if(ExistsFile(FileName(dirname,prefix,"tagging.xml"))) |
192 | tagging=FileName(dirname,prefix,"tagging.xml"); | ||
193 | else if(ExistsFile(FileName(DATADIR,NULL,"tagging.xml"))) | ||
194 | tagging=FileName(DATADIR,NULL,"tagging.xml"); | ||
195 | else | ||
196 | { | ||
197 | fprintf(stderr,"Error: The '--tagging' option was not used and the default 'tagging.xml' does not exist.\n"); | ||
198 | amb | 1359 | exit(EXIT_FAILURE); |
199 | amb | 989 | } |
200 | } | ||
201 | |||
202 | if(ParseXMLTaggingRules(tagging)) | ||
203 | { | ||
204 | fprintf(stderr,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging); | ||
205 | amb | 1359 | exit(EXIT_FAILURE); |
206 | amb | 481 | } |
207 | } | ||
208 | amb | 395 | |
209 | amb | 498 | /* Create new node, segment, way and relation variables */ |
210 | amb | 82 | |
211 | amb | 1314 | OSMNodes=NewNodeList(option_append||option_changes,option_process_only); |
212 | amb | 275 | |
213 | amb | 1314 | OSMWays=NewWayList(option_append||option_changes,option_process_only); |
214 | amb | 26 | |
215 | amb | 1314 | OSMRelations=NewRelationList(option_append||option_changes,option_process_only); |
216 | amb | 498 | |
217 | amb | 804 | /* Create the error log file */ |
218 | |||
219 | amb | 809 | if(errorlog) |
220 | amb | 1313 | open_errorlog(FileName(dirname,prefix,errorlog),option_append||option_changes||option_process_only,option_keep); |
221 | amb | 804 | |
222 | amb | 89 | /* Parse the file */ |
223 | amb | 2 | |
224 | amb | 989 | if(!option_process_only) |
225 | { | ||
226 | amb | 1224 | for(arg=1;arg<argc;arg++) |
227 | amb | 989 | { |
228 | amb | 1224 | int fd; |
229 | amb | 1227 | char *filename,*p; |
230 | amb | 327 | |
231 | amb | 1224 | if(argv[arg][0]=='-' && argv[arg][1]=='-') |
232 | continue; | ||
233 | amb | 327 | |
234 | amb | 1227 | filename=strcpy(malloc(strlen(argv[arg])+1),argv[arg]); |
235 | amb | 327 | |
236 | amb | 1412 | fd=OpenFile(filename); |
237 | amb | 1227 | |
238 | if((p=strstr(filename,".bz2")) && !strcmp(p,".bz2")) | ||
239 | { | ||
240 | amb | 1224 | fd=Uncompress_Bzip2(fd); |
241 | amb | 1227 | *p=0; |
242 | } | ||
243 | amb | 1194 | |
244 | amb | 1227 | if((p=strstr(filename,".gz")) && !strcmp(p,".gz")) |
245 | { | ||
246 | amb | 1224 | fd=Uncompress_Gzip(fd); |
247 | amb | 1227 | *p=0; |
248 | } | ||
249 | amb | 1196 | |
250 | amb | 1224 | if(option_changes) |
251 | { | ||
252 | amb | 1227 | printf("\nParse OSC Data [%s]\n==============\n\n",filename); |
253 | amb | 1224 | fflush(stdout); |
254 | |||
255 | amb | 1227 | if((p=strstr(filename,".pbf")) && !strcmp(p,".pbf")) |
256 | amb | 1140 | { |
257 | amb | 1226 | logassert(0,"Unable to read a PBF file to apply changes (format does not permit this)"); |
258 | amb | 1140 | } |
259 | amb | 1227 | else if((p=strstr(filename,".o5c")) && !strcmp(p,".o5c")) |
260 | { | ||
261 | amb | 1339 | if(ParseO5CFile(fd,OSMNodes,OSMWays,OSMRelations)) |
262 | amb | 1227 | exit(EXIT_FAILURE); |
263 | } | ||
264 | amb | 1140 | else |
265 | { | ||
266 | amb | 1339 | if(ParseOSCFile(fd,OSMNodes,OSMWays,OSMRelations)) |
267 | amb | 1224 | exit(EXIT_FAILURE); |
268 | amb | 1140 | } |
269 | amb | 989 | } |
270 | amb | 1224 | else |
271 | amb | 1140 | { |
272 | amb | 1227 | printf("\nParse OSM Data [%s]\n==============\n\n",filename); |
273 | amb | 1140 | fflush(stdout); |
274 | amb | 2 | |
275 | amb | 1227 | if((p=strstr(filename,".pbf")) && !strcmp(p,".pbf")) |
276 | amb | 1224 | { |
277 | amb | 1339 | if(ParsePBFFile(fd,OSMNodes,OSMWays,OSMRelations)) |
278 | amb | 1224 | exit(EXIT_FAILURE); |
279 | } | ||
280 | amb | 1227 | else if((p=strstr(filename,".o5m")) && !strcmp(p,".o5m")) |
281 | { | ||
282 | amb | 1339 | if(ParseO5MFile(fd,OSMNodes,OSMWays,OSMRelations)) |
283 | amb | 1227 | exit(EXIT_FAILURE); |
284 | } | ||
285 | amb | 1224 | else |
286 | { | ||
287 | amb | 1339 | if(ParseOSMFile(fd,OSMNodes,OSMWays,OSMRelations)) |
288 | amb | 1224 | exit(EXIT_FAILURE); |
289 | } | ||
290 | amb | 1140 | } |
291 | |||
292 | amb | 1412 | CloseFile(fd); |
293 | amb | 1227 | |
294 | free(filename); | ||
295 | amb | 989 | } |
296 | amb | 80 | |
297 | amb | 989 | DeleteXMLTaggingRules(); |
298 | } | ||
299 | |||
300 | amb | 1314 | FinishNodeList(OSMNodes); |
301 | FinishWayList(OSMWays); | ||
302 | FinishRelationList(OSMRelations); | ||
303 | amb | 1139 | |
304 | amb | 1157 | if(option_parse_only) |
305 | amb | 326 | { |
306 | amb | 1314 | FreeNodeList(OSMNodes,1); |
307 | FreeWayList(OSMWays,1); | ||
308 | FreeRelationList(OSMRelations,1); | ||
309 | amb | 326 | |
310 | return(0); | ||
311 | } | ||
312 | |||
313 | amb | 1120 | |
314 | amb | 1151 | /* Sort the data */ |
315 | amb | 229 | |
316 | amb | 1151 | printf("\nSort OSM Data\n=============\n\n"); |
317 | amb | 227 | fflush(stdout); |
318 | amb | 8 | |
319 | amb | 1355 | /* Sort the nodes, ways and relations */ |
320 | amb | 263 | |
321 | amb | 1314 | SortNodeList(OSMNodes); |
322 | amb | 263 | |
323 | amb | 1314 | SortWayList(OSMWays); |
324 | amb | 87 | |
325 | amb | 1314 | SortRelationList(OSMRelations); |
326 | amb | 559 | |
327 | amb | 1151 | /* Process the data */ |
328 | |||
329 | printf("\nProcess OSM Data\n================\n\n"); | ||
330 | fflush(stdout); | ||
331 | |||
332 | amb | 1350 | /* Remove non-highway nodes by looking through the ways */ |
333 | |||
334 | RemoveNonHighwayNodes(OSMNodes,OSMWays,option_keep||option_changes); | ||
335 | |||
336 | amb | 1348 | /* Separate the segments and way names and sort them. */ |
337 | amb | 1339 | |
338 | amb | 1349 | OSMSegments=SplitWays(OSMWays,OSMNodes,option_keep||option_changes); |
339 | amb | 1339 | |
340 | amb | 1348 | SortWayNames(OSMWays); |
341 | |||
342 | amb | 1339 | SortSegmentList(OSMSegments); |
343 | |||
344 | amb | 1352 | /* Process the segments and index them */ |
345 | amb | 549 | |
346 | amb | 1351 | ProcessSegments(OSMSegments,OSMNodes,OSMWays); |
347 | amb | 549 | |
348 | amb | 1352 | IndexSegments(OSMSegments,OSMNodes,OSMWays); |
349 | |||
350 | amb | 1353 | /* Process the route relations and turn relations (must be before compacting the ways) */ |
351 | amb | 498 | |
352 | amb | 1314 | ProcessRouteRelations(OSMRelations,OSMWays,option_keep||option_changes); |
353 | amb | 498 | |
354 | amb | 1353 | ProcessTurnRelations(OSMRelations,OSMNodes,OSMSegments,OSMWays,option_keep||option_changes); |
355 | amb | 498 | |
356 | amb | 1353 | /* Compact the ways (must be after processing turn relations) */ |
357 | amb | 643 | |
358 | amb | 1314 | CompactWayList(OSMWays,OSMSegments); |
359 | amb | 1100 | |
360 | /* Index the segments */ | ||
361 | |||
362 | amb | 1314 | IndexSegments(OSMSegments,OSMNodes,OSMWays); |
363 | amb | 1100 | |
364 | amb | 949 | /* Prune unwanted nodes/segments. */ |
365 | amb | 645 | |
366 | amb | 975 | if(option_prune_straight || option_prune_isolated || option_prune_short) |
367 | amb | 949 | { |
368 | amb | 1098 | printf("\nPrune Unneeded Data\n===================\n\n"); |
369 | fflush(stdout); | ||
370 | |||
371 | amb | 1314 | StartPruning(OSMNodes,OSMSegments,OSMWays); |
372 | amb | 949 | |
373 | amb | 975 | if(option_prune_isolated) |
374 | amb | 1314 | PruneIsolatedRegions(OSMNodes,OSMSegments,OSMWays,option_prune_isolated); |
375 | amb | 953 | |
376 | amb | 975 | if(option_prune_short) |
377 | amb | 1314 | PruneShortSegments(OSMNodes,OSMSegments,OSMWays,option_prune_short); |
378 | amb | 964 | |
379 | amb | 1268 | if(option_prune_straight) |
380 | amb | 1314 | PruneStraightHighwayNodes(OSMNodes,OSMSegments,OSMWays,option_prune_straight); |
381 | amb | 1268 | |
382 | amb | 1314 | FinishPruning(OSMNodes,OSMSegments,OSMWays); |
383 | amb | 1098 | |
384 | amb | 1355 | /* Remove the pruned nodes, segments, ways and relations and update the indexes */ |
385 | amb | 1098 | |
386 | amb | 1314 | RemovePrunedNodes(OSMNodes,OSMSegments); |
387 | RemovePrunedSegments(OSMSegments,OSMWays); | ||
388 | CompactWayList(OSMWays,OSMSegments); | ||
389 | RemovePrunedTurnRelations(OSMRelations,OSMNodes); | ||
390 | amb | 1355 | |
391 | amb | 1314 | IndexSegments(OSMSegments,OSMNodes,OSMWays); |
392 | amb | 949 | } |
393 | |||
394 | amb | 258 | /* Repeated iteration on Super-Nodes and Super-Segments */ |
395 | amb | 58 | |
396 | do | ||
397 | { | ||
398 | amb | 1302 | index_t nsuper; |
399 | amb | 650 | |
400 | amb | 229 | printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":""); |
401 | amb | 227 | fflush(stdout); |
402 | amb | 80 | |
403 | amb | 90 | if(iteration==0) |
404 | { | ||
405 | /* Select the super-nodes */ | ||
406 | amb | 58 | |
407 | amb | 1314 | ChooseSuperNodes(OSMNodes,OSMSegments,OSMWays); |
408 | amb | 58 | |
409 | amb | 90 | /* Select the super-segments */ |
410 | amb | 58 | |
411 | amb | 1314 | SuperSegments=CreateSuperSegments(OSMNodes,OSMSegments,OSMWays); |
412 | amb | 650 | |
413 | amb | 1314 | nsuper=OSMSegments->number; |
414 | amb | 90 | } |
415 | else | ||
416 | { | ||
417 | amb | 97 | SegmentsX *SuperSegments2; |
418 | amb | 58 | |
419 | amb | 90 | /* Select the super-nodes */ |
420 | |||
421 | amb | 1314 | ChooseSuperNodes(OSMNodes,SuperSegments,OSMWays); |
422 | amb | 90 | |
423 | /* Select the super-segments */ | ||
424 | |||
425 | amb | 1314 | SuperSegments2=CreateSuperSegments(OSMNodes,SuperSegments,OSMWays); |
426 | amb | 90 | |
427 | amb | 650 | nsuper=SuperSegments->number; |
428 | amb | 104 | |
429 | amb | 1339 | FreeSegmentList(SuperSegments); |
430 | amb | 90 | |
431 | amb | 97 | SuperSegments=SuperSegments2; |
432 | amb | 90 | } |
433 | |||
434 | amb | 1132 | /* Sort the super-segments and remove duplicates */ |
435 | amb | 58 | |
436 | amb | 1314 | DeduplicateSuperSegments(SuperSegments,OSMWays); |
437 | amb | 58 | |
438 | amb | 643 | /* Index the segments */ |
439 | |||
440 | amb | 1314 | IndexSegments(SuperSegments,OSMNodes,OSMWays); |
441 | amb | 643 | |
442 | /* Check for end condition */ | ||
443 | |||
444 | amb | 650 | if(SuperSegments->number==nsuper) |
445 | quit=1; | ||
446 | |||
447 | amb | 89 | iteration++; |
448 | amb | 58 | |
449 | amb | 89 | if(iteration>max_iterations) |
450 | quit=1; | ||
451 | } | ||
452 | while(!quit); | ||
453 | amb | 58 | |
454 | amb | 229 | /* Combine the super-segments */ |
455 | |||
456 | printf("\nCombine Segments and Super-Segments\n===================================\n\n"); | ||
457 | amb | 227 | fflush(stdout); |
458 | amb | 58 | |
459 | amb | 104 | /* Merge the super-segments */ |
460 | |||
461 | amb | 1314 | MergedSegments=MergeSuperSegments(OSMSegments,SuperSegments); |
462 | amb | 104 | |
463 | amb | 1339 | FreeSegmentList(OSMSegments); |
464 | amb | 256 | |
465 | amb | 1339 | FreeSegmentList(SuperSegments); |
466 | amb | 58 | |
467 | amb | 1314 | OSMSegments=MergedSegments; |
468 | amb | 90 | |
469 | amb | 1133 | /* Re-index the merged segments */ |
470 | amb | 258 | |
471 | amb | 1314 | IndexSegments(OSMSegments,OSMNodes,OSMWays); |
472 | amb | 275 | |
473 | amb | 229 | /* Cross reference the nodes and segments */ |
474 | amb | 90 | |
475 | amb | 229 | printf("\nCross-Reference Nodes and Segments\n==================================\n\n"); |
476 | fflush(stdout); | ||
477 | amb | 90 | |
478 | amb | 1107 | /* Sort the nodes and segments geographically */ |
479 | amb | 645 | |
480 | amb | 1314 | SortNodeListGeographically(OSMNodes); |
481 | amb | 645 | |
482 | amb | 1314 | SortSegmentListGeographically(OSMSegments,OSMNodes); |
483 | amb | 209 | |
484 | amb | 1107 | /* Re-index the segments */ |
485 | amb | 212 | |
486 | amb | 1314 | IndexSegments(OSMSegments,OSMNodes,OSMWays); |
487 | amb | 665 | |
488 | amb | 1108 | /* Sort the turn relations geographically */ |
489 | amb | 212 | |
490 | amb | 1314 | SortTurnRelationListGeographically(OSMRelations,OSMNodes,OSMSegments); |
491 | amb | 551 | |
492 | amb | 229 | /* Output the results */ |
493 | |||
494 | printf("\nWrite Out Database Files\n========================\n\n"); | ||
495 | fflush(stdout); | ||
496 | |||
497 | amb | 89 | /* Write out the nodes */ |
498 | amb | 58 | |
499 | amb | 1314 | SaveNodeList(OSMNodes,FileName(dirname,prefix,"nodes.mem"),OSMSegments); |
500 | amb | 95 | |
501 | amb | 89 | /* Write out the segments */ |
502 | amb | 58 | |
503 | amb | 1314 | SaveSegmentList(OSMSegments,FileName(dirname,prefix,"segments.mem")); |
504 | amb | 58 | |
505 | amb | 89 | /* Write out the ways */ |
506 | amb | 58 | |
507 | amb | 1314 | SaveWayList(OSMWays,FileName(dirname,prefix,"ways.mem")); |
508 | amb | 58 | |
509 | amb | 549 | /* Write out the relations */ |
510 | |||
511 | amb | 1314 | SaveRelationList(OSMRelations,FileName(dirname,prefix,"relations.mem")); |
512 | amb | 549 | |
513 | amb | 1317 | /* Close the error log file and process the data */ |
514 | amb | 804 | |
515 | amb | 809 | if(errorlog) |
516 | amb | 1317 | { |
517 | amb | 809 | close_errorlog(); |
518 | amb | 804 | |
519 | amb | 1317 | if(option_keep) |
520 | { | ||
521 | amb | 1362 | ErrorLogsX *OSMErrorLogs; |
522 | |||
523 | amb | 1317 | printf("\nCreate Error Log\n================\n\n"); |
524 | fflush(stdout); | ||
525 | |||
526 | amb | 1362 | OSMErrorLogs=NewErrorLogList(); |
527 | amb | 1317 | |
528 | amb | 1362 | ProcessErrorLogs(OSMErrorLogs,OSMNodes,OSMWays,OSMRelations); |
529 | amb | 1317 | |
530 | amb | 1362 | SortErrorLogsGeographically(OSMErrorLogs); |
531 | |||
532 | SaveErrorLogs(OSMErrorLogs,FileName(dirname,prefix,"errorlogs.mem")); | ||
533 | |||
534 | FreeErrorLogList(OSMErrorLogs); | ||
535 | amb | 1317 | } |
536 | } | ||
537 | |||
538 | amb | 1314 | /* Free the memory (delete the temporary files) */ |
539 | |||
540 | FreeNodeList(OSMNodes,0); | ||
541 | FreeWayList(OSMWays,0); | ||
542 | FreeRelationList(OSMRelations,0); | ||
543 | |||
544 | amb | 1339 | FreeSegmentList(OSMSegments); |
545 | |||
546 | amb | 1398 | printf_program_end(); |
547 | amb | 982 | |
548 | amb | 2 | return(0); |
549 | } | ||
550 | amb | 342 | |
551 | |||
552 | /*++++++++++++++++++++++++++++++++++++++ | ||
553 | Print out the usage information. | ||
554 | |||
555 | int detail The level of detail to use - 0 = low, 1 = high. | ||
556 | amb | 490 | |
557 | const char *argerr The argument that gave the error (if there is one). | ||
558 | |||
559 | const char *err Other error message (if there is one). | ||
560 | amb | 342 | ++++++++++++++++++++++++++++++++++++++*/ |
561 | |||
562 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err) |
563 | amb | 342 | { |
564 | fprintf(stderr, | ||
565 | "Usage: planetsplitter [--help]\n" | ||
566 | " [--dir=<dirname>] [--prefix=<name>]\n" | ||
567 | amb | 991 | #if defined(USE_PTHREADS) && USE_PTHREADS |
568 | " [--sort-ram-size=<size>] [--sort-threads=<number>]\n" | ||
569 | #else | ||
570 | amb | 452 | " [--sort-ram-size=<size>]\n" |
571 | amb | 991 | #endif |
572 | amb | 358 | " [--tmpdir=<dirname>]\n" |
573 | amb | 953 | " [--tagging=<filename>]\n" |
574 | amb | 982 | " [--loggable] [--logtime]\n" |
575 | " [--errorlog[=<name>]]\n" | ||
576 | amb | 342 | " [--parse-only | --process-only]\n" |
577 | amb | 1167 | " [--append] [--keep] [--changes]\n" |
578 | amb | 342 | " [--max-iterations=<number>]\n" |
579 | amb | 975 | " [--prune-none]\n" |
580 | " [--prune-isolated=<len>]\n" | ||
581 | " [--prune-short=<len>]\n" | ||
582 | " [--prune-straight=<len>]\n" | ||
583 | amb | 1221 | " [<filename.osm> ... | <filename.osc> ...\n" |
584 | amb | 1227 | " | <filename.pbf> ...\n" |
585 | amb | 1366 | " | <filename.o5m> ... | <filename.o5c> ..." |
586 | amb | 1197 | #if defined(USE_BZIP2) && USE_BZIP2 |
587 | amb | 1227 | "\n | <filename.(osm|osc|o5m|o5c).bz2> ..." |
588 | amb | 1197 | #endif |
589 | #if defined(USE_GZIP) && USE_GZIP | ||
590 | amb | 1227 | "\n | <filename.(osm|osc|o5m|o5c).gz> ..." |
591 | amb | 1197 | #endif |
592 | "]\n"); | ||
593 | amb | 342 | |
594 | amb | 490 | if(argerr) |
595 | fprintf(stderr, | ||
596 | "\n" | ||
597 | "Error with command line parameter: %s\n",argerr); | ||
598 | |||
599 | amb | 491 | if(err) |
600 | amb | 490 | fprintf(stderr, |
601 | "\n" | ||
602 | "Error: %s\n",err); | ||
603 | |||
604 | amb | 342 | if(detail) |
605 | fprintf(stderr, | ||
606 | "\n" | ||
607 | "--help Prints this information.\n" | ||
608 | "\n" | ||
609 | "--dir=<dirname> The directory containing the routing database.\n" | ||
610 | "--prefix=<name> The filename prefix for the routing database.\n" | ||
611 | "\n" | ||
612 | amb | 358 | "--sort-ram-size=<size> The amount of RAM (in MB) to use for data sorting\n" |
613 | amb | 452 | #if SLIM |
614 | " (defaults to 64MB otherwise.)\n" | ||
615 | #else | ||
616 | " (defaults to 256MB otherwise.)\n" | ||
617 | #endif | ||
618 | amb | 991 | #if defined(USE_PTHREADS) && USE_PTHREADS |
619 | "--sort-threads=<number> The number of threads to use for data sorting.\n" | ||
620 | #endif | ||
621 | "\n" | ||
622 | amb | 342 | "--tmpdir=<dirname> The directory name for temporary files.\n" |
623 | amb | 358 | " (defaults to the '--dir' option directory.)\n" |
624 | amb | 342 | "\n" |
625 | amb | 953 | "--tagging=<filename> The name of the XML file containing the tagging rules\n" |
626 | " (defaults to 'tagging.xml' with '--dir' and\n" | ||
627 | " '--prefix' options or the file installed in\n" | ||
628 | " '" DATADIR "').\n" | ||
629 | amb | 342 | "\n" |
630 | amb | 519 | "--loggable Print progress messages suitable for logging to file.\n" |
631 | amb | 982 | "--logtime Print the elapsed time for each processing step.\n" |
632 | amb | 810 | "--errorlog[=<name>] Log parsing errors to 'error.log' or the given name\n" |
633 | amb | 804 | " (the '--dir' and '--prefix' options are applied).\n" |
634 | amb | 519 | "\n" |
635 | amb | 1140 | "--parse-only Parse the OSM/OSC file(s) and store the results.\n" |
636 | amb | 953 | "--process-only Process the stored results from previous option.\n" |
637 | amb | 1120 | "--append Parse the OSM file(s) and append to existing results.\n" |
638 | amb | 1167 | "--keep Keep the intermediate files after parsing & sorting.\n" |
639 | amb | 1140 | "--changes Parse the data as an OSC file and apply the changes.\n" |
640 | amb | 953 | "\n" |
641 | amb | 861 | "--max-iterations=<number> The number of iterations for finding super-nodes\n" |
642 | " (defaults to 5).\n" | ||
643 | amb | 342 | "\n" |
644 | amb | 975 | "--prune-none Disable the prune options below, they are re-enabled\n" |
645 | " by adding them to the command line after this option.\n" | ||
646 | amb | 1117 | "--prune-isolated=<len> Remove access from small disconnected segment groups\n" |
647 | amb | 975 | " (defaults to removing groups under 500m).\n" |
648 | "--prune-short=<len> Remove short segments (defaults to removing segments\n" | ||
649 | " up to a maximum length of 5m).\n" | ||
650 | "--prune-straight=<len> Remove nodes in almost straight highways (defaults to\n" | ||
651 | " removing nodes up to 3m offset from a straight line).\n" | ||
652 | amb | 395 | "\n" |
653 | amb | 1227 | "<filename.osm>, <filename.osc>, <filename.pbf>, <filename.o5m>, <filename.o5c>\n" |
654 | amb | 1224 | " The name(s) of the file(s) to read and parse.\n" |
655 | amb | 1227 | " Filenames ending '.pbf' read as PBF, filenames ending\n" |
656 | " '.o5m' or '.o5c' read as O5M/O5C, others as XML.\n" | ||
657 | amb | 1197 | #if defined(USE_BZIP2) && USE_BZIP2 |
658 | " Filenames ending '.bz2' will be bzip2 uncompressed.\n" | ||
659 | #endif | ||
660 | #if defined(USE_GZIP) && USE_GZIP | ||
661 | " Filenames ending '.gz' will be gzip uncompressed.\n" | ||
662 | #endif | ||
663 | amb | 342 | "\n" |
664 | "<transport> defaults to all but can be set to:\n" | ||
665 | "%s" | ||
666 | "\n" | ||
667 | "<highway> can be selected from:\n" | ||
668 | "%s" | ||
669 | "\n" | ||
670 | "<property> can be selected from:\n" | ||
671 | "%s", | ||
672 | TransportList(),HighwayList(),PropertyList()); | ||
673 | |||
674 | exit(!detail); | ||
675 | } |
Properties
Name | Value |
---|---|
cvs:description | Planet file splitter. |