Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/planetsplitter.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 358 - (show annotations) (download) (as text)
Fri Apr 9 15:15:02 2010 UTC (14 years, 11 months 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 /***************************************
2 $Header: /home/amb/CVS/routino/src/planetsplitter.c,v 1.71 2010-04-09 15:15:02 amb Exp $
3
4 OSM planet file splitter.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
9
10 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 ***************************************/
23
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <errno.h>
29
30 #include "typesx.h"
31 #include "types.h"
32 #include "functionsx.h"
33 #include "functions.h"
34 #include "nodesx.h"
35 #include "segmentsx.h"
36 #include "waysx.h"
37 #include "superx.h"
38 #include "profiles.h"
39 #include "ways.h"
40
41
42 /* Variables */
43
44 /*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/
45 int option_slim=0;
46
47 /*+ The name of the temporary directory. +*/
48 char *option_tmpdirname=NULL;
49
50 /*+ The amount of RAM to use for filesorting. +*/
51 size_t option_filesort_ramsize=0;
52
53
54 /* Local functions */
55
56 static void print_usage(int detail);
57
58
59 /*++++++++++++++++++++++++++++++++++++++
60 The main program for the router.
61 ++++++++++++++++++++++++++++++++++++++*/
62
63 int main(int argc,char** argv)
64 {
65 NodesX *Nodes;
66 SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL;
67 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
76 /* Fill in the default profile. */
77
78 profile.transport=Transport_None; /* Not used by planetsplitter */
79
80 profile.allow=0;
81
82 for(i=1;i<Way_Count;i++)
83 profile.highway[i]=1;
84
85 for(i=1;i<Property_Count;i++)
86 profile.props_yes[i]=1;
87
88 profile.oneway=1; /* Not used by planetsplitter */
89
90 /* Parse the command line arguments */
91
92 for(arg=1;arg<argc;arg++)
93 {
94 if(!strcmp(argv[arg],"--help"))
95 print_usage(1);
96 else if(!strcmp(argv[arg],"--slim"))
97 option_slim=1;
98 else if(!strncmp(argv[arg],"--sort-ram-size=",16))
99 option_filesort_ramsize=atoi(&argv[arg][16]);
100 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 option_parse_only=1;
108 else if(!strcmp(argv[arg],"--process-only"))
109 option_process_only=1;
110 else if(!strncmp(argv[arg],"--max-iterations=",17))
111 max_iterations=atoi(&argv[arg][17]);
112 else if(!strncmp(argv[arg],"--transport=",12))
113 {
114 Transport transport=TransportType(&argv[arg][12]);
115 if(transport==Transport_None)
116 print_usage(0);
117 profile.allow|=ALLOWED(transport);
118 }
119 else if(!strncmp(argv[arg],"--not-highway=",14))
120 {
121 Highway highway=HighwayType(&argv[arg][14]);
122 if(highway==Way_Count)
123 print_usage(0);
124 profile.highway[highway]=0;
125 }
126 else if(!strncmp(argv[arg],"--not-property=",15))
127 {
128 Property property=PropertyType(&argv[arg][15]);
129 if(property==Property_Count)
130 print_usage(0);
131 profile.props_yes[property]=0;
132 }
133 else if(argv[arg][0]=='-' && argv[arg][1]=='-')
134 print_usage(0);
135 else
136 option_filenames++;
137 }
138
139 if(option_parse_only && option_process_only)
140 print_usage(0);
141
142 if(option_filenames && option_process_only)
143 print_usage(0);
144
145 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 if(!option_tmpdirname)
156 {
157 if(!dirname)
158 option_tmpdirname=".";
159 else
160 option_tmpdirname=dirname;
161 }
162
163 if(!profile.allow)
164 profile.allow=Allow_ALL;
165
166 /* Create new node, segment and way variables */
167
168 Nodes=NewNodeList(option_parse_only||option_process_only);
169
170 Segments=NewSegmentList(option_parse_only||option_process_only);
171
172 Ways=NewWayList(option_parse_only||option_process_only);
173
174 /* Parse the file */
175
176 if(option_filenames)
177 {
178 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 fprintf(stderr,"Cannot open file '%s' for reading [%s].\n",argv[arg],strerror(errno));
190 exit(EXIT_FAILURE);
191 }
192
193 printf("\nParse OSM Data [%s]\n==============\n\n",argv[arg]);
194 fflush(stdout);
195
196 ParseOSM(file,Nodes,Segments,Ways,&profile);
197
198 fclose(file);
199 }
200 }
201 else if(!option_process_only)
202 {
203 printf("\nParse OSM Data\n==============\n\n");
204 fflush(stdout);
205
206 ParseOSM(stdin,Nodes,Segments,Ways,&profile);
207 }
208
209 if(option_parse_only)
210 {
211 FreeNodeList(Nodes,1);
212 FreeSegmentList(Segments,1);
213 FreeWayList(Ways,1);
214
215 return(0);
216 }
217
218 /* Process the data */
219
220 printf("\nProcess OSM Data\n================\n\n");
221 fflush(stdout);
222
223 /* Sort the nodes, segments and ways */
224
225 SortNodeList(Nodes);
226
227 SortSegmentList(Segments);
228
229 SortWayList(Ways);
230
231 /* Remove bad segments (must be after sorting the nodes and segments) */
232
233 RemoveBadSegments(Nodes,Segments);
234
235 /* Remove non-highway nodes (must be after removing the bad segments) */
236
237 RemoveNonHighwayNodes(Nodes,Segments);
238
239 /* Measure the segments and replace node/way id with index (must be after removing non-highway nodes) */
240
241 UpdateSegments(Segments,Nodes,Ways);
242
243
244 /* Repeated iteration on Super-Nodes and Super-Segments */
245
246 do
247 {
248 printf("\nProcess Super-Data (iteration %d)\n================================%s\n\n",iteration,iteration>9?"=":"");
249 fflush(stdout);
250
251 if(iteration==0)
252 {
253 /* Select the super-nodes */
254
255 ChooseSuperNodes(Nodes,Segments,Ways);
256
257 /* Select the super-segments */
258
259 SuperSegments=CreateSuperSegments(Nodes,Segments,Ways,iteration);
260 }
261 else
262 {
263 SegmentsX *SuperSegments2;
264
265 /* Select the super-nodes */
266
267 ChooseSuperNodes(Nodes,SuperSegments,Ways);
268
269 /* Select the super-segments */
270
271 SuperSegments2=CreateSuperSegments(Nodes,SuperSegments,Ways,iteration);
272
273 if(SuperSegments->xnumber==SuperSegments2->xnumber)
274 quit=1;
275
276 FreeSegmentList(SuperSegments,0);
277
278 SuperSegments=SuperSegments2;
279 }
280
281 /* Sort the super-segments */
282
283 SortSegmentList(SuperSegments);
284
285 /* Remove duplicated super-segments */
286
287 DeduplicateSegments(SuperSegments,Nodes,Ways);
288
289 iteration++;
290
291 if(iteration>max_iterations)
292 quit=1;
293 }
294 while(!quit);
295
296 /* Combine the super-segments */
297
298 printf("\nCombine Segments and Super-Segments\n===================================\n\n");
299 fflush(stdout);
300
301 /* Merge the super-segments */
302
303 MergedSegments=MergeSuperSegments(Segments,SuperSegments);
304
305 FreeSegmentList(Segments,0);
306
307 FreeSegmentList(SuperSegments,0);
308
309 Segments=MergedSegments;
310
311 /* Rotate segments so that node1<node2 */
312
313 RotateSegments(Segments);
314
315 /* Sort the segments */
316
317 SortSegmentList(Segments);
318
319 /* Remove duplicated segments */
320
321 DeduplicateSegments(Segments,Nodes,Ways);
322
323 /* Cross reference the nodes and segments */
324
325 printf("\nCross-Reference Nodes and Segments\n==================================\n\n");
326 fflush(stdout);
327
328 /* Sort the node list geographically */
329
330 SortNodeListGeographically(Nodes);
331
332 /* Create the real segments and nodes */
333
334 CreateRealNodes(Nodes,iteration);
335
336 CreateRealSegments(Segments,Ways);
337
338 /* Fix the segment and node indexes */
339
340 IndexNodes(Nodes,Segments);
341
342 IndexSegments(Segments,Nodes);
343
344 /* Output the results */
345
346 printf("\nWrite Out Database Files\n========================\n\n");
347 fflush(stdout);
348
349 /* Write out the nodes */
350
351 SaveNodeList(Nodes,FileName(dirname,prefix,"nodes.mem"));
352
353 FreeNodeList(Nodes,0);
354
355 /* Write out the segments */
356
357 SaveSegmentList(Segments,FileName(dirname,prefix,"segments.mem"));
358
359 FreeSegmentList(Segments,0);
360
361 /* Write out the ways */
362
363 SaveWayList(Ways,FileName(dirname,prefix,"ways.mem"),&profile);
364
365 FreeWayList(Ways,0);
366
367 return(0);
368 }
369
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 " [--slim] [--sort-ram-size=<size>]\n"
383 " [--tmpdir=<dirname>]\n"
384 " [--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 "--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 "--tmpdir=<dirname> The directory name for temporary files.\n"
403 " (defaults to the '--dir' option directory.)\n"
404 "\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 "<filename.osm> ... The name(s) of the file(s) to process (by default\n"
415 " data is read from standard input).\n"
416 "\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.