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