Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 481 - (hide annotations) (download) (as text)
Sun Sep 5 18:26:01 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 11171 byte(s)
Use the installed tagging.xml, profiles.xml or translations.xml files as the
fallback option if no other given.

1 amb 2 /***************************************
2 amb 481 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.76 2010-09-05 18:26:01 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 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     #include "superx.h"
38 amb 449
39     #include "files.h"
40     #include "functions.h"
41     #include "functionsx.h"
42 amb 395 #include "tagging.h"
43 amb 2
44    
45 amb 395 /* Global variables */
46 amb 284
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 amb 395 The main program for the planetsplitter.
61 amb 342 ++++++++++++++++++++++++++++++++++++++*/
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 amb 395 char *dirname=NULL,*prefix=NULL,*tagging=NULL;
71 amb 327 int option_parse_only=0,option_process_only=0;
72     int option_filenames=0;
73 amb 398 int arg;
74 amb 26
75 amb 82 /* Parse the command line arguments */
76    
77 amb 327 for(arg=1;arg<argc;arg++)
78 amb 60 {
79 amb 327 if(!strcmp(argv[arg],"--help"))
80 amb 342 print_usage(1);
81 amb 358 else if(!strncmp(argv[arg],"--sort-ram-size=",16))
82     option_filesort_ramsize=atoi(&argv[arg][16]);
83 amb 327 else if(!strncmp(argv[arg],"--dir=",6))
84     dirname=&argv[arg][6];
85     else if(!strncmp(argv[arg],"--tmpdir=",9))
86     option_tmpdirname=&argv[arg][9];
87     else if(!strncmp(argv[arg],"--prefix=",9))
88     prefix=&argv[arg][9];
89     else if(!strcmp(argv[arg],"--parse-only"))
90 amb 326 option_parse_only=1;
91 amb 327 else if(!strcmp(argv[arg],"--process-only"))
92 amb 326 option_process_only=1;
93 amb 327 else if(!strncmp(argv[arg],"--max-iterations=",17))
94     max_iterations=atoi(&argv[arg][17]);
95 amb 395 else if(!strncmp(argv[arg],"--tagging=",10))
96     tagging=&argv[arg][10];
97 amb 327 else if(argv[arg][0]=='-' && argv[arg][1]=='-')
98 amb 342 print_usage(0);
99 amb 327 else
100     option_filenames++;
101 amb 60 }
102 amb 26
103 amb 395 /* Check the specified command line options */
104    
105 amb 326 if(option_parse_only && option_process_only)
106 amb 342 print_usage(0);
107 amb 326
108 amb 327 if(option_filenames && option_process_only)
109 amb 342 print_usage(0);
110 amb 327
111 amb 358 if(!option_filesort_ramsize)
112     {
113 amb 452 #if SLIM
114 amb 358 option_filesort_ramsize=64*1024*1024;
115 amb 452 #else
116 amb 358 option_filesort_ramsize=256*1024*1024;
117 amb 452 #endif
118 amb 358 }
119     else
120     option_filesort_ramsize*=1024*1024;
121    
122 amb 284 if(!option_tmpdirname)
123 amb 252 {
124     if(!dirname)
125 amb 284 option_tmpdirname=".";
126 amb 252 else
127 amb 284 option_tmpdirname=dirname;
128 amb 252 }
129    
130 amb 481 if(tagging)
131 amb 395 {
132 amb 481 if(!ExistsFile(tagging))
133     {
134     fprintf(stderr,"Error: The '--tagging' option specifies a file that does not exist.\n");
135     return(1);
136     }
137 amb 395 }
138 amb 481 else
139     {
140     if(ExistsFile(FileName(dirname,prefix,"tagging.xml")))
141     tagging=FileName(dirname,prefix,"tagging.xml");
142     else if(ExistsFile(FileName(DATADIR,NULL,"tagging.xml")))
143     tagging=FileName(DATADIR,NULL,"tagging.xml");
144     else
145     {
146     fprintf(stderr,"Error: The '--tagging' option was not used and the default 'tagging.xml' does not exist.\n");
147     return(1);
148     }
149     }
150 amb 395
151 amb 481 if(ParseXMLTaggingRules(tagging))
152 amb 395 {
153 amb 481 fprintf(stderr,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging);
154 amb 395 return(1);
155     }
156    
157 amb 275 /* Create new node, segment and way variables */
158 amb 82
159 amb 326 Nodes=NewNodeList(option_parse_only||option_process_only);
160 amb 275
161 amb 326 Segments=NewSegmentList(option_parse_only||option_process_only);
162 amb 275
163 amb 326 Ways=NewWayList(option_parse_only||option_process_only);
164 amb 26
165 amb 89 /* Parse the file */
166 amb 2
167 amb 327 if(option_filenames)
168 amb 326 {
169 amb 327 for(arg=1;arg<argc;arg++)
170     {
171     FILE *file;
172    
173     if(argv[arg][0]=='-' && argv[arg][1]=='-')
174     continue;
175    
176     file=fopen(argv[arg],"rb");
177    
178     if(!file)
179     {
180 amb 330 fprintf(stderr,"Cannot open file '%s' for reading [%s].\n",argv[arg],strerror(errno));
181 amb 327 exit(EXIT_FAILURE);
182     }
183    
184     printf("\nParse OSM Data [%s]\n==============\n\n",argv[arg]);
185     fflush(stdout);
186    
187 amb 398 if(ParseOSM(file,Nodes,Segments,Ways))
188 amb 395 exit(EXIT_FAILURE);
189 amb 327
190     fclose(file);
191     }
192     }
193     else if(!option_process_only)
194     {
195 amb 326 printf("\nParse OSM Data\n==============\n\n");
196     fflush(stdout);
197 amb 2
198 amb 398 if(ParseOSM(stdin,Nodes,Segments,Ways))
199 amb 395 exit(EXIT_FAILURE);
200 amb 326 }
201 amb 80
202 amb 326 if(option_parse_only)
203     {
204     FreeNodeList(Nodes,1);
205     FreeSegmentList(Segments,1);
206     FreeWayList(Ways,1);
207    
208     return(0);
209     }
210    
211 amb 229 /* Process the data */
212    
213     printf("\nProcess OSM Data\n================\n\n");
214 amb 227 fflush(stdout);
215 amb 8
216 amb 275 /* Sort the nodes, segments and ways */
217 amb 263
218     SortNodeList(Nodes);
219    
220 amb 275 SortSegmentList(Segments);
221 amb 80
222 amb 256 SortWayList(Ways);
223 amb 87
224 amb 279 /* Remove bad segments (must be after sorting the nodes and segments) */
225 amb 247
226 amb 256 RemoveBadSegments(Nodes,Segments);
227 amb 87
228 amb 247 /* Remove non-highway nodes (must be after removing the bad segments) */
229 amb 66
230 amb 256 RemoveNonHighwayNodes(Nodes,Segments);
231 amb 247
232 amb 279 /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */
233 amb 247
234 amb 279 UpdateSegments(Segments,Nodes,Ways);
235 amb 66
236    
237 amb 258 /* Repeated iteration on Super-Nodes and Super-Segments */
238 amb 58
239     do
240     {
241 amb 229 printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":"");
242 amb 227 fflush(stdout);
243 amb 80
244 amb 90 if(iteration==0)
245     {
246     /* Select the super-nodes */
247 amb 58
248 amb 256 ChooseSuperNodes(Nodes,Segments,Ways);
249 amb 58
250 amb 90 /* Select the super-segments */
251 amb 58
252 amb 256 SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration);
253 amb 90 }
254     else
255     {
256 amb 97 SegmentsX *SuperSegments2;
257 amb 58
258 amb 90 /* Select the super-nodes */
259    
260 amb 256 ChooseSuperNodes(Nodes,SuperSegments,Ways);
261 amb 90
262     /* Select the super-segments */
263    
264 amb 256 SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration);
265 amb 90
266 amb 282 if(SuperSegments->xnumber==SuperSegments2->xnumber)
267 amb 104 quit=1;
268    
269 amb 326 FreeSegmentList(SuperSegments,0);
270 amb 90
271 amb 97 SuperSegments=SuperSegments2;
272 amb 90 }
273    
274 amb 275 /* Sort the super-segments */
275 amb 58
276 amb 275 SortSegmentList(SuperSegments);
277 amb 58
278 amb 229 /* Remove duplicated super-segments */
279    
280 amb 279 DeduplicateSegments(SuperSegments,Nodes,Ways);
281 amb 229
282 amb 89 iteration++;
283 amb 58
284 amb 89 if(iteration>max_iterations)
285     quit=1;
286     }
287     while(!quit);
288 amb 58
289 amb 229 /* Combine the super-segments */
290    
291     printf("\nCombine Segments and Super-Segments\n===================================\n\n");
292 amb 227 fflush(stdout);
293 amb 58
294 amb 104 /* Merge the super-segments */
295    
296 amb 256 MergedSegments=MergeSuperSegments(Segments,SuperSegments);
297 amb 104
298 amb 326 FreeSegmentList(Segments,0);
299 amb 256
300 amb 326 FreeSegmentList(SuperSegments,0);
301 amb 58
302 amb 256 Segments=MergedSegments;
303 amb 90
304 amb 275 /* Rotate segments so that node1<node2 */
305 amb 256
306 amb 275 RotateSegments(Segments);
307 amb 256
308 amb 275 /* Sort the segments */
309 amb 258
310 amb 275 SortSegmentList(Segments);
311 amb 258
312 amb 275 /* Remove duplicated segments */
313    
314 amb 279 DeduplicateSegments(Segments,Nodes,Ways);
315 amb 275
316 amb 229 /* Cross reference the nodes and segments */
317 amb 90
318 amb 229 printf("\nCross-Reference Nodes and Segments\n==================================\n\n");
319     fflush(stdout);
320 amb 90
321 amb 212 /* Sort the node list geographically */
322 amb 209
323 amb 256 SortNodeListGeographically(Nodes);
324 amb 212
325     /* Create the real segments and nodes */
326    
327 amb 256 CreateRealNodes(Nodes,iteration);
328 amb 212
329 amb 256 CreateRealSegments(Segments,Ways);
330 amb 209
331 amb 104 /* Fix the segment and node indexes */
332    
333 amb 256 IndexNodes(Nodes,Segments);
334 amb 104
335 amb 256 IndexSegments(Segments,Nodes);
336 amb 104
337 amb 229 /* Output the results */
338    
339     printf("\nWrite Out Database Files\n========================\n\n");
340     fflush(stdout);
341    
342 amb 89 /* Write out the nodes */
343 amb 58
344 amb 256 SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem"));
345 amb 95
346 amb 326 FreeNodeList(Nodes,0);
347 amb 226
348 amb 89 /* Write out the segments */
349 amb 58
350 amb 256 SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem"));
351 amb 58
352 amb 326 FreeSegmentList(Segments,0);
353 amb 226
354 amb 89 /* Write out the ways */
355 amb 58
356 amb 398 SaveWayList(Ways,FileName(dirname,prefix,"ways.mem"));
357 amb 58
358 amb 326 FreeWayList(Ways,0);
359 amb 226
360 amb 2 return(0);
361     }
362 amb 342
363    
364     /*++++++++++++++++++++++++++++++++++++++
365     Print out the usage information.
366    
367     int detail The level of detail to use - 0 = low, 1 = high.
368     ++++++++++++++++++++++++++++++++++++++*/
369    
370     static void print_usage(int detail)
371     {
372     fprintf(stderr,
373     "Usage: planetsplitter [--help]\n"
374     " [--dir=<dirname>] [--prefix=<name>]\n"
375 amb 452 " [--sort-ram-size=<size>]\n"
376 amb 358 " [--tmpdir=<dirname>]\n"
377 amb 342 " [--parse-only | --process-only]\n"
378     " [--max-iterations=<number>]\n"
379 amb 395 " [--tagging=<filename>]\n"
380 amb 342 " [<filename.osm> ...]\n");
381    
382     if(detail)
383     fprintf(stderr,
384     "\n"
385     "--help Prints this information.\n"
386     "\n"
387     "--dir=<dirname> The directory containing the routing database.\n"
388     "--prefix=<name> The filename prefix for the routing database.\n"
389     "\n"
390 amb 358 "--sort-ram-size=<size> The amount of RAM (in MB) to use for data sorting\n"
391 amb 452 #if SLIM
392     " (defaults to 64MB otherwise.)\n"
393     #else
394     " (defaults to 256MB otherwise.)\n"
395     #endif
396 amb 342 "--tmpdir=<dirname> The directory name for temporary files.\n"
397 amb 358 " (defaults to the '--dir' option directory.)\n"
398 amb 342 "\n"
399     "--parse-only Parse the input OSM files and store the results.\n"
400     "--process-only Process the stored results from previous option.\n"
401     "\n"
402     "--max-iterations=<number> The number of iterations for finding super-nodes.\n"
403     "\n"
404 amb 395 "--tagging=<filename> The name of the XML file containing the tagging rules\n"
405     " (defaults to 'tagging.xml' with '--dirname' and\n"
406 amb 481 " '--prefix' options or the file installed in\n"
407     " '" DATADIR "').\n"
408 amb 395 "\n"
409 amb 358 "<filename.osm> ... The name(s) of the file(s) to process (by default\n"
410     " data is read from standard input).\n"
411 amb 342 "\n"
412     "<transport> defaults to all but can be set to:\n"
413     "%s"
414     "\n"
415     "<highway> can be selected from:\n"
416     "%s"
417     "\n"
418     "<property> can be selected from:\n"
419     "%s",
420     TransportList(),HighwayList(),PropertyList());
421    
422     exit(!detail);
423     }

Properties

Name Value
cvs:description Planet file splitter.