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