Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /branches/destination-access/src/router.c
Parent Directory
|
Revision Log
Revision 1465 -
(show annotations)
(download)
(as text)
Fri Aug 2 18:12:56 2013 UTC (11 years, 7 months ago) by amb
Original Path: trunk/src/router.c
File MIME type: text/x-csrc
File size: 24933 byte(s)
Fri Aug 2 18:12:56 2013 UTC (11 years, 7 months ago) by amb
Original Path: trunk/src/router.c
File MIME type: text/x-csrc
File size: 24933 byte(s)
Add a '--output-stdout' option.
1 | /*************************************** |
2 | OSM router. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2013 Andrew M. Bishop |
7 | |
8 | 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 | ***************************************/ |
21 | |
22 | |
23 | #include <stdio.h> |
24 | #include <string.h> |
25 | #include <stdlib.h> |
26 | #include <ctype.h> |
27 | |
28 | #include "types.h" |
29 | #include "nodes.h" |
30 | #include "segments.h" |
31 | #include "ways.h" |
32 | #include "relations.h" |
33 | |
34 | #include "files.h" |
35 | #include "logging.h" |
36 | #include "functions.h" |
37 | #include "fakes.h" |
38 | #include "translations.h" |
39 | #include "profiles.h" |
40 | |
41 | |
42 | /*+ To help when debugging +*/ |
43 | #define DEBUG 0 |
44 | |
45 | /*+ The maximum distance from the specified point to search for a node or segment (in km). +*/ |
46 | #define MAXSEARCH 1 |
47 | |
48 | |
49 | /* Global variables */ |
50 | |
51 | /*+ The option not to print any progress information. +*/ |
52 | int option_quiet=0; |
53 | |
54 | /*+ The options to select the format of the output. +*/ |
55 | int option_html=0,option_gpx_track=0,option_gpx_route=0,option_text=0,option_text_all=0,option_none=0,option_stdout=0; |
56 | |
57 | /*+ The option to calculate the quickest route insted of the shortest. +*/ |
58 | int option_quickest=0; |
59 | |
60 | |
61 | /* Local functions */ |
62 | |
63 | static void print_usage(int detail,const char *argerr,const char *err); |
64 | |
65 | |
66 | /*++++++++++++++++++++++++++++++++++++++ |
67 | The main program for the router. |
68 | ++++++++++++++++++++++++++++++++++++++*/ |
69 | |
70 | int main(int argc,char** argv) |
71 | { |
72 | Nodes *OSMNodes; |
73 | Segments *OSMSegments; |
74 | Ways *OSMWays; |
75 | Relations*OSMRelations; |
76 | Results *results[NWAYPOINTS+1]={NULL}; |
77 | int point_used[NWAYPOINTS+1]={0}; |
78 | double point_lon[NWAYPOINTS+1],point_lat[NWAYPOINTS+1]; |
79 | double heading=-999; |
80 | int help_profile=0,help_profile_xml=0,help_profile_json=0,help_profile_pl=0; |
81 | char *dirname=NULL,*prefix=NULL; |
82 | char *profiles=NULL,*profilename=NULL; |
83 | char *translations=NULL,*language=NULL; |
84 | int exactnodes=0; |
85 | Transport transport=Transport_None; |
86 | Profile *profile=NULL; |
87 | index_t start_node=NO_NODE,finish_node=NO_NODE; |
88 | index_t join_segment=NO_SEGMENT; |
89 | int arg,point; |
90 | |
91 | /* Parse the command line arguments */ |
92 | |
93 | if(argc<2) |
94 | print_usage(0,NULL,NULL); |
95 | |
96 | /* Get the non-routing, general program options */ |
97 | |
98 | for(arg=1;arg<argc;arg++) |
99 | { |
100 | if(!strcmp(argv[arg],"--help")) |
101 | print_usage(1,NULL,NULL); |
102 | else if(!strcmp(argv[arg],"--help-profile")) |
103 | help_profile=1; |
104 | else if(!strcmp(argv[arg],"--help-profile-xml")) |
105 | help_profile_xml=1; |
106 | else if(!strcmp(argv[arg],"--help-profile-json")) |
107 | help_profile_json=1; |
108 | else if(!strcmp(argv[arg],"--help-profile-perl")) |
109 | help_profile_pl=1; |
110 | else if(!strncmp(argv[arg],"--dir=",6)) |
111 | dirname=&argv[arg][6]; |
112 | else if(!strncmp(argv[arg],"--prefix=",9)) |
113 | prefix=&argv[arg][9]; |
114 | else if(!strncmp(argv[arg],"--profiles=",11)) |
115 | profiles=&argv[arg][11]; |
116 | else if(!strncmp(argv[arg],"--translations=",15)) |
117 | translations=&argv[arg][15]; |
118 | else if(!strcmp(argv[arg],"--exact-nodes-only")) |
119 | exactnodes=1; |
120 | else if(!strcmp(argv[arg],"--quiet")) |
121 | option_quiet=1; |
122 | else if(!strcmp(argv[arg],"--loggable")) |
123 | option_loggable=1; |
124 | else if(!strcmp(argv[arg],"--output-html")) |
125 | option_html=1; |
126 | else if(!strcmp(argv[arg],"--output-gpx-track")) |
127 | option_gpx_track=1; |
128 | else if(!strcmp(argv[arg],"--output-gpx-route")) |
129 | option_gpx_route=1; |
130 | else if(!strcmp(argv[arg],"--output-text")) |
131 | option_text=1; |
132 | else if(!strcmp(argv[arg],"--output-text-all")) |
133 | option_text_all=1; |
134 | else if(!strcmp(argv[arg],"--output-none")) |
135 | option_none=1; |
136 | else if(!strcmp(argv[arg],"--output-stdout")) |
137 | { option_stdout=1; option_quiet=1; } |
138 | else if(!strncmp(argv[arg],"--profile=",10)) |
139 | profilename=&argv[arg][10]; |
140 | else if(!strncmp(argv[arg],"--language=",11)) |
141 | language=&argv[arg][11]; |
142 | else if(!strncmp(argv[arg],"--transport=",12)) |
143 | { |
144 | transport=TransportType(&argv[arg][12]); |
145 | |
146 | if(transport==Transport_None) |
147 | print_usage(0,argv[arg],NULL); |
148 | } |
149 | else |
150 | continue; |
151 | |
152 | argv[arg]=NULL; |
153 | } |
154 | |
155 | if(option_stdout && (option_html+option_gpx_track+option_gpx_route+option_text+option_text_all)!=1) |
156 | { |
157 | fprintf(stderr,"Error: The '--output-stdout' option requires exactly one other output option (but not '--output-none').\n"); |
158 | exit(EXIT_FAILURE); |
159 | } |
160 | |
161 | /* Load in the profiles */ |
162 | |
163 | if(transport==Transport_None) |
164 | transport=Transport_Motorcar; |
165 | |
166 | if(profiles) |
167 | { |
168 | if(!ExistsFile(profiles)) |
169 | { |
170 | fprintf(stderr,"Error: The '--profiles' option specifies a file that does not exist.\n"); |
171 | exit(EXIT_FAILURE); |
172 | } |
173 | } |
174 | else |
175 | { |
176 | if(ExistsFile(FileName(dirname,prefix,"profiles.xml"))) |
177 | profiles=FileName(dirname,prefix,"profiles.xml"); |
178 | else if(ExistsFile(FileName(DATADIR,NULL,"profiles.xml"))) |
179 | profiles=FileName(DATADIR,NULL,"profiles.xml"); |
180 | else |
181 | { |
182 | fprintf(stderr,"Error: The '--profiles' option was not used and the default 'profiles.xml' does not exist.\n"); |
183 | exit(EXIT_FAILURE); |
184 | } |
185 | } |
186 | |
187 | if(ParseXMLProfiles(profiles)) |
188 | { |
189 | fprintf(stderr,"Error: Cannot read the profiles in the file '%s'.\n",profiles); |
190 | exit(EXIT_FAILURE); |
191 | } |
192 | |
193 | /* Choose the selected profile. */ |
194 | |
195 | if(profilename) |
196 | { |
197 | profile=GetProfile(profilename); |
198 | |
199 | if(!profile) |
200 | { |
201 | fprintf(stderr,"Error: Cannot find a profile called '%s' in '%s'.\n",profilename,profiles); |
202 | exit(EXIT_FAILURE); |
203 | } |
204 | } |
205 | else |
206 | profile=GetProfile(TransportName(transport)); |
207 | |
208 | if(!profile) |
209 | { |
210 | profile=(Profile*)calloc(1,sizeof(Profile)); |
211 | profile->transport=transport; |
212 | } |
213 | |
214 | /* Parse the other command line arguments */ |
215 | |
216 | for(arg=1;arg<argc;arg++) |
217 | { |
218 | if(!argv[arg]) |
219 | continue; |
220 | else if(!strcmp(argv[arg],"--shortest")) |
221 | option_quickest=0; |
222 | else if(!strcmp(argv[arg],"--quickest")) |
223 | option_quickest=1; |
224 | else if(isdigit(argv[arg][0]) || |
225 | ((argv[arg][0]=='-' || argv[arg][0]=='+') && isdigit(argv[arg][1]))) |
226 | { |
227 | for(point=1;point<=NWAYPOINTS;point++) |
228 | if(point_used[point]!=3) |
229 | { |
230 | if(point_used[point]==0) |
231 | { |
232 | point_lon[point]=degrees_to_radians(atof(argv[arg])); |
233 | point_used[point]=1; |
234 | } |
235 | else /* if(point_used[point]==1) */ |
236 | { |
237 | point_lat[point]=degrees_to_radians(atof(argv[arg])); |
238 | point_used[point]=3; |
239 | } |
240 | break; |
241 | } |
242 | } |
243 | else if(!strncmp(argv[arg],"--lon",5) && isdigit(argv[arg][5])) |
244 | { |
245 | char *p=&argv[arg][6]; |
246 | while(isdigit(*p)) p++; |
247 | if(*p++!='=') |
248 | print_usage(0,argv[arg],NULL); |
249 | |
250 | point=atoi(&argv[arg][5]); |
251 | if(point>NWAYPOINTS || point_used[point]&1) |
252 | print_usage(0,argv[arg],NULL); |
253 | |
254 | point_lon[point]=degrees_to_radians(atof(p)); |
255 | point_used[point]+=1; |
256 | } |
257 | else if(!strncmp(argv[arg],"--lat",5) && isdigit(argv[arg][5])) |
258 | { |
259 | char *p=&argv[arg][6]; |
260 | while(isdigit(*p)) p++; |
261 | if(*p++!='=') |
262 | print_usage(0,argv[arg],NULL); |
263 | |
264 | point=atoi(&argv[arg][5]); |
265 | if(point>NWAYPOINTS || point_used[point]&2) |
266 | print_usage(0,argv[arg],NULL); |
267 | |
268 | point_lat[point]=degrees_to_radians(atof(p)); |
269 | point_used[point]+=2; |
270 | } |
271 | else if(!strncmp(argv[arg],"--heading=",10)) |
272 | { |
273 | double h=atof(&argv[arg][10]); |
274 | |
275 | if(h>=-360 && h<=360) |
276 | { |
277 | heading=h; |
278 | |
279 | if(heading<0) heading+=360; |
280 | } |
281 | } |
282 | else if(!strncmp(argv[arg],"--transport=",12)) |
283 | ; /* Done this already */ |
284 | else if(!strncmp(argv[arg],"--highway-",10)) |
285 | { |
286 | Highway highway; |
287 | char *equal=strchr(argv[arg],'='); |
288 | char *string; |
289 | |
290 | if(!equal) |
291 | print_usage(0,argv[arg],NULL); |
292 | |
293 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+10); |
294 | string[equal-argv[arg]-10]=0; |
295 | |
296 | highway=HighwayType(string); |
297 | |
298 | if(highway==Highway_None) |
299 | print_usage(0,argv[arg],NULL); |
300 | |
301 | profile->highway[highway]=atof(equal+1); |
302 | |
303 | free(string); |
304 | } |
305 | else if(!strncmp(argv[arg],"--speed-",8)) |
306 | { |
307 | Highway highway; |
308 | char *equal=strchr(argv[arg],'='); |
309 | char *string; |
310 | |
311 | if(!equal) |
312 | print_usage(0,argv[arg],NULL); |
313 | |
314 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+8); |
315 | string[equal-argv[arg]-8]=0; |
316 | |
317 | highway=HighwayType(string); |
318 | |
319 | if(highway==Highway_None) |
320 | print_usage(0,argv[arg],NULL); |
321 | |
322 | profile->speed[highway]=kph_to_speed(atof(equal+1)); |
323 | |
324 | free(string); |
325 | } |
326 | else if(!strncmp(argv[arg],"--property-",11)) |
327 | { |
328 | Property property; |
329 | char *equal=strchr(argv[arg],'='); |
330 | char *string; |
331 | |
332 | if(!equal) |
333 | print_usage(0,argv[arg],NULL); |
334 | |
335 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+11); |
336 | string[equal-argv[arg]-11]=0; |
337 | |
338 | property=PropertyType(string); |
339 | |
340 | if(property==Property_None) |
341 | print_usage(0,argv[arg],NULL); |
342 | |
343 | profile->props_yes[property]=atof(equal+1); |
344 | |
345 | free(string); |
346 | } |
347 | else if(!strncmp(argv[arg],"--oneway=",9)) |
348 | profile->oneway=!!atoi(&argv[arg][9]); |
349 | else if(!strncmp(argv[arg],"--turns=",8)) |
350 | profile->turns=!!atoi(&argv[arg][8]); |
351 | else if(!strncmp(argv[arg],"--weight=",9)) |
352 | profile->weight=tonnes_to_weight(atof(&argv[arg][9])); |
353 | else if(!strncmp(argv[arg],"--height=",9)) |
354 | profile->height=metres_to_height(atof(&argv[arg][9])); |
355 | else if(!strncmp(argv[arg],"--width=",8)) |
356 | profile->width=metres_to_width(atof(&argv[arg][8])); |
357 | else if(!strncmp(argv[arg],"--length=",9)) |
358 | profile->length=metres_to_length(atof(&argv[arg][9])); |
359 | else |
360 | print_usage(0,argv[arg],NULL); |
361 | } |
362 | |
363 | for(point=1;point<=NWAYPOINTS;point++) |
364 | if(point_used[point]==1 || point_used[point]==2) |
365 | print_usage(0,NULL,"All waypoints must have latitude and longitude."); |
366 | |
367 | /* Print one of the profiles if requested */ |
368 | |
369 | if(help_profile) |
370 | { |
371 | PrintProfile(profile); |
372 | |
373 | return(0); |
374 | } |
375 | else if(help_profile_xml) |
376 | { |
377 | PrintProfilesXML(); |
378 | |
379 | return(0); |
380 | } |
381 | else if(help_profile_json) |
382 | { |
383 | PrintProfilesJSON(); |
384 | |
385 | return(0); |
386 | } |
387 | else if(help_profile_pl) |
388 | { |
389 | PrintProfilesPerl(); |
390 | |
391 | return(0); |
392 | } |
393 | |
394 | /* Load in the translations */ |
395 | |
396 | if(option_html==0 && option_gpx_track==0 && option_gpx_route==0 && option_text==0 && option_text_all==0 && option_none==0) |
397 | option_html=option_gpx_track=option_gpx_route=option_text=option_text_all=1; |
398 | |
399 | if(option_html || option_gpx_route || option_gpx_track) |
400 | { |
401 | if(translations) |
402 | { |
403 | if(!ExistsFile(translations)) |
404 | { |
405 | fprintf(stderr,"Error: The '--translations' option specifies a file that does not exist.\n"); |
406 | exit(EXIT_FAILURE); |
407 | } |
408 | } |
409 | else |
410 | { |
411 | if(ExistsFile(FileName(dirname,prefix,"translations.xml"))) |
412 | translations=FileName(dirname,prefix,"translations.xml"); |
413 | else if(ExistsFile(FileName(DATADIR,NULL,"translations.xml"))) |
414 | translations=FileName(DATADIR,NULL,"translations.xml"); |
415 | else |
416 | { |
417 | fprintf(stderr,"Error: The '--translations' option was not used and the default 'translations.xml' does not exist.\n"); |
418 | exit(EXIT_FAILURE); |
419 | } |
420 | } |
421 | |
422 | if(ParseXMLTranslations(translations,language)) |
423 | { |
424 | fprintf(stderr,"Error: Cannot read the translations in the file '%s'.\n",translations); |
425 | exit(EXIT_FAILURE); |
426 | } |
427 | } |
428 | |
429 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ |
430 | |
431 | OSMNodes=LoadNodeList(FileName(dirname,prefix,"nodes.mem")); |
432 | |
433 | OSMSegments=LoadSegmentList(FileName(dirname,prefix,"segments.mem")); |
434 | |
435 | OSMWays=LoadWayList(FileName(dirname,prefix,"ways.mem")); |
436 | |
437 | OSMRelations=LoadRelationList(FileName(dirname,prefix,"relations.mem")); |
438 | |
439 | if(UpdateProfile(profile,OSMWays)) |
440 | { |
441 | fprintf(stderr,"Error: Profile is invalid or not compatible with database.\n"); |
442 | exit(EXIT_FAILURE); |
443 | } |
444 | |
445 | /* Loop through all pairs of points */ |
446 | |
447 | for(point=1;point<=NWAYPOINTS;point++) |
448 | { |
449 | Results *begin,*end; |
450 | distance_t distmax=km_to_distance(MAXSEARCH); |
451 | distance_t distmin; |
452 | index_t segment=NO_SEGMENT; |
453 | index_t node1,node2; |
454 | |
455 | if(point_used[point]!=3) |
456 | continue; |
457 | |
458 | /* Find the closest point */ |
459 | |
460 | start_node=finish_node; |
461 | |
462 | if(exactnodes) |
463 | { |
464 | finish_node=FindClosestNode(OSMNodes,OSMSegments,OSMWays,point_lat[point],point_lon[point],distmax,profile,&distmin); |
465 | } |
466 | else |
467 | { |
468 | distance_t dist1,dist2; |
469 | |
470 | segment=FindClosestSegment(OSMNodes,OSMSegments,OSMWays,point_lat[point],point_lon[point],distmax,profile,&distmin,&node1,&node2,&dist1,&dist2); |
471 | |
472 | if(segment!=NO_SEGMENT) |
473 | finish_node=CreateFakes(OSMNodes,OSMSegments,point,LookupSegment(OSMSegments,segment,1),node1,node2,dist1,dist2); |
474 | else |
475 | finish_node=NO_NODE; |
476 | } |
477 | |
478 | if(finish_node==NO_NODE) |
479 | { |
480 | fprintf(stderr,"Error: Cannot find node close to specified point %d.\n",point); |
481 | exit(EXIT_FAILURE); |
482 | } |
483 | |
484 | if(!option_quiet) |
485 | { |
486 | double lat,lon; |
487 | |
488 | if(IsFakeNode(finish_node)) |
489 | GetFakeLatLong(finish_node,&lat,&lon); |
490 | else |
491 | GetLatLong(OSMNodes,finish_node,NULL,&lat,&lon); |
492 | |
493 | if(IsFakeNode(finish_node)) |
494 | printf("Point %d is segment %"Pindex_t" (node %"Pindex_t" -> %"Pindex_t"): %3.6f %4.6f = %2.3f km\n",point,segment,node1,node2, |
495 | radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); |
496 | else |
497 | printf("Point %d is node %"Pindex_t": %3.6f %4.6f = %2.3f km\n",point,finish_node, |
498 | radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); |
499 | } |
500 | |
501 | if(start_node==NO_NODE) |
502 | continue; |
503 | |
504 | if(start_node==finish_node) |
505 | continue; |
506 | |
507 | if(heading!=-999 && join_segment==NO_SEGMENT) |
508 | join_segment=FindClosestSegmentHeading(OSMNodes,OSMSegments,OSMWays,start_node,heading,profile); |
509 | |
510 | /* Calculate the beginning of the route */ |
511 | |
512 | begin=FindStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node); |
513 | |
514 | if(begin) |
515 | { |
516 | /* Check if the end of the route was reached */ |
517 | |
518 | if(begin->finish_node!=NO_NODE) |
519 | results[point]=ExtendStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,begin,finish_node); |
520 | } |
521 | else |
522 | { |
523 | if(join_segment!=NO_SEGMENT) |
524 | { |
525 | /* Try again but allow a U-turn at the start waypoint - |
526 | this solves the problem of facing a dead-end that contains no super-nodes. */ |
527 | |
528 | join_segment=NO_SEGMENT; |
529 | |
530 | begin=FindStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node); |
531 | } |
532 | |
533 | if(begin) |
534 | { |
535 | /* Check if the end of the route was reached */ |
536 | |
537 | if(begin->finish_node!=NO_NODE) |
538 | results[point]=ExtendStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,begin,finish_node); |
539 | } |
540 | else |
541 | { |
542 | fprintf(stderr,"Error: Cannot find initial section of route compatible with profile.\n"); |
543 | exit(EXIT_FAILURE); |
544 | } |
545 | } |
546 | |
547 | /* Calculate the rest of the route */ |
548 | |
549 | if(!results[point]) |
550 | { |
551 | Results *middle; |
552 | |
553 | /* Calculate the end of the route */ |
554 | |
555 | end=FindFinishRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,finish_node); |
556 | |
557 | if(!end) |
558 | { |
559 | fprintf(stderr,"Error: Cannot find final section of route compatible with profile.\n"); |
560 | exit(EXIT_FAILURE); |
561 | } |
562 | |
563 | /* Calculate the middle of the route */ |
564 | |
565 | middle=FindMiddleRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,begin,end); |
566 | |
567 | if(!middle && join_segment!=NO_SEGMENT) |
568 | { |
569 | /* Try again but allow a U-turn at the start waypoint - |
570 | this solves the problem of facing a dead-end that contains some super-nodes. */ |
571 | |
572 | FreeResultsList(begin); |
573 | |
574 | begin=FindStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,NO_SEGMENT,finish_node); |
575 | |
576 | if(begin) |
577 | middle=FindMiddleRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,begin,end); |
578 | } |
579 | |
580 | FreeResultsList(end); |
581 | |
582 | if(!middle) |
583 | { |
584 | fprintf(stderr,"Error: Cannot find super-route compatible with profile.\n"); |
585 | exit(EXIT_FAILURE); |
586 | } |
587 | |
588 | results[point]=CombineRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,begin,middle); |
589 | |
590 | if(!results[point]) |
591 | { |
592 | fprintf(stderr,"Error: Cannot create combined route following super-route.\n"); |
593 | exit(EXIT_FAILURE); |
594 | } |
595 | |
596 | FreeResultsList(begin); |
597 | |
598 | FreeResultsList(middle); |
599 | } |
600 | |
601 | #if DEBUG |
602 | Result *r=FindResult(results[point],results[point]->start_node,results[point]->prev_segment); |
603 | |
604 | printf("The final route is:\n"); |
605 | |
606 | while(r) |
607 | { |
608 | printf(" node=%"Pindex_t" segment=%"Pindex_t" score=%f\n",r->node,r->segment,r->score); |
609 | |
610 | r=r->next; |
611 | } |
612 | #endif |
613 | |
614 | join_segment=results[point]->last_segment; |
615 | } |
616 | |
617 | if(!option_quiet) |
618 | { |
619 | printf("Routed OK\n"); |
620 | fflush(stdout); |
621 | } |
622 | |
623 | /* Print out the combined route */ |
624 | |
625 | if(!option_none) |
626 | PrintRoute(results,NWAYPOINTS,OSMNodes,OSMSegments,OSMWays,profile); |
627 | |
628 | /* Destroy the remaining results lists and data structures */ |
629 | |
630 | #if 0 |
631 | |
632 | for(point=1;point<=NWAYPOINTS;point++) |
633 | if(results[point]) |
634 | FreeResultsList(results[point]); |
635 | |
636 | DestroyNodeList(OSMNodes); |
637 | DestroySegmentList(OSMSegments); |
638 | DestroyWayList(OSMWays); |
639 | DestroyRelationList(OSMRelations); |
640 | |
641 | #endif |
642 | |
643 | return(0); |
644 | } |
645 | |
646 | |
647 | /*++++++++++++++++++++++++++++++++++++++ |
648 | Print out the usage information. |
649 | |
650 | int detail The level of detail to use - 0 = low, 1 = high. |
651 | |
652 | const char *argerr The argument that gave the error (if there is one). |
653 | |
654 | const char *err Other error message (if there is one). |
655 | ++++++++++++++++++++++++++++++++++++++*/ |
656 | |
657 | static void print_usage(int detail,const char *argerr,const char *err) |
658 | { |
659 | fprintf(stderr, |
660 | "Usage: router [--help | --help-profile | --help-profile-xml |\n" |
661 | " --help-profile-json | --help-profile-perl ]\n" |
662 | " [--dir=<dirname>] [--prefix=<name>]\n" |
663 | " [--profiles=<filename>] [--translations=<filename>]\n" |
664 | " [--exact-nodes-only]\n" |
665 | " [--loggable | --quiet]\n" |
666 | " [--language=<lang>]\n" |
667 | " [--output-html]\n" |
668 | " [--output-gpx-track] [--output-gpx-route]\n" |
669 | " [--output-text] [--output-text-all]\n" |
670 | " [--output-none] [--output-stdout]\n" |
671 | " [--profile=<name>]\n" |
672 | " [--transport=<transport>]\n" |
673 | " [--shortest | --quickest]\n" |
674 | " --lon1=<longitude> --lat1=<latitude>\n" |
675 | " --lon2=<longitude> --lon2=<latitude>\n" |
676 | " [ ... --lon99=<longitude> --lon99=<latitude>]\n" |
677 | " [--highway-<highway>=<preference> ...]\n" |
678 | " [--speed-<highway>=<speed> ...]\n" |
679 | " [--property-<property>=<preference> ...]\n" |
680 | " [--oneway=(0|1)] [--turns=(0|1)]\n" |
681 | " [--weight=<weight>]\n" |
682 | " [--height=<height>] [--width=<width>] [--length=<length>]\n"); |
683 | |
684 | if(argerr) |
685 | fprintf(stderr, |
686 | "\n" |
687 | "Error with command line parameter: %s\n",argerr); |
688 | |
689 | if(err) |
690 | fprintf(stderr, |
691 | "\n" |
692 | "Error: %s\n",err); |
693 | |
694 | if(detail) |
695 | fprintf(stderr, |
696 | "\n" |
697 | "--help Prints this information.\n" |
698 | "--help-profile Prints the information about the selected profile.\n" |
699 | "--help-profile-xml Prints all loaded profiles in XML format.\n" |
700 | "--help-profile-json Prints all loaded profiles in JSON format.\n" |
701 | "--help-profile-perl Prints all loaded profiles in Perl format.\n" |
702 | "\n" |
703 | "--dir=<dirname> The directory containing the routing database.\n" |
704 | "--prefix=<name> The filename prefix for the routing database.\n" |
705 | "--profiles=<filename> The name of the XML file containing the profiles\n" |
706 | " (defaults to 'profiles.xml' with '--dir' and\n" |
707 | " '--prefix' options or the file installed in\n" |
708 | " '" DATADIR "').\n" |
709 | "--translations=<fname> The name of the XML file containing the translations\n" |
710 | " (defaults to 'translations.xml' with '--dir' and\n" |
711 | " '--prefix' options or the file installed in\n" |
712 | " '" DATADIR "').\n" |
713 | "\n" |
714 | "--exact-nodes-only Only route between nodes (don't find closest segment).\n" |
715 | "\n" |
716 | "--loggable Print progress messages suitable for logging to file.\n" |
717 | "--quiet Don't print any screen output when running.\n" |
718 | "\n" |
719 | "--language=<lang> Use the translations for specified language.\n" |
720 | "--output-html Write an HTML description of the route.\n" |
721 | "--output-gpx-track Write a GPX track file with all route points.\n" |
722 | "--output-gpx-route Write a GPX route file with interesting junctions.\n" |
723 | "--output-text Write a plain text file with interesting junctions.\n" |
724 | "--output-text-all Write a plain test file with all route points.\n" |
725 | "--output-none Don't write any output files or read any translations.\n" |
726 | " (If no output option is given then all are written.)\n" |
727 | "--output-stdout Write to stdout instead of a file (requires exactly\n" |
728 | " one output format option, implies '--quiet').\n" |
729 | "\n" |
730 | "--profile=<name> Select the loaded profile with this name.\n" |
731 | "--transport=<transport> Select the transport to use (selects the profile\n" |
732 | " named after the transport if '--profile' is not used.)\n" |
733 | "\n" |
734 | "--shortest Find the shortest route between the waypoints.\n" |
735 | "--quickest Find the quickest route between the waypoints.\n" |
736 | "\n" |
737 | "--lon<n>=<longitude> Specify the longitude of the n'th waypoint.\n" |
738 | "--lat<n>=<latitude> Specify the latitude of the n'th waypoint.\n" |
739 | "\n" |
740 | "--heading=<bearing> Initial compass bearing at lowest numbered waypoint.\n" |
741 | "\n" |
742 | " Routing preference options\n" |
743 | "--highway-<highway>=<preference> * preference for highway type (%%).\n" |
744 | "--speed-<highway>=<speed> * speed for highway type (km/h).\n" |
745 | "--property-<property>=<preference> * preference for proprty type (%%).\n" |
746 | "--oneway=(0|1) * oneway restrictions are to be obeyed.\n" |
747 | "--turns=(0|1) * turn restrictions are to be obeyed.\n" |
748 | "--weight=<weight> * maximum weight limit (tonnes).\n" |
749 | "--height=<height> * maximum height limit (metres).\n" |
750 | "--width=<width> * maximum width limit (metres).\n" |
751 | "--length=<length> * maximum length limit (metres).\n" |
752 | "\n" |
753 | "<transport> defaults to motorcar but can be set to:\n" |
754 | "%s" |
755 | "\n" |
756 | "<highway> can be selected from:\n" |
757 | "%s" |
758 | "\n" |
759 | "<property> can be selected from:\n" |
760 | "%s", |
761 | TransportList(),HighwayList(),PropertyList()); |
762 | |
763 | exit(!detail); |
764 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |