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