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