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